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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,652,793,134 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 92 | 28,364,800 | s, x, y=[input() for i in range(3)]
t=s[::-1]
op=0
pos=0
if x in s:
pos=s.index(x)+len(x)
if y in s[pos:]: op+=1
if y in t[pos:]:
pos=s.index(x)+len(x)
if y in s[pos:]: op+=2
ans=['fantasy', 'forward', 'backward', 'both']
print(ans[op]) | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
s, x, y=[input() for i in range(3)]
t=s[::-1]
op=0
pos=0
if x in s:
pos=s.index(x)+len(x)
if y in s[pos:]: op+=1
if y in t[pos:]:
pos=s.index(x)+len(x)
if y in s[pos:]: op+=2
ans=['fantasy', 'forward', 'backward', 'both']
print(ans[op])
``` | 0 |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,668,747,318 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 92 | 0 | def solve()-> str:
k=int(input())
s=input()
d={}
c=0
for i in s:
d[i] = d.get(i, 0)+1
c= d[i]
for v in d.values():
if c!=v:
return "-1"
res="".join(d.keys())*c
return res
print(solve()) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
def solve()-> str:
k=int(input())
s=input()
d={}
c=0
for i in s:
d[i] = d.get(i, 0)+1
c= d[i]
for v in d.values():
if c!=v:
return "-1"
res="".join(d.keys())*c
return res
print(solve())
``` | 0 | |
614 | B | Gena's Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en... | The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total leng... | Print a single number without leading zeroes — the product of the number of tanks presented by each country. | [
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] | [
"50",
"110",
"0"
] | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | 1,000 | [
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 ... | 1,559,630,183 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 500 | 512,000 | n=int(input())
a=list(map(int,input().split()))
p=1
for i in a:
p=p*i
print(p) | Title: Gena's Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from eac... | ```python
n=int(input())
a=list(map(int,input().split()))
p=1
for i in a:
p=p*i
print(p)
``` | 0 | |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,554,060,646 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 0 | mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
s=ls()
n=len(s)
if n==1:
print(''.join(s))
elif n==2:
if s[0]==s[1]:
if s[1]... | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wa... | ```python
mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
s=ls()
n=len(s)
if n==1:
print(''.join(s))
elif n==2:
if s[0]==s[1]:
... | 0 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,664,034,993 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | n=int(input())
x=list(map(int,input().split()))
k=sum(x)%(n+1)
if k==0:
print(2)
else:
print(1)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n=int(input())
x=list(map(int,input().split()))
k=sum(x)%(n+1)
if k==0:
print(2)
else:
print(1)
``` | 0 | |
1,004 | B | Sonya and Exhibition | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null | Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions shoul... | The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. | Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any. | [
"5 3\n1 3\n2 4\n2 5\n",
"6 3\n5 6\n1 4\n4 6\n"
] | [
"01100",
"110010"
] | In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty ... | 1,000 | [
{
"input": "5 3\n1 3\n2 4\n2 5",
"output": "01010"
},
{
"input": "6 3\n5 6\n1 4\n4 6",
"output": "010101"
},
{
"input": "10 4\n3 3\n1 6\n9 9\n10 10",
"output": "0101010101"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "1000 10\n3 998\n2 1000\n1 999\n2 100... | 1,632,893,821 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 93 | 20,172,800 | n,m=map(int,input().split())
print('10'*(n//2)+('1' if n%2 else '')) | Title: Sonya and Exhibition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the ... | ```python
n,m=map(int,input().split())
print('10'*(n//2)+('1' if n%2 else ''))
``` | 3 | |
78 | D | Archer's Shot | PROGRAMMING | 2,300 | [
"binary search",
"geometry",
"math",
"two pointers"
] | D. Archer's Shot | 2 | 256 | A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playin... | The first and only line of input contains a single positive integer *k* — the archer's shot range (1<=≤<=*k*<=≤<=106). | Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator). | [
"3\n",
"4\n",
"5\n"
] | [
"7",
"13",
"19"
] | none | 2,000 | [
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "13"
},
{
"input": "5",
"output": "19"
},
{
"input": "9",
"output": "85"
},
{
"input": "11",
"output": "121"
},
{
"input": "51",
"output": "3037"
},
{
"input": "101",
"output": ... | 1,500,136,196 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 77 | 5,529,600 | from sys import stdin, stdout
from decimal import Decimal
n = int(stdin.readline())
ans = 0
l = 1
label = 1
x = -1
while l and x <= n:
x += 1.5
l, r = 0, n
while (r - l > 1):
m = (r + l) // 2
if label % 2:
y = 3 ** 0.5 * (m - 1) + (3 ** 0.5) / 2... | Title: Archer's Shot
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular h... | ```python
from sys import stdin, stdout
from decimal import Decimal
n = int(stdin.readline())
ans = 0
l = 1
label = 1
x = -1
while l and x <= n:
x += 1.5
l, r = 0, n
while (r - l > 1):
m = (r + l) // 2
if label % 2:
y = 3 ** 0.5 * (m - 1) + (3 *... | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109... | Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. | [
"3\n7 1 3\n1 2 1\n",
"4\n5 10 3 2\n2 3 2 4\n"
] | [
"2.000000000000\n",
"1.400000000000\n"
] | In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. | 0 | [
{
"input": "3\n7 1 3\n1 2 1",
"output": "2.000000000000"
},
{
"input": "4\n5 10 3 2\n2 3 2 4",
"output": "1.400000000000"
},
{
"input": "3\n1 1000000000 2\n1 2 1000000000",
"output": "333333332.999999999971"
},
{
"input": "2\n4 5\n10 8",
"output": "0.055555555556"
},
... | 1,627,172,903 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 2,963 | 13,619,200 |
def check(second):
second = second * 0.000001
# 1^-2 = 0.01
lower_bound = 0
higher_bound = 999999999999999
for i in range(len(friends)):
lower_bound = max(lower_bound, friends[i] - speed[i] * second)
higher_bound = min(higher_bound, friends[i] + speed[i] * second)
if lower_bound <= higher_... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*... | ```python
def check(second):
second = second * 0.000001
# 1^-2 = 0.01
lower_bound = 0
higher_bound = 999999999999999
for i in range(len(friends)):
lower_bound = max(lower_bound, friends[i] - speed[i] * second)
higher_bound = min(higher_bound, friends[i] + speed[i] * second)
if lower_bound ... | 3 | |
123 | D | String | PROGRAMMING | 2,300 | [
"string suffix structures"
] | null | null | You are given a string *s*. Each pair of numbers *l* and *r* that fulfill the condition 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|, correspond to a substring of the string *s*, starting in the position *l* and ending in the position *r* (inclusive).
Let's define the function of two strings *F*(*x*,<=*y*) like this. We'll find a list... | The only line contains the given string *s*, consisting only of small Latin letters (1<=≤<=|*s*|<=≤<=105). | Print the single number — the sought sum.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"aaaa\n",
"abcdef\n",
"abacabadabacaba\n"
] | [
"20\n",
"21\n",
"188\n"
] | In the first sample the function values at *x* equal to "a", "aa", "aaa" and "aaaa" equal 10, 6, 3 and 1 correspondingly.
In the second sample for any satisfying *x* the function value is 1. | 2,000 | [
{
"input": "aaaa",
"output": "20"
},
{
"input": "abcdef",
"output": "21"
},
{
"input": "abacabadabacaba",
"output": "188"
},
{
"input": "tkth",
"output": "11"
},
{
"input": "eqkrqe",
"output": "23"
},
{
"input": "cwuiax",
"output": "21"
},
{
... | 1,693,834,773 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def count_substrings(s):
n = len(s)
result = 0
occurrences = [0] * 26
for i in range(n):
count = 0
for j in range(i, n):
char_idx = ord(s[j]) - ord('a')
if occurrences[char_idx] == 0:
count += 1
occurrences[char_idx] += ... | Title: String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s*. Each pair of numbers *l* and *r* that fulfill the condition 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|, correspond to a substring of the string *s*, starting in the position *l* and ending in the position *r* (inclu... | ```python
def count_substrings(s):
n = len(s)
result = 0
occurrences = [0] * 26
for i in range(n):
count = 0
for j in range(i, n):
char_idx = ord(s[j]) - ord('a')
if occurrences[char_idx] == 0:
count += 1
occurrences[cha... | 0 | |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,607,546,359 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | #Codeforces: solution to problem 676A. Difficulty: 900 (constructive algorithms, implementation)
#Input
n = input()
a = input()
a = a.split()
#Core
low= int()
high= int()
for i in range(int(n)):
if a[i] == '1':
low=i+1
if a[i] == n:
high=i+1
if low < high:
if (low-1) <= (int(n)-high):
... | Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
#Codeforces: solution to problem 676A. Difficulty: 900 (constructive algorithms, implementation)
#Input
n = input()
a = input()
a = a.split()
#Core
low= int()
high= int()
for i in range(int(n)):
if a[i] == '1':
low=i+1
if a[i] == n:
high=i+1
if low < high:
if (low-1) <= (int(n... | 0 | |
165 | B | Burning Midnight Oil | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lin... | The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10. | Print the only integer — the minimum value of *v* that lets Vasya write the program in one night. | [
"7 2\n",
"59 9\n"
] | [
"4\n",
"54\n"
] | In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.
In the second sample the answer is *v* = 54. Vasya writes the code in the following por... | 1,000 | [
{
"input": "7 2",
"output": "4"
},
{
"input": "59 9",
"output": "54"
},
{
"input": "1 9",
"output": "1"
},
{
"input": "11 2",
"output": "7"
},
{
"input": "747 2",
"output": "376"
},
{
"input": "6578 2",
"output": "3293"
},
{
"input": "37212... | 1,674,447,153 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 122 | 0 | def first_match(n,k,start,end,decide):
res = -1
while start <=end :
mid = (start+end)//2
if decide(n,k,mid):
res = mid
end = mid -1
else :
start = mid +1
return res
def decide(n,k,tst):
wrote = tst
while wrote < n :
today = tst // (... | Title: Burning Midnight Oil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of c... | ```python
def first_match(n,k,start,end,decide):
res = -1
while start <=end :
mid = (start+end)//2
if decide(n,k,mid):
res = mid
end = mid -1
else :
start = mid +1
return res
def decide(n,k,tst):
wrote = tst
while wrote < n :
today ... | 0 | |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,690,814,353 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 92 | 0 | n = int(input())
p = input().split()
a = [int(i) for i in p]
m = int(input())
q = input().split()
b = [int(i) for i in q]
c = []
for i in a:
for j in b:
if int(j/i) == j/i:
c.append(j/i)
k=0
for i in c:
if i == max(c):
k+=1
print(k)
| Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
n = int(input())
p = input().split()
a = [int(i) for i in p]
m = int(input())
q = input().split()
b = [int(i) for i in q]
c = []
for i in a:
for j in b:
if int(j/i) == j/i:
c.append(j/i)
k=0
for i in c:
if i == max(c):
k+=1
print(k)
``` | 3 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,657,551,117 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
x = [int(x) for x in input().split()]
cnt = 0
j = 1
for i in range(1,len(x)):
if x[i-1] < x[i]:
cnt = cnt + 1
print(cnt+1)
| Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n = int(input())
x = [int(x) for x in input().split()]
cnt = 0
j = 1
for i in range(1,len(x)):
if x[i-1] < x[i]:
cnt = cnt + 1
print(cnt+1)
``` | 0 | |
719 | A | Vitya in the Countryside | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent. | If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly ... | [
"5\n3 4 5 6 7\n",
"7\n12 13 14 15 14 13 12\n",
"1\n8\n"
] | [
"UP\n",
"DOWN\n",
"-1\n"
] | In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus t... | 500 | [
{
"input": "5\n3 4 5 6 7",
"output": "UP"
},
{
"input": "7\n12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "1\n8",
"output": "-1"
},
{
"input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10",
"out... | 1,474,636,466 | 566 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 61 | 0 | n = int(input())
zikl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] * 2
l = list(map(int, input().split()))
if n == 1:
if l[0] == 0:
print("UP")
else:
print(-1)
for i in range(len(zikl)):
curr = 0
for j in range(len(l)):... | Title: Vitya in the Countryside
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the momen... | ```python
n = int(input())
zikl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] * 2
l = list(map(int, input().split()))
if n == 1:
if l[0] == 0:
print("UP")
else:
print(-1)
for i in range(len(zikl)):
curr = 0
for j in rang... | 0 | |
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,598,940,743 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 248 | 0 | def q99a():
num = input()
dot_loc = num.index('.')
if(num[dot_loc-1] == '9'):
print("GOTO Vasilisa.")
else:
if(int(num[dot_loc+1]) < 5):
print(num[:dot_loc])
else:
print(num[:dot_loc-1], end='')
print(int(num[dot_loc-1])+1)
# num = float(input())
# num_rounded = round(num)
# if(int(num) % 10 != 9)... | Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
def q99a():
num = input()
dot_loc = num.index('.')
if(num[dot_loc-1] == '9'):
print("GOTO Vasilisa.")
else:
if(int(num[dot_loc+1]) < 5):
print(num[:dot_loc])
else:
print(num[:dot_loc-1], end='')
print(int(num[dot_loc-1])+1)
# num = float(input())
# num_rounded = round(num)
# if(int(num) ... | 3.938 |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,685,208,445 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 93 | 3,686,400 | n,k,d=map(int,input().split())
mod=10**9+7
from functools import lru_cache
@lru_cache(maxsize=None)
def calc(x,flag):
if x==0:
return flag
ANS=0
for i in range(1,k+1):
if x>=i:
if i>=d:
ANS+=calc(x-i,1)
else:
ANS+=calc(... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
n,k,d=map(int,input().split())
mod=10**9+7
from functools import lru_cache
@lru_cache(maxsize=None)
def calc(x,flag):
if x==0:
return flag
ANS=0
for i in range(1,k+1):
if x>=i:
if i>=d:
ANS+=calc(x-i,1)
else:
... | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,623,203,584 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 498 | 5,939,200 | from typing import Counter
n=int(input())
l=list(map(int,input().split()))
c=Counter(l)
if ((1 in c) or (3 in c) or (5 in c)) and ((2 in c) or (4 in c)):
print(0)
elif ((1 in c) or (3 in c) or (5 in c)):
print(3)
else:
print(2) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
from typing import Counter
n=int(input())
l=list(map(int,input().split()))
c=Counter(l)
if ((1 in c) or (3 in c) or (5 in c)) and ((2 in c) or (4 in c)):
print(0)
elif ((1 in c) or (3 in c) or (5 in c)):
print(3)
else:
print(2)
``` | 0 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,698,394,532 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
a = []
for i in range(n):
b = input()
a.append(b[0])
print(a.count(0) + 1) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input())
a = []
for i in range(n):
b = input()
a.append(b[0])
print(a.count(0) + 1)
``` | 0 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,588,566,173 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | s=input()
l=[0]*26
m=0
for i in s:
k=ord(i)-97
l[k]+=1
if l[k]>l[m] or (l[k]==l[m] and k>m):
m=k
#print(m)
k1=chr(97+m)
print(k1*l[m])
| Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
s=input()
l=[0]*26
m=0
for i in s:
k=ord(i)-97
l[k]+=1
if l[k]>l[m] or (l[k]==l[m] and k>m):
m=k
#print(m)
k1=chr(97+m)
print(k1*l[m])
``` | 0 | |
290 | D | Orange | PROGRAMMING | 1,400 | [
"*special",
"implementation"
] | null | null | The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive. | Output the required string. | [
"AprilFool\n14\n"
] | [
"AprILFooL\n"
] | none | 0 | [
{
"input": "AprilFool\n14",
"output": "AprILFooL"
},
{
"input": "abcdefabc\n3",
"output": "ABCdefABC"
},
{
"input": "fgWjSAlPOvcAbCdDEFjz\n7",
"output": "FGwjsAlpovCABCDDEFjz"
},
{
"input": "sm\n26",
"output": "SM"
},
{
"input": "GnlFOqPeZtPiBkvvLhaDvGPgFqBTnLgMT\... | 1,638,361,455 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 124 | 0 | alphabet_lower=list('abcdefghijklmnopqrstuvwxyz')
s=input()
s=s.lower()
s=list(s)
count=int(input())
for i in range(len(s)):
if alphabet_lower.index(s[i])<count:
s[i]=s[i].upper()
print(''.join(s)) | Title: Orange
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integ... | ```python
alphabet_lower=list('abcdefghijklmnopqrstuvwxyz')
s=input()
s=s.lower()
s=list(s)
count=int(input())
for i in range(len(s)):
if alphabet_lower.index(s[i])<count:
s[i]=s[i].upper()
print(''.join(s))
``` | 3 | ||
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,338,225 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n=int(input())
string=str(n)
count=0
for i in range(len(n)):
if string[i]==4 or string[i]==7:
count+=1
if count==4 or count==7:
print("YES")
else:
print("NO") | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n=int(input())
string=str(n)
count=0
for i in range(len(n)):
if string[i]==4 or string[i]==7:
count+=1
if count==4 or count==7:
print("YES")
else:
print("NO")
``` | -1 |
690 | C2 | Brain Network (medium) | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology ... | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow.... | Print one number – the brain latency. | [
"4 3\n1 2\n1 3\n1 4\n",
"5 4\n1 2\n2 3\n3 4\n3 5\n"
] | [
"2",
"3"
] | none | 0 | [
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 2\n2 1\n3 2",
"output": "2"
},
{
"input": "10 9\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4",
"output": "6"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n3 5",
"outp... | 1,695,300,988 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 7 | 733 | 20,582,400 | mod = int(1e9+7)
inf = int(1e10)
ans = 0
def solve():
n,m = map(int,input().split())
adj = [[]for i in range(n+5)]
for i in range(m):
a,b=map(int,input().split())
adj[a].append(b)
adj[b].append(a)
def dfs(s,par):
global ans
max1 = 0
max2 = 0
for i in adj[s]:
if i!=par:
res = dfs(i,s)
if res... | Title: Brain Network (medium)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of... | ```python
mod = int(1e9+7)
inf = int(1e10)
ans = 0
def solve():
n,m = map(int,input().split())
adj = [[]for i in range(n+5)]
for i in range(m):
a,b=map(int,input().split())
adj[a].append(b)
adj[b].append(a)
def dfs(s,par):
global ans
max1 = 0
max2 = 0
for i in adj[s]:
if i!=par:
res = dfs(i,s)
... | -1 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,563,555,079 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | # import sys
# sys.stdin=open("input.in","r")
n=int(input())
print(len(set(input().split())-{"0"})) | Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
# import sys
# sys.stdin=open("input.in","r")
n=int(input())
print(len(set(input().split())-{"0"}))
``` | 3 | |
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 4... | 1,511,765,241 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 5,529,600 | n = int(input())
l = list(map(int, input().split()))
ans = 180
for i in range(0, n):
sum = 0
for j in range(i, n):
sum += l[a]
if ans > abs(180 - sum):
ans = abs(180 - sum)
print(ans * 2) | Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut in... | ```python
n = int(input())
l = list(map(int, input().split()))
ans = 180
for i in range(0, n):
sum = 0
for j in range(i, n):
sum += l[a]
if ans > abs(180 - sum):
ans = abs(180 - sum)
print(ans * 2)
``` | -1 | |
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,579,076,512 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 204,800 | n=int(input())
s=input()
a=0
d=0
c=0
x=0
b=0
for i in list(s):
if i=='ABC':
a=a+1
elif(i=='AB'):
d=d+1
elif(i=='A'):
c=c+1
elif(i=='B'):
x=x+1
else:
b=0
if (a>d and a>c and a>x and a>b):
print("ABC")
elif (d>a and d>c and d>x and d>b):
... | 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())
s=input()
a=0
d=0
c=0
x=0
b=0
for i in list(s):
if i=='ABC':
a=a+1
elif(i=='AB'):
d=d+1
elif(i=='A'):
c=c+1
elif(i=='B'):
x=x+1
else:
b=0
if (a>d and a>c and a>x and a>b):
print("ABC")
elif (d>a and d>c and d>x ... | 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,680,426,890 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | def domino_piling(m, n):
return m * n // 2
if __name__ == "__main__":
m, n = map(int, input().split())
print(domino_piling(m, n))
| 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
def domino_piling(m, n):
return m * n // 2
if __name__ == "__main__":
m, n = map(int, input().split())
print(domino_piling(m, n))
``` | 3.977 |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,670,835,329 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 4 | 77 | 3,072,000 | s=input()
a=len(s)
for i in range(0,a//2):
if s[i]==s[-1-i] :
pass
else:
b=str(s[0:i]+s[-1-i]+s[i+1:a])
break
if b[0:a]==b[::-1] :
print("YES")
else:
print("NO") | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
s=input()
a=len(s)
for i in range(0,a//2):
if s[i]==s[-1-i] :
pass
else:
b=str(s[0:i]+s[-1-i]+s[i+1:a])
break
if b[0:a]==b[::-1] :
print("YES")
else:
print("NO")
``` | -1 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,690,552,799 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | while True:
m=int(input())
n=input()
if m == len(n):
break
so_lan_x = 0
so_lan_xoa = 0
for i in range(0,len(n)):
if n[i] == 'x':
so_lan_x += 1
if n[i] != 'x':
so_lan_x = 0
if so_lan_x > 2:
so_lan_xoa += 1
print(so_lan_x) | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
while True:
m=int(input())
n=input()
if m == len(n):
break
so_lan_x = 0
so_lan_xoa = 0
for i in range(0,len(n)):
if n[i] == 'x':
so_lan_x += 1
if n[i] != 'x':
so_lan_x = 0
if so_lan_x > 2:
so_lan_xoa += 1
print(so_lan_x)
``` | 0 | |
103 | A | Testing Pants for Sadness | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | A. Testing Pants for Sadness | 2 | 256 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. | Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] | [
"2",
"5",
"10"
] | Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the ... | 500 | [
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "... | 1,593,866,414 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 280 | 0 | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
n = iinput()
A = rlinput()
ans = 0
for i in range(n)... | Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* q... | ```python
import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
n = iinput()
A = rlinput()
ans = 0
for i i... | 0 |
453 | A | Little Pony and Expected Maximum | PROGRAMMING | 1,600 | [
"probabilities"
] | null | null | Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots... | A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105). | Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4. | [
"6 1\n",
"6 3\n",
"2 2\n"
] | [
"3.500000000000\n",
"4.958333333333\n",
"1.750000000000\n"
] | Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in t... | 500 | [
{
"input": "6 1",
"output": "3.500000000000"
},
{
"input": "6 3",
"output": "4.958333333333"
},
{
"input": "2 2",
"output": "1.750000000000"
},
{
"input": "5 4",
"output": "4.433600000000"
},
{
"input": "5 8",
"output": "4.814773760000"
},
{
"input": "... | 1,672,316,570 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 124 | 0 | m, n = map(int, input().split())
def N(x):
if x ==1:
return 1
return x**n - (x-1)**n
expect_max = 0
for x in range(1,m+1):
expect_max+=x*(((x/m)**n)-(((x-1)/m)**n))
print(expect_max) | Title: Little Pony and Expected Maximum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were ... | ```python
m, n = map(int, input().split())
def N(x):
if x ==1:
return 1
return x**n - (x-1)**n
expect_max = 0
for x in range(1,m+1):
expect_max+=x*(((x/m)**n)-(((x-1)/m)**n))
print(expect_max)
``` | 3 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,680,165,670 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def countOnes(n, l, r):
count = 0
for i in range(l, r+1):
if n % i == 0:
count += 1
return count
n = int(input())
l = int(input())
r = int(input())
count = countOnes(n, l, r)
print(count)
| Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
def countOnes(n, l, r):
count = 0
for i in range(l, r+1):
if n % i == 0:
count += 1
return count
n = int(input())
l = int(input())
r = int(input())
count = countOnes(n, l, r)
print(count)
``` | -1 | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,693,212,659 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import math
for i in range(int(input())):
gcd=0
a,b=map(int,input().split())
x=math.factorial(a)
y=math.factorial(b)
if x>y:
temp=y
else:
temp=x
for i in range(1,temp+1):
if(a%i==0)and(b%i==0):
gcd=i
print(gcd)
| Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
for i in range(int(input())):
gcd=0
a,b=map(int,input().split())
x=math.factorial(a)
y=math.factorial(b)
if x>y:
temp=y
else:
temp=x
for i in range(1,temp+1):
if(a%i==0)and(b%i==0):
gcd=i
print(gcd)
``` | -1 | |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,632,549,889 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 139 | 30,003,200 | """
Summary of Code:
- Gets the string, convert it to string
- change the substring of the same letter with minimum difference
Time Complexity:
- O(2N) => O(N)
Space Complexity:
- O(N)
Why the chosen algorithm are good:
- the maximum of N is 2*10^5 and time complexity is O(N)
- thus it should be fast enough
"""
s = ... | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wa... | ```python
"""
Summary of Code:
- Gets the string, convert it to string
- change the substring of the same letter with minimum difference
Time Complexity:
- O(2N) => O(N)
Space Complexity:
- O(N)
Why the chosen algorithm are good:
- the maximum of N is 2*10^5 and time complexity is O(N)
- thus it should be fast enoug... | 3 | |
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,656,408,547 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | # Abu Hurayra
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in... | 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
# Abu Hurayra
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x... | 0 | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,617,758,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def criaMonte(origem, destino, cont):
if origem[0] == destino[0] or origem[1] == destino[1]:
return cont
else:
distancia_y = abs(destino[1] - origem[1])
distancia_x = abs(destino[0] - origem[0])
if(distancia_y < distancia_x):
if origem[1] < destino[1]:
... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
def criaMonte(origem, destino, cont):
if origem[0] == destino[0] or origem[1] == destino[1]:
return cont
else:
distancia_y = abs(destino[1] - origem[1])
distancia_x = abs(destino[0] - origem[0])
if(distancia_y < distancia_x):
if origem[1] < destino[1]:
... | 0 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,645,693,802 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 109 | 614,400 | import collections, math, bisect, sys
from collections import OrderedDict, Counter, defaultdict
from sys import stdin, stdout
import string
def get_line(): return list(map(int, sys.stdin.readline().strip().split()))
def in1(): return int(stdin.readline())
def display_arr(arr): stdout.write(" ".join(map(... | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
import collections, math, bisect, sys
from collections import OrderedDict, Counter, defaultdict
from sys import stdin, stdout
import string
def get_line(): return list(map(int, sys.stdin.readline().strip().split()))
def in1(): return int(stdin.readline())
def display_arr(arr): stdout.write(" "... | 3 | |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,527,486,124 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def docfile():
f = open('', 'r')
line = f.readline()
return line
if __name__ == "__main__":
word = input()
while word == word[::-1]:
word == word[0:-1]
return len(word)
| Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
def docfile():
f = open('', 'r')
line = f.readline()
return line
if __name__ == "__main__":
word = input()
while word == word[::-1]:
word == word[0:-1]
return len(word)
``` | -1 | |
152 | C | Pocket Book | PROGRAMMING | 1,400 | [
"combinatorics"
] | null | null | One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. | Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). | [
"2 3\nAAB\nBAA\n",
"4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n"
] | [
"4\n",
"216\n"
] | In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | 1,500 | [
{
"input": "2 3\nAAB\nBAA",
"output": "4"
},
{
"input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA",
"output": "216"
},
{
"input": "1 1\nE",
"output": "1"
},
{
"input": "2 2\nNS\nPD",
"output": "4"
},
{
"input": "3 4\nPJKD\nNFJX\nFGFK",
"output": "81"
},
{
"inpu... | 1,623,159,956 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | n, m = map(int, input().split())
tp = [ [' '] for i in range(m) ]
for i in range(n):
a = input()
for j in range(m):
if not a[j] in tp[j]:
tp[j].append(a[j])
c = 1
for i in range(n):
c*=len(tp[i])-1
print((c*2)%1000000007) | Title: Pocket Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
... | ```python
n, m = map(int, input().split())
tp = [ [' '] for i in range(m) ]
for i in range(n):
a = input()
for j in range(m):
if not a[j] in tp[j]:
tp[j].append(a[j])
c = 1
for i in range(n):
c*=len(tp[i])-1
print((c*2)%1000000007)
``` | 0 | |
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO"... | 1,661,606,326 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | S=input()
if len(S)==1 or S!=S[::-1]:
print('NO')
else:
Nb=0
for i in S:
if i in "BCDEFGJKLNPQRSZ"
Nb=1
break
if Nb==0:
print('YES')
else:
print('NO')
| Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of ... | ```python
S=input()
if len(S)==1 or S!=S[::-1]:
print('NO')
else:
Nb=0
for i in S:
if i in "BCDEFGJKLNPQRSZ"
Nb=1
break
if Nb==0:
print('YES')
else:
print('NO')
``` | -1 | |
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,472,001,517 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 4,608,000 | n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = a[0]
for i in range(1,len(a)):
if a[i]==a[i-1]:
ans += a[i]-1
else:
ans += a[i]
print(ans) | 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
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = a[0]
for i in range(1,len(a)):
if a[i]==a[i-1]:
ans += a[i]-1
else:
ans += a[i]
print(ans)
``` | 0 | |
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"in... | 1,637,249,474 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | text=input()
l=len(text)
zero=0
one=0
a=0
for i in range(l):
if text[i]=='0':
one=0
zero=zero+1
if zero>=7:
a=1
break
elif text[i]=='1':
zero=0
one=one+1
if one>=7:
a=1
break
... | Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after eve... | ```python
text=input()
l=len(text)
zero=0
one=0
a=0
for i in range(l):
if text[i]=='0':
one=0
zero=zero+1
if zero>=7:
a=1
break
elif text[i]=='1':
zero=0
one=one+1
if one>=7:
a=1
... | 0 | |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,560,716,255 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int portion = 0;
for (int i = 0; i < n; ++i) {
int w;
cin >> w;
portion += (w + k - 1) / k;
}
cout << (portion + 1) / 2;
return 0;
}
| Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
#include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int portion = 0;
for (int i = 0; i < n; ++i) {
int w;
cin >> w;
portion += (w + k - 1) / k;
}
cout << (portion + 1) / 2;
return 0;
}
``` | -1 | |
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,649,253,933 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | n = input()
hello = ("hello")
count = 0
for i in range(len(n)):
if n[i]== hello[count]:
count+= 1
if count == 5:
break
if count == 5:
print('YES')
else:
print('NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
n = input()
hello = ("hello")
count = 0
for i in range(len(n)):
if n[i]== hello[count]:
count+= 1
if count == 5:
break
if count == 5:
print('YES')
else:
print('NO')
``` | 3.977 |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,686,128,826 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n=int(input())
l=list(map(int,input().split()))
mi,ma=l[0],l[0]
c=0
for i in range(1,n):
if mi>l[i]:
mi=l[i]
c+=1
elif ma<l[i]:
ma=l[i]
c+=1
print(c)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
l=list(map(int,input().split()))
mi,ma=l[0],l[0]
c=0
for i in range(1,n):
if mi>l[i]:
mi=l[i]
c+=1
elif ma<l[i]:
ma=l[i]
c+=1
print(c)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 0 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,508,055,131 | 431 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 5,529,600 | n,m=map(int,input().split())
ar1=list(map(int,input().split()))
ar2=list(map(int,input().split()))
ar1.sort()
ar2.sort()
num=0
if(ar1[0]==ar2[0]):
print(ar1[0])
elif(ar1[0]<ar2[0]):
num=ar1[0]
num=num*10+ar2[0]
print(num)
else:
num=ar2[0]
num=num*10+ar1[0]
print(num)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty... | ```python
n,m=map(int,input().split())
ar1=list(map(int,input().split()))
ar2=list(map(int,input().split()))
ar1.sort()
ar2.sort()
num=0
if(ar1[0]==ar2[0]):
print(ar1[0])
elif(ar1[0]<ar2[0]):
num=ar1[0]
num=num*10+ar2[0]
print(num)
else:
num=ar2[0]
num=num*10+ar1[0]
print(num)
``` | 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,560,753,867 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | a, b = map(int, input().split())
player1 = 0
player2 = 0
draw = 0
for i in range(1, 7):
if abs(a - i) < abs(b - i):
player1 = player1 + 1
elif abs(a - i) > abs(b - i):
player2 = player2 + 1
else:
... | 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
a, b = map(int, input().split())
player1 = 0
player2 = 0
draw = 0
for i in range(1, 7):
if abs(a - i) < abs(b - i):
player1 = player1 + 1
elif abs(a - i) > abs(b - i):
player2 = player2 + 1
... | 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,672,949,234 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | data = list(iter(input, '')) # собираем вводные данные
data.pop(0) # удалем цифру в начале
def func(x): # создаем функцию преобразователь
a = list(x) # сразу с построчным выводом переменных
b = len(a)
c = a[0]
d = a[-1]
e = (b - 2)
if b >= 10:
return print(c, e, d, sep="... | 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
data = list(iter(input, '')) # собираем вводные данные
data.pop(0) # удалем цифру в начале
def func(x): # создаем функцию преобразователь
a = list(x) # сразу с построчным выводом переменных
b = len(a)
c = a[0]
d = a[-1]
e = (b - 2)
if b >= 10:
return print(c, e... | -1 |
412 | A | Poster | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a l... | The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or di... | In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th ac... | [
"2 2\nR1\n",
"2 1\nR1\n",
"6 4\nGO?GO!\n"
] | [
"PRINT 1\nLEFT\nPRINT R\n",
"PRINT R\nRIGHT\nPRINT 1\n",
"RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n"
] | Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | 500 | [
{
"input": "2 2\nR1",
"output": "PRINT 1\nLEFT\nPRINT R"
},
{
"input": "2 1\nR1",
"output": "PRINT R\nRIGHT\nPRINT 1"
},
{
"input": "6 4\nGO?GO!",
"output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"
},
{
"input": "7 3\n... | 1,594,698,368 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 155 | 20,172,800 | l1 = [int(x) for x in input().split()]
n,k = l1[0],l1[1]
# 1 2 3 4 5 6 7 8
#
l2 = list(input())
if k > (n+1)/2:
i=k-1
while i<n-1:
print("RIGHT")
i+=1
l2.reverse()
i=0
while i<n:
print("PRINT",l2[i])
if i!=n-1:print("LEFT")
i+=1
... | Title: Poster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the... | ```python
l1 = [int(x) for x in input().split()]
n,k = l1[0],l1[1]
# 1 2 3 4 5 6 7 8
#
l2 = list(input())
if k > (n+1)/2:
i=k-1
while i<n-1:
print("RIGHT")
i+=1
l2.reverse()
i=0
while i<n:
print("PRINT",l2[i])
if i!=n-1:print("LEFT")
... | 3 | |
893 | B | Beautiful Divisors | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes.
Some examples of beautiful numbers:
- 12 (110); - 1102 (610); - 11110002 (12010); - 1111100... | The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got. | Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. | [
"3\n",
"992\n"
] | [
"1\n",
"496\n"
] | none | 0 | [
{
"input": "3",
"output": "1"
},
{
"input": "992",
"output": "496"
},
{
"input": "81142",
"output": "1"
},
{
"input": "76920",
"output": "120"
},
{
"input": "2016",
"output": "2016"
},
{
"input": "1",
"output": "1"
},
{
"input": "6",
"o... | 1,603,867,310 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 140 | 0 | import sys, bisect
n = int(sys.stdin.readline())
ans = 0
for i in range(10):
temp = '1' * (i + 1) + '0' * i
if n % (int(temp, base=2)) == 0:
ans = int(temp, base=2)
print(ans) | Title: Beautiful Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive ze... | ```python
import sys, bisect
n = int(sys.stdin.readline())
ans = 0
for i in range(10):
temp = '1' * (i + 1) + '0' * i
if n % (int(temp, base=2)) == 0:
ans = int(temp, base=2)
print(ans)
``` | 3 | |
988 | B | Substrings Sort | PROGRAMMING | 1,100 | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su... | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | 0 | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "Y... | 1,630,248,693 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 108 | 20,172,800 | s = sorted((input() for i in range(int(input()))),key = len)
if all(x in y for x,y in zip(s,s[1:])):
print("YES")
print(*s,sep = ' ')
else:
print("NO")
| Title: Substrings Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String ... | ```python
s = sorted((input() for i in range(int(input()))),key = len)
if all(x in y for x,y in zip(s,s[1:])):
print("YES")
print(*s,sep = ' ')
else:
print("NO")
``` | 3 | |
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,670,280,632 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int dfs(int a, int vis[],vector<int> edge[],int depth){
vis[a]=1;
int x=depth;
for (auto s:edge[a]){
if(vis[s]==0) depth =max(depth,dfs(s,vis,edge,x+1));
}
return depth;
}
int main(){
int n,m,cnt=0;
cin>>n;
vector<i... | 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
#include <bits/stdc++.h>
using namespace std;
int dfs(int a, int vis[],vector<int> edge[],int depth){
vis[a]=1;
int x=depth;
for (auto s:edge[a]){
if(vis[s]==0) depth =max(depth,dfs(s,vis,edge,x+1));
}
return depth;
}
int main(){
int n,m,cnt=0;
cin>>n;
... | -1 | |
754 | A | Lesha and array splitting | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*. | If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *... | [
"3\n1 2 -3\n",
"8\n9 -12 3 4 -4 -10 7 3\n",
"1\n0\n",
"4\n1 2 3 -5\n"
] | [
"YES\n2\n1 2\n3 3\n",
"YES\n2\n1 2\n3 8\n",
"NO\n",
"YES\n4\n1 1\n2 2\n3 3\n4 4\n"
] | none | 500 | [
{
"input": "3\n1 2 -3",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "8\n9 -12 3 4 -4 -10 7 3",
"output": "YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "4\n1 2 3 -5",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
... | 1,640,692,684 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input()
lst=list(map(int,input().split()))
sum=0
for i in range(n):
sum=lst[i]+sum
if(sum==0):
print("NO")
elif(sum):
print("YES\n1\n1")
else:
print("YES\n[2]\n[1]\n,sum,sum+1") | Title: Lesha and array splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that t... | ```python
n=int(input()
lst=list(map(int,input().split()))
sum=0
for i in range(n):
sum=lst[i]+sum
if(sum==0):
print("NO")
elif(sum):
print("YES\n1\n1")
else:
print("YES\n[2]\n[1]\n,sum,sum+1")
``` | -1 | |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,607,147,707 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<stdio.h>
using namespace std;
int main(){
int
}
| Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
#include<stdio.h>
using namespace std;
int main(){
int
}
``` | -1 | |
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,679,232,416 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a = input()
x = [1,2,3,4,5,6,7,8,9]
sum=0
for i in a:
sum+=int(i)
print(i,end="")
print(10-sum)
| 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
a = input()
x = [1,2,3,4,5,6,7,8,9]
sum=0
for i in a:
sum+=int(i)
print(i,end="")
print(10-sum)
``` | 0 | |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t... | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guarant... | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ... | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "3... | 1,680,685,953 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 31 | 0 | n = int(input())
counter_pos , counter_neg = 0 , 0
data_pos =[]
data_neg =[]
for i in range(n) :
s = list(map(int ,input().split()))
if s[0] > 0 :
counter_pos += 1
data_pos.append(s)
else :
counter_neg += 1
data_neg.append(s)
res = 0
if counter_neg == 0 :... | Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree num... | ```python
n = int(input())
counter_pos , counter_neg = 0 , 0
data_pos =[]
data_neg =[]
for i in range(n) :
s = list(map(int ,input().split()))
if s[0] > 0 :
counter_pos += 1
data_pos.append(s)
else :
counter_neg += 1
data_neg.append(s)
res = 0
if counter_... | 0 | |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,451,139,058 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | N = int(input())
cashiers = []
K_unused = input().split()
for i in range(N):
qu_sum = 0
tmp = list(map(int, input().split()))
queue = len(tmp)
for e in tmp:
qu_sum += (e*5) + 15
cashiers.append(qu_sum)
print(min(cashiers))
| Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
N = int(input())
cashiers = []
K_unused = input().split()
for i in range(N):
qu_sum = 0
tmp = list(map(int, input().split()))
queue = len(tmp)
for e in tmp:
qu_sum += (e*5) + 15
cashiers.append(qu_sum)
print(min(cashiers))
``` | 3 | |
412 | B | Network Configuration | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* deno... | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | [
"3 2\n40 20 30\n",
"6 4\n100 20 40 20 50 50\n"
] | [
"30\n",
"40\n"
] | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | 1,000 | [
{
"input": "3 2\n40 20 30",
"output": "30"
},
{
"input": "6 4\n100 20 40 20 50 50",
"output": "40"
},
{
"input": "1 1\n16",
"output": "16"
},
{
"input": "2 1\n10000 17",
"output": "10000"
},
{
"input": "2 2\n200 300",
"output": "200"
},
{
"input": "3 1... | 1,631,544,129 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,758,400 | n, k = map(int, input().split())
l = list(map(int, input().split()))
print(sum(l) // n * 10) | Title: Network Configuration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly a... | ```python
n, k = map(int, input().split())
l = list(map(int, input().split()))
print(sum(l) // n * 10)
``` | 0 | |
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number t... | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the nu... | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
... | 1,506,794,749 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 62 | 0 | n = int(input())
A = set()
for _ in range(n):
A.add(int(input()))
if len(A) == 2:
print('YES')
A = list(A)
print(A[0], A[1])
else:
print('NO') | Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (di... | ```python
n = int(input())
A = set()
for _ in range(n):
A.add(int(input()))
if len(A) == 2:
print('YES')
A = list(A)
print(A[0], A[1])
else:
print('NO')
``` | 0 | |
855 | B | Marvolo Gaunt's Ring | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"dp"
] | null | null | Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he... | First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. | [
"5 1 2 3\n1 2 3 4 5\n",
"5 1 2 -3\n-1 -2 -3 -4 -5\n"
] | [
"30\n",
"12\n"
] | In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.
In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12. | 1,000 | [
{
"input": "5 1 2 3\n1 2 3 4 5",
"output": "30"
},
{
"input": "5 1 2 -3\n-1 -2 -3 -4 -5",
"output": "12"
},
{
"input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777",
"output": "376059240645059046"
},
{
"input": "4 -96405765 -495906217 6... | 1,584,062,855 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 307,200 | #!/usr/bin/python3
# -*- coding: UTF-8 -*-
from math import inf
# Função que lê uma quantidade qualquer de inteiros em uma só linha
read_int = lambda string: list(map(int, string.split()))
def max_sum(k, arr, y):
x = -inf
for i in range(len(arr)):
x = max(x, k * arr[i] + y)
return x
def main():
n, p, q, r =... | Title: Marvolo Gaunt's Ring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed i... | ```python
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
from math import inf
# Função que lê uma quantidade qualquer de inteiros em uma só linha
read_int = lambda string: list(map(int, string.split()))
def max_sum(k, arr, y):
x = -inf
for i in range(len(arr)):
x = max(x, k * arr[i] + y)
return x
def main():
n,... | 0 | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,693,824,981 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 92 | 0 | #Представте себя в яблонинивем саду лежашем на траве, слева обдувает прохладный ветерок, а ты в ожидании своего нового вертолёта#
n=list(input())
for i in n:
if i not in 'aeiouAEIOU':
print('.'+i.lower(),end='')
| 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=list(input())
for i in n:
if i not in 'aeiouAEIOU':
print('.'+i.lower(),end='')
``` | 0 | |
350 | B | Resort | PROGRAMMING | 1,500 | [
"graphs"
] | null | null | Valera's finally decided to go on holiday! He packed up and headed for a ski resort.
Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n* objects (we will consider the objects indexed in some way by integers from 1 to *n*), each ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of objects.
The second line contains *n* space-separated integers *type*1,<=*type*2,<=...,<=*type**n* — the types of the objects. If *type**i* equals zero, then the *i*-th object is the mountain. If *type**i* equals one, then the *i*-th object is the... | In the first line print *k* — the maximum possible path length for Valera. In the second line print *k* integers *v*1,<=*v*2,<=...,<=*v**k* — the path. If there are multiple solutions, you can print any of them. | [
"5\n0 0 0 0 1\n0 1 2 3 4\n",
"5\n0 0 1 0 1\n0 1 2 2 4\n",
"4\n1 0 0 0\n2 3 4 2\n"
] | [
"5\n1 2 3 4 5\n",
"2\n4 5\n",
"1\n1\n"
] | none | 1,000 | [
{
"input": "5\n0 0 0 0 1\n0 1 2 3 4",
"output": "5\n1 2 3 4 5"
},
{
"input": "5\n0 0 1 0 1\n0 1 2 2 4",
"output": "2\n4 5"
},
{
"input": "4\n1 0 0 0\n2 3 4 2",
"output": "1\n1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 1\n4 0 8 4 7 8 5 5 7 2",
"output": "2\n2 10"
},
{
... | 1,603,159,632 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
using namespace std;
pair<int, vector<int>> getAns(int f, int *paths, bool *types, bool *more_than_one) {
vector<int> res;
if (types[f]) {
res.push_back(f);
return make_pair(1, res);
}
if (more_than_one[f] || paths[f] == -1) {
ret... | Title: Resort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera's finally decided to go on holiday! He packed up and headed for a ski resort.
Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n*... | ```python
#include <iostream>
#include <vector>
using namespace std;
pair<int, vector<int>> getAns(int f, int *paths, bool *types, bool *more_than_one) {
vector<int> res;
if (types[f]) {
res.push_back(f);
return make_pair(1, res);
}
if (more_than_one[f] || paths[f] == -1) {
... | -1 | |
18 | A | Triangle | PROGRAMMING | 1,500 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t... | The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero. | If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER. | [
"0 0 2 0 0 1\n",
"2 3 4 5 6 6\n",
"-1 0 2 0 0 1\n"
] | [
"RIGHT\n",
"NEITHER\n",
"ALMOST\n"
] | none | 0 | [
{
"input": "0 0 2 0 0 1",
"output": "RIGHT"
},
{
"input": "2 3 4 5 6 6",
"output": "NEITHER"
},
{
"input": "-1 0 2 0 0 1",
"output": "ALMOST"
},
{
"input": "27 74 85 23 100 99",
"output": "NEITHER"
},
{
"input": "-97 -19 17 62 30 -76",
"output": "NEITHER"
},... | 1,691,252,200 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | def triangle(pt):
a = (pt[0] - pt[2]) **2 + (pt[1] - pt[3]) **2
b = (pt[0] - pt[4]) **2 + (pt[1] - pt[5]) **2
c = (pt[2] - pt[4]) **2 + (pt[3] - pt[5]) **2
return a and b and c and (a + b == c or a + c == b or b + c == a)
pt = list(map(int, input().strip().split()))
if triangle(point):
... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer co... | ```python
def triangle(pt):
a = (pt[0] - pt[2]) **2 + (pt[1] - pt[3]) **2
b = (pt[0] - pt[4]) **2 + (pt[1] - pt[5]) **2
c = (pt[2] - pt[4]) **2 + (pt[3] - pt[5]) **2
return a and b and c and (a + b == c or a + c == b or b + c == a)
pt = list(map(int, input().strip().split()))
if triangle... | -1 |
329 | A | Purification | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy"
] | null | null | You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* from top to bottom, and the columns are numbered 1 through *n* from left to right. At the far side... | The first line will contain a single integer *n* (1<=≤<=*n*<=≤<=100). Then, *n* lines follows, each contains *n* characters. The *j*-th character in the *i*-th row represents the cell located at row *i* and column *j*. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise. | If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts *x* "Purification" spells (where *x* is the minimum possible number of spells), output *x* lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purificati... | [
"3\n.E.\nE.E\n.E.\n",
"3\nEEE\nE..\nE.E\n",
"5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE\n"
] | [
"1 1\n2 2\n3 3\n",
"-1\n",
"3 3\n1 3\n2 2\n4 4\n5 3"
] | The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
In the se... | 500 | [
{
"input": "3\n.E.\nE.E\n.E.",
"output": "1 1\n2 2\n3 1"
},
{
"input": "3\nEEE\nE..\nE.E",
"output": "-1"
},
{
"input": "5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE",
"output": "1 3\n2 2\n3 2\n4 1\n5 3"
},
{
"input": "3\n.EE\n.EE\n.EE",
"output": "1 1\n2 1\n3 1"
},
{
"in... | 1,625,331,984 | 2,147,483,647 | PyPy 3 | OK | TESTS | 65 | 312 | 2,560,000 | import traceback
import math
from collections import defaultdict
from functools import lru_cache
def main():
N = int(input())
grid = []
for _ in range(N):
s = input()
grid.append(s)
if all('.' in [grid[i][j] for j in range(N)] for i in range(N)):
for i in ran... | Title: Purification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* ... | ```python
import traceback
import math
from collections import defaultdict
from functools import lru_cache
def main():
N = int(input())
grid = []
for _ in range(N):
s = input()
grid.append(s)
if all('.' in [grid[i][j] for j in range(N)] for i in range(N)):
fo... | 3 | |
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to deter... | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n0000010010101... | 1,610,038,585 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 139 | 0 | n=int(input())
s=input()
out=0
tmp=0
i=0
while i<len(s)-1:
if(s[i]=='0' and s[i+1]=='1' or s[i]=='1' and s[i+1]=='0'):
tmp+=2
out=max(out,tmp)
i+=2
else:
if(tmp>0):
i-=1
else:
i+=1
tmp=0
print(out)
| Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called... | ```python
n=int(input())
s=input()
out=0
tmp=0
i=0
while i<len(s)-1:
if(s[i]=='0' and s[i+1]=='1' or s[i]=='1' and s[i+1]=='0'):
tmp+=2
out=max(out,tmp)
i+=2
else:
if(tmp>0):
i-=1
else:
i+=1
tmp=0
print(out)
``` | 0 | |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,672,060,910 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n = int(input())
lst = list(map(int,input().split(" ")))[:n]
ans,prev = 0,10**5
for i in lst:
if prev-i<0:
ans+=abs(i-prev)
prev = i
if ans ==0:
print(lst[0])
else:
print(ans+1) | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
n = int(input())
lst = list(map(int,input().split(" ")))[:n]
ans,prev = 0,10**5
for i in lst:
if prev-i<0:
ans+=abs(i-prev)
prev = i
if ans ==0:
print(lst[0])
else:
print(ans+1)
``` | 0 | |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,661,520,105 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | import math
tc = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse = True)
c = 0
for i in range(tc):
c += (-1 if i % 2 == 1 else 1) * arr[i] ** 2
print(c * math.pi) | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
import math
tc = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse = True)
c = 0
for i in range(tc):
c += (-1 if i % 2 == 1 else 1) * arr[i] ** 2
print(c * math.pi)
``` | 3 | |
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T... | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<... | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "5287... | 1,698,146,799 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import sys
input = sys.stdin.readline
| Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f... | ```python
import sys
input = sys.stdin.readline
``` | 0 |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,558,700,237 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 202 | 409,600 | n = int(input())
s = input()
keys = ''
cnt = 0
for i in range((n*2)-2):
if i % 2 == 0:
keys += s[i]
else:
if keys.count(s[i].lower()) > 0:
keys = keys.replace(s[i].lower(), '')
else:
cnt += 1
print(cnt)
| Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
n = int(input())
s = input()
keys = ''
cnt = 0
for i in range((n*2)-2):
if i % 2 == 0:
keys += s[i]
else:
if keys.count(s[i].lower()) > 0:
keys = keys.replace(s[i].lower(), '')
else:
cnt += 1
print(cnt)
``` | 0 | |
771 | B | Bear and Different Names | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy"
] | null | null | In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).
A group of soldiers is effective if and only if their names... | The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=50) — the number of soldiers and the size of a group respectively.
The second line contains *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1. The string *s**i* is "YES" if the group of soldiers *i* through *i*<=+<=*k... | Find any solution satisfying all given conditions. In one line print *n* space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10.
... | [
"8 3\nNO NO YES YES YES NO\n",
"9 8\nYES NO\n",
"3 2\nNO NO\n"
] | [
"Adam Bob Bob Cpqepqwer Limak Adam Bob Adam",
"R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc",
"Na Na Na"
] | In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:
- First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string *s*<sub class="lower-index">1</... | 500 | [
{
"input": "8 3\nNO NO YES YES YES NO",
"output": "Ab Ac Ab Ac Af Ag Ah Ag "
},
{
"input": "9 8\nYES NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Ac "
},
{
"input": "3 2\nNO NO",
"output": "Ab Ab Ab "
},
{
"input": "2 2\nYES",
"output": "Ab Ac "
},
{
"input": "2 2\nNO"... | 1,489,853,800 | 2,500 | PyPy 3 | WRONG_ANSWER | PRETESTS | 0 | 124 | 23,142,400 | names = ["A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "Aa",
"Bb", "Cc", "Dd", "Ee", "Ff", "Gg", "Hh", "Ii",
"Jj", "Kk", "Ll", "Mm", "Nn", "Oo", "Pp", "Qq", "Rr",
"Ss", "Tt", "Uu", "Vv", "Ww"... | Title: Bear and Different Names
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an orde... | ```python
names = ["A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "Aa",
"Bb", "Cc", "Dd", "Ee", "Ff", "Gg", "Hh", "Ii",
"Jj", "Kk", "Ll", "Mm", "Nn", "Oo", "Pp", "Qq", "Rr",
"Ss", "Tt", "Uu", ... | 0 | |
599 | B | Spongebob and Joke | PROGRAMMING | 1,500 | [
"implementation"
] | null | null | While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence *a*1,<=*a*2,<=...,<=*a**m* of length *m*, consisting of integers from 1 to *n*, not necessarily distinct. Then he picked some sequence *f*1,<=*f*2,<=.... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — the lengths of sequences *f**i* and *b**i* respectively.
The second line contains *n* integers, determining sequence *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*).
The last line contains *m* integers, determining sequen... | Print "Possible" if there is exactly one sequence *a**i*, such that *b**i*<==<=*f**a**i* for all *i* from 1 to *m*. Then print *m* integers *a*1,<=*a*2,<=...,<=*a**m*.
If there are multiple suitable sequences *a**i*, print "Ambiguity".
If Spongebob has made a mistake in his calculations and no suitable sequence *a**i... | [
"3 3\n3 2 1\n1 2 3\n",
"3 3\n1 1 1\n1 1 1\n",
"3 3\n1 2 1\n3 3 3\n"
] | [
"Possible\n3 2 1 \n",
"Ambiguity\n",
"Impossible\n"
] | In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique.
In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence.
In the third sample *f*<sub class="lower-index">*i*</sub> ≠ 3 for all *i*, so no sequen... | 1,000 | [
{
"input": "3 3\n3 2 1\n1 2 3",
"output": "Possible\n3 2 1 "
},
{
"input": "3 3\n1 1 1\n1 1 1",
"output": "Ambiguity"
},
{
"input": "3 3\n1 2 1\n3 3 3",
"output": "Impossible"
},
{
"input": "2 100\n2 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | 1,678,971,312 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 280 | 13,824,000 | n, m = map(int, input().split())
f, b = [int(e) for e in input().split()], [int(e) for e in input().split()]
F, l = {}, []
for e, u in enumerate(f):
if u in F:
F[u] = 0
else:
F[u] = e+1
for e in b:
if e in F:
if F[e] > 0:
l += [F[e]]
else:
print('... | Title: Spongebob and Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence *a*1,<=*a*2,<=...,<=*a**m* of length *m*, cons... | ```python
n, m = map(int, input().split())
f, b = [int(e) for e in input().split()], [int(e) for e in input().split()]
F, l = {}, []
for e, u in enumerate(f):
if u in F:
F[u] = 0
else:
F[u] = e+1
for e in b:
if e in F:
if F[e] > 0:
l += [F[e]]
else:
... | 3 | |
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
... | 1,655,755,714 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n = int (input() )
if n>4:
up = 10
else:
up = 0
ans = n - (n%10) + up
r = n % 10
down = n - r
print (ans) | Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5... | ```python
n = int (input() )
if n>4:
up = 10
else:
up = 0
ans = n - (n%10) + up
r = n % 10
down = n - r
print (ans)
``` | 0 | |
478 | A | Initial Bet | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program ... | The input consists of a single line containing five integers *c*1,<=*c*2,<=*c*3,<=*c*4 and *c*5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0<=≤<=*c*1,<=*c*2,<=*c*3,<=*c*4,<=*c*5<=≤<=100). | Print the only line containing a single positive integer *b* — the number of coins in the initial bet of each player. If there is no such value of *b*, then print the only value "-1" (quotes for clarity). | [
"2 5 4 0 4\n",
"4 5 9 2 1\n"
] | [
"3\n",
"-1\n"
] | In the first sample the following sequence of operations is possible:
1. One coin is passed from the fourth player to the second player; 1. One coin is passed from the fourth player to the fifth player; 1. One coin is passed from the first player to the third player; 1. One coin is passed from the fourth player to... | 500 | [
{
"input": "2 5 4 0 4",
"output": "3"
},
{
"input": "4 5 9 2 1",
"output": "-1"
},
{
"input": "0 0 0 0 0",
"output": "-1"
},
{
"input": "1 2 1 2 3",
"output": "-1"
},
{
"input": "100 0 0 0 0",
"output": "20"
},
{
"input": "2 3 4 5 6",
"output": "4"... | 1,652,892,716 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 4,300,800 | arr = tuple(map(int,input().split()))
x,sm = min(arr)-max(arr),sum(arr)
if x == 0:print(-1)
else:
print(sm // len(arr) if sm % x == 0 else -1) | Title: Initial Bet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for severa... | ```python
arr = tuple(map(int,input().split()))
x,sm = min(arr)-max(arr),sum(arr)
if x == 0:print(-1)
else:
print(sm // len(arr) if sm % x == 0 else -1)
``` | 0 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,446,311,472 | 2,472 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 0 | a = list(map(int , input().split()))
t = a[0]
w = a[1]
b = a[2]
#val = gcd(w,b)
cnt = 0
for i in range(1,t+1):
f1 = i%w
f2 = i%b
if(f1==f2):
cnt = cnt + 1
print(str(cnt)+ "/" + str(t))
| Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
a = list(map(int , input().split()))
t = a[0]
w = a[1]
b = a[2]
#val = gcd(w,b)
cnt = 0
for i in range(1,t+1):
f1 = i%w
f2 = i%b
if(f1==f2):
cnt = cnt + 1
print(str(cnt)+ "/" + str(t))
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,648,971,740 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | str,k=input(),[]
sm=['a','b','c','d','i','f','j','h','i','g','k','l','m','n','o','p','q','r','s','t','u','e','w','v','x','y','z']
bi=['A','B','C','D','I','F','J','H','I','G','K','L','M','N','O','P','Q','R','S','T','U','E','W','V','X','Y','Z']
sma=0
b=0
def smal(smale,bige,k):
for i in range(len(k)):
... | 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
str,k=input(),[]
sm=['a','b','c','d','i','f','j','h','i','g','k','l','m','n','o','p','q','r','s','t','u','e','w','v','x','y','z']
bi=['A','B','C','D','I','F','J','H','I','G','K','L','M','N','O','P','Q','R','S','T','U','E','W','V','X','Y','Z']
sma=0
b=0
def smal(smale,bige,k):
for i in range(len(k)):... | 3.977 |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,683,786,080 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a=input()
b=[]
for i in a:
if i!= 'a' and i!='A' and i!= 'e' and i!='E' and i!= 'i' and i!='I' and i!= 'o' and i!='O' and i!= 'u'and i!='U' and i!= 'y'and i!='Y':
b.append(i.lower())
c=".".join(b)
c="."+c
print(c) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
a=input()
b=[]
for i in a:
if i!= 'a' and i!='A' and i!= 'e' and i!='E' and i!= 'i' and i!='I' and i!= 'o' and i!='O' and i!= 'u'and i!='U' and i!= 'y'and i!='Y':
b.append(i.lower())
c=".".join(b)
c="."+c
print(c)
``` | 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,677,965,659 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | s=input()
if("ll" in s):
if(s.index("h")<s.index("e")<s.index("ll")<s.index("o")):
print("YES")
else:
print("NO")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
if("ll" in s):
if(s.index("h")<s.index("e")<s.index("ll")<s.index("o")):
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 |
523 | D | Statistics of Recompressing Videos | PROGRAMMING | 1,600 | [
"*special",
"data structures",
"implementation"
] | null | null | A social network for dogs called DH (DogHouse) has *k* special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.
We know that each server takes one second to recompress a on... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=5·105) — the number of videos and servers, respectively.
Next *n* lines contain the descriptions of the videos as pairs of integers *s**i*,<=*m**i* (1<=≤<=*s**i*,<=*m**i*<=≤<=109), where *s**i* is the time in seconds when the *i*-th video a... | Print *n* numbers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the time in seconds after the servers start working, when the *i*-th video will be recompressed. | [
"3 2\n1 5\n2 5\n3 5\n",
"6 1\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 3\n"
] | [
"6\n7\n11\n",
"1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n5000000004\n"
] | none | 2,000 | [
{
"input": "3 2\n1 5\n2 5\n3 5",
"output": "6\n7\n11"
},
{
"input": "6 1\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 3",
"output": "1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n5000000004"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
... | 1,426,427,644 | 82,444 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 12 | 3,000 | 3,174,400 | def add(x):
global h
h.append(x)
i = len(h) - 1
while h[i] < h[(i - 1) // 2] and i > 0:
h[i], h[(i - 1) // 2] = h[(i - 1) // 2], h[i]
i = (i - 1) // 2
def delete_min():
global h
x = h[0]
h[0] = h[- 1]
h.pop()
i = 0
while 2 * i + 1 < len(h):
... | Title: Statistics of Recompressing Videos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A social network for dogs called DH (DogHouse) has *k* special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, ... | ```python
def add(x):
global h
h.append(x)
i = len(h) - 1
while h[i] < h[(i - 1) // 2] and i > 0:
h[i], h[(i - 1) // 2] = h[(i - 1) // 2], h[i]
i = (i - 1) // 2
def delete_min():
global h
x = h[0]
h[0] = h[- 1]
h.pop()
i = 0
while 2 * i + 1 < len(... | 0 | |
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w... | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ... | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input"... | 1,680,779,475 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 0 | a,b = map(int,input().split())
c1 = []
d = 0
d1 = 0
c2 = 0
c = []
for i in range(a):
e = input()
c1.append(e)
for i in range(a):
if '*' in c1[i]:
c.append(c1[i])
for i in range(len(c)):
if c[i].find('*') > d:
d = c[i].find('*')
if c[i].rfind('*') > d1:
d1 = c[... | Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe... | ```python
a,b = map(int,input().split())
c1 = []
d = 0
d1 = 0
c2 = 0
c = []
for i in range(a):
e = input()
c1.append(e)
for i in range(a):
if '*' in c1[i]:
c.append(c1[i])
for i in range(len(c)):
if c[i].find('*') > d:
d = c[i].find('*')
if c[i].rfind('*') > d1:
... | 0 |
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* ar... | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
... | 1,447,480,053 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 16 | 61 | 0 | def main():
input()
s = input()
s = s[s.find("1"): s.rfind("1") + 1:2]
print(len(s) - s.replace("010", "0110").replace("101", "").count("0"))
if __name__ == '__main__':
main()
| Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic ... | ```python
def main():
input()
s = input()
s = s[s.find("1"): s.rfind("1") + 1:2]
print(len(s) - s.replace("010", "0110").replace("101", "").count("0"))
if __name__ == '__main__':
main()
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,673,275,408 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | x= input('')
l = 0
u = 0
for i in x :
if i.isupper() :
u += 1
elif i.islower():
l += 1
if u > l :
print(x.upper())
elif l > u or l == u :
print(x.lower()) | 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
x= input('')
l = 0
u = 0
for i in x :
if i.isupper() :
u += 1
elif i.islower():
l += 1
if u > l :
print(x.upper())
elif l > u or l == u :
print(x.lower())
``` | 3.969 |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,560,767,311 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 186 | 8,499,200 | n,c=map(int,input().split(' '))
l=list(map(int,input().split(' ')))
s=1
for i in range(1,len(l)):
if (l[i]-l[i-1])<=c:
s=s+1
else:
s=1
print(s) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
n,c=map(int,input().split(' '))
l=list(map(int,input().split(' ')))
s=1
for i in range(1,len(l)):
if (l[i]-l[i-1])<=c:
s=s+1
else:
s=1
print(s)
``` | 3 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,697,730,867 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | def func(n, len, pos):
if r < pos - len// 2 or pos + len // 2 < l:
return 0
if len== 1:
return n % 2
dis = (len + 1) // 4
if l <= pos <= r:
return func(n // 2, len // 2, pos - dis) + n % 2 + func(n // 2, len // 2, pos + dis)
if r < pos:
return func(n // 2, len // 2, ... | Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
def func(n, len, pos):
if r < pos - len// 2 or pos + len // 2 < l:
return 0
if len== 1:
return n % 2
dis = (len + 1) // 4
if l <= pos <= r:
return func(n // 2, len // 2, pos - dis) + n % 2 + func(n // 2, len // 2, pos + dis)
if r < pos:
return func(n // 2, ... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,525,448,326 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 186 | 7,065,600 | n = int(input())
i = 0
sum = 0
while i < n:
x, y, z = [int(i) for i in input().split()]
sum += x + y + z
i += 1
if sum == 0:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
i = 0
sum = 0
while i < n:
x, y, z = [int(i) for i in input().split()]
sum += x + y + z
i += 1
if sum == 0:
print("YES")
else:
print("NO")
``` | 0 |
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
... | 1,656,312,482 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 4,300,800 | n=int(input())
a=n%10
if a>5:
b=10-a
x=n+b
print(x)
else:
x=n-a
print(x) | Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5... | ```python
n=int(input())
a=n%10
if a>5:
b=10-a
x=n+b
print(x)
else:
x=n-a
print(x)
``` | 3 | |
407 | B | Long Path | PROGRAMMING | 1,600 | [
"dp",
"implementation"
] | null | null | One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider roo... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of rooms. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*i*). Each *p**i* denotes the number of the room, that someone can reach, if he will use the second portal in the *i*-th room. | Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109<=+<=7). | [
"2\n1 2\n",
"4\n1 1 2 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"20\n",
"62\n"
] | none | 1,000 | [
{
"input": "2\n1 2",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "20"
},
{
"input": "5\n1 1 1 1 1",
"output": "62"
},
{
"input": "7\n1 2 1 3 1 2 1",
"output": "154"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "3\n1 1 3",
"output": "8"... | 1,632,633,206 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 93 | 20,172,800 | def f(s):
return int(s)-1
n = int(input())
mod = 10**9+7
arr = list(map(f,input().split()))
dp=[0]*(n+1)
for i in range(n):
dp[i+1] = dp[i]+2+dp[i]-dp[arr[i]]
dp[i+1]%=mod
print(dp[-1])
| Title: Long Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one.
The ... | ```python
def f(s):
return int(s)-1
n = int(input())
mod = 10**9+7
arr = list(map(f,input().split()))
dp=[0]*(n+1)
for i in range(n):
dp[i+1] = dp[i]+2+dp[i]-dp[arr[i]]
dp[i+1]%=mod
print(dp[-1])
``` | 3 | |
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,692,679,118 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 102,400 | resultados = []
alfabeto = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = int(input())
for x in range(n):
posi = input()
resposta = []
a = True
if posi[0] == 'R'and posi.find('C') != -1:
for y in range(1, posi.find('C')):
if not int(posi[y]) >= 0 :
a = False
... | 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
resultados = []
alfabeto = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = int(input())
for x in range(n):
posi = input()
resposta = []
a = True
if posi[0] == 'R'and posi.find('C') != -1:
for y in range(1, posi.find('C')):
if not int(posi[y]) >= 0 :
a = False
... | -1 |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,692,814,867 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | def check_lucky(val):
check = False
if len(str(val)) < 2:
if val == 4 or val == 7:
check = True
else:
val = list(set(str(val)))
if len(val) != 2:
check = False
else:
if (val[0] == "4" or val[0] == "7") and (val[1] == "4" or val[1] == "7"):
... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
def check_lucky(val):
check = False
if len(str(val)) < 2:
if val == 4 or val == 7:
check = True
else:
val = list(set(str(val)))
if len(val) != 2:
check = False
else:
if (val[0] == "4" or val[0] == "7") and (val[1] == "4" or val[1]... | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,518,450,941 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 46 | 5,632,000 | n = int(input())
m = 5
while n>m:
n-=m
m=m*2
l=['Sheldon','Leonard','Penny','Rajesh','Howard']
print(l[(5*n-1)//5])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n = int(input())
m = 5
while n>m:
n-=m
m=m*2
l=['Sheldon','Leonard','Penny','Rajesh','Howard']
print(l[(5*n-1)//5])
``` | -1 |
696 | A | Lorenzo Von Matterhorn | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"implementation",
"trees"
] | null | null | Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections *i* and 2*i* and another road between *i* and 2*i*<=+<=1 for every positive integer *i*. You can clearly see that there exists a unique shortest path bet... | The first line of input contains a single integer *q* (1<=≤<=*q*<=≤<=1<=000).
The next *q* lines contain the information about the events in chronological order. Each event is described in form 1 *v* *u* *w* if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest... | For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events. | [
"7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4\n"
] | [
"94\n0\n32\n"
] | In the example testcase:
Here are the intersections used:
1. Intersections on the path are 3, 1, 2 and 4. 1. Intersections on the path are 4, 2 and 1. 1. Intersections on the path are only 3 and 6. 1. Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answ... | 500 | [
{
"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4",
"output": "94\n0\n32"
},
{
"input": "1\n2 666077344481199252 881371880336470888",
"output": "0"
},
{
"input": "10\n1 1 63669439577744021 396980128\n1 2582240553355225 63669439577744021 997926286\n1 258224055335522... | 1,551,600,740 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 187 | 8,601,600 | n=int(input())
d={}
def lca(u,v,w) :
res=0
while u!=v :
if u<v :
v,u=u,v
d[u]=d.get(u,0)+w
res+=d[u]
u=u//2
return res
for i in range(n) :
l=list(map(int,input().split()))
if l[0]==1 :
lca(l[1],l[2],l[3])
else :
print(lc... | Title: Lorenzo Von Matterhorn
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections *i* and 2*i* and another road between *i* and... | ```python
n=int(input())
d={}
def lca(u,v,w) :
res=0
while u!=v :
if u<v :
v,u=u,v
d[u]=d.get(u,0)+w
res+=d[u]
u=u//2
return res
for i in range(n) :
l=list(map(int,input().split()))
if l[0]==1 :
lca(l[1],l[2],l[3])
else :
... | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,640,268,895 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 0 | x,y= map(int,input().split())
def isPrime(n):
for i in range(2,n):
if(n%i==0):
return False
return True
n=x+1
while(True):
if(isPrime(n)):
break
n+=1
if(y==n):
print("YES")
else:
print("NO") | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
x,y= map(int,input().split())
def isPrime(n):
for i in range(2,n):
if(n%i==0):
return False
return True
n=x+1
while(True):
if(isPrime(n)):
break
n+=1
if(y==n):
print("YES")
else:
print("NO")
``` | 3.969 |
215 | B | Olympic Medal | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=<<=*r*2<=<<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/... | The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line conta... | Print a single real number — the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists. | [
"3 1 2 3\n1 2\n3 3 2 1\n1 2\n",
"4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n"
] | [
"2.683281573000\n",
"2.267786838055\n"
] | In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1. | 500 | [
{
"input": "3 1 2 3\n1 2\n3 3 2 1\n1 2",
"output": "2.683281573000"
},
{
"input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1",
"output": "2.267786838055"
},
{
"input": "1 5\n1 3\n1 7\n515 892",
"output": "3.263613058533"
},
{
"input": "2 3 2\n3 2 3 1\n2 2 1\n733 883",
"output": "2.... | 1,657,217,304 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | r1 = max(map(int,input().split()))
p1 = max(map(int,input().split()))
p2 = min(map(int,input().split()))
a,b = map(int,input().split())
r2 = 0
the_root = ((b*p1)/(b*p1+a*p2))**0.5
r2 = r1*the_root
print('%.7f' %r2)
| Title: Olympic Medal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=<<=*r*2<=<<=*r*1) made of metal with density *p*1 g/... | ```python
r1 = max(map(int,input().split()))
p1 = max(map(int,input().split()))
p2 = min(map(int,input().split()))
a,b = map(int,input().split())
r2 = 0
the_root = ((b*p1)/(b*p1+a*p2))**0.5
r2 = r1*the_root
print('%.7f' %r2)
``` | 0 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,665,477,833 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | n,m = map(int,input().split())
a = set()
for i in range(n):a.update(set(input()[1:]))
print(("NO","YES")[len(a)-1 == m]) | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n,m = map(int,input().split())
a = set()
for i in range(n):a.update(set(input()[1:]))
print(("NO","YES")[len(a)-1 == m])
``` | 0 | |
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,657,263,813 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | def generatePassword(n, k):
password = []; idx = 0
for i in range(n):
password.append(chr(idx+ord('a')))
idx = (idx+1)%k
return ''.join(password)
n, k = list(map(int, input().split(' ')))
print(generatePassword(n, k))
| 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
def generatePassword(n, k):
password = []; idx = 0
for i in range(n):
password.append(chr(idx+ord('a')))
idx = (idx+1)%k
return ''.join(password)
n, k = list(map(int, input().split(' ')))
print(generatePassword(n, k))
``` | 3 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,678,746,128 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <stdio.h>
int main() {
int n, m;
scanf("%d %d", &n, &m);
char matriz[n][m];
for (int i = 0; n > i; i++) {
scanf("%s", matriz[i]);
}
for (int i = 0; n > i; i++) {
for (int j = 0; j < m; j++) {
if (matriz[i][j] == '.') {
if ((i + j) % 2 == 0) {... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
#include <stdio.h>
int main() {
int n, m;
scanf("%d %d", &n, &m);
char matriz[n][m];
for (int i = 0; n > i; i++) {
scanf("%s", matriz[i]);
}
for (int i = 0; n > i; i++) {
for (int j = 0; j < m; j++) {
if (matriz[i][j] == '.') {
if ((i + j) %... | -1 | |
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,692,583,189 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | a = list(map(int,input().split(" ")))
b = a[0]
c = a[1]
d = b * c
print(d // 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
a = list(map(int,input().split(" ")))
b = a[0]
c = a[1]
d = b * c
print(d // 2)
``` | 3.977 |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,588,053,565 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 218 | 307,200 | r,c=[int(z) for z in input().split()]
r1=list(range(0,r))
c1=list(range(0,c))
for i in range(0,r):
s=input()
for j in range(0,len(s)):
if s[j]=='S':
if i in r1:
r1.remove(i)
if j in c1:
c1.remove(j)
print(len(r1)*c+len(c1)*r-len(r1)*len(... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
r,c=[int(z) for z in input().split()]
r1=list(range(0,r))
c1=list(range(0,c))
for i in range(0,r):
s=input()
for j in range(0,len(s)):
if s[j]=='S':
if i in r1:
r1.remove(i)
if j in c1:
c1.remove(j)
print(len(r1)*c+len(c1)*r-le... | 3 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,697,396,213 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | n, k = map(int, input().split())
print((k-(n+1)//2)*2 if k > (n+1)//2 else 2*k-1) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
n, k = map(int, input().split())
print((k-(n+1)//2)*2 if k > (n+1)//2 else 2*k-1)
``` | 3 | |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pie... | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
... | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,604,948,873 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 307,200 | '''
Time complexity: O(N)
Space complexity: O(N)
where N is the input given
'''
def solve(n) :
isPrime = [True for i in range(n + 2)]
for i in range(2, n + 2) :
if(isPrime[i] == True) :
j = 2
while(i * j <= n + 2) :
isPrime[i * j] = False
if(n <= 1) :
print(1)
... | Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ... | ```python
'''
Time complexity: O(N)
Space complexity: O(N)
where N is the input given
'''
def solve(n) :
isPrime = [True for i in range(n + 2)]
for i in range(2, n + 2) :
if(isPrime[i] == True) :
j = 2
while(i * j <= n + 2) :
isPrime[i * j] = False
if(n <= 1) :
pr... | 0 | |
505 | A | Mr. Kitayuta's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes... | The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. | If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. | [
"revive\n",
"ee\n",
"kitayuta\n"
] | [
"reviver\n",
"eye",
"NA\n"
] | For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | 500 | [
{
"input": "revive",
"output": "reviver"
},
{
"input": "ee",
"output": "eee"
},
{
"input": "kitayuta",
"output": "NA"
},
{
"input": "evima",
"output": "NA"
},
{
"input": "a",
"output": "aa"
},
{
"input": "yutampo",
"output": "NA"
},
{
"inpu... | 1,426,240,934 | 554 | Python 3 | OK | TESTS | 40 | 62 | 0 | def isPal(s):
return s == s[::-1]
def allway(s):
flag = 0
for i in range(len(s) + 1):
for j in alf:
new = s[:i] + j + s[i:]
if isPal(new):
flag = 1
return new
if flag == 0:
return 'NA'
alf = 'abcdefghijklmnopqrstuvwx... | Title: Mr. Kitayuta's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re... | ```python
def isPal(s):
return s == s[::-1]
def allway(s):
flag = 0
for i in range(len(s) + 1):
for j in alf:
new = s[:i] + j + s[i:]
if isPal(new):
flag = 1
return new
if flag == 0:
return 'NA'
alf = 'abcdefghijklmn... | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,672,828,936 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 156 | 0 | n = input()
s = [int(x) for x in input().split()]
if sum(s)%2 !=0:
for i in range(0,len(s)): s[i] += 1
p = 0
for x in s:
if x%2 == 0: p+=1
print(p) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n = input()
s = [int(x) for x in input().split()]
if sum(s)%2 !=0:
for i in range(0,len(s)): s[i] += 1
p = 0
for x in s:
if x%2 == 0: p+=1
print(p)
``` | 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.