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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o... | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
... | 1,528,807,832 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | string=str(input())
for i in range(1,len(string),1):
if ord(string[i])!=46 and ord(string[i+1])!=46 and ord(string[i-1])!=46:
print("Yes")
break
else:
print("No") | Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti... | ```python
string=str(input())
for i in range(1,len(string),1):
if ord(string[i])!=46 and ord(string[i+1])!=46 and ord(string[i-1])!=46:
print("Yes")
break
else:
print("No")
``` | 0 | |
550 | C | Divisibility by Eight | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"math"
] | null | null | You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a no... | The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits. | Print "NO" (without quotes), if there is no such way to remove some digits from number *n*.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8.
If there are multiple possible answers, you may print any ... | [
"3454\n",
"10\n",
"111111\n"
] | [
"YES\n344\n",
"YES\n0\n",
"NO\n"
] | none | 1,000 | [
{
"input": "3454",
"output": "YES\n344"
},
{
"input": "10",
"output": "YES\n0"
},
{
"input": "111111",
"output": "NO"
},
{
"input": "8996988892",
"output": "YES\n8"
},
{
"input": "5555555555",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
... | 1,691,683,584 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | v1=input()
for i in range(len(v1)):
v2=v1[:i]+v1[i+1:]
if int(v2)%8==0:print("YES");print(int(v2));break
else:print("NO") | Title: Divisibility by Eight
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of t... | ```python
v1=input()
for i in range(len(v1)):
v2=v1[:i]+v1[i+1:]
if int(v2)%8==0:print("YES");print(int(v2));break
else:print("NO")
``` | 0 | |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,695,646,572 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 23 | 528 | 97,484,800 | n=int(input())
a=list(map(int,input().split()))[:n]
x=0
y=0
z=0
for i in range(n):
if a[i]==1:
x+=1
elif a[i]==2:
y+=1
else:
z+=1
if x==y and x==z:
print(n-x)
else:
if x>=y and x>=z:
print(n-x)
elif y>=x and y>=z:
print(n-y)
else:
... | Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
n=int(input())
a=list(map(int,input().split()))[:n]
x=0
y=0
z=0
for i in range(n):
if a[i]==1:
x+=1
elif a[i]==2:
y+=1
else:
z+=1
if x==y and x==z:
print(n-x)
else:
if x>=y and x>=z:
print(n-x)
elif y>=x and y>=z:
print(n-y)
... | 3.68642 |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,697,018,474 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | for i in range(1,6):
a=input()
if '1' in a:
b=a.index('1')+1
c=i
break
n=abs(b-3)+abs(c-3)
print(n) | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
for i in range(1,6):
a=input()
if '1' in a:
b=a.index('1')+1
c=i
break
n=abs(b-3)+abs(c-3)
print(n)
``` | 0 | |
610 | C | Harmony Analysis | PROGRAMMING | 1,800 | [
"constructive algorithms"
] | null | null | The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec... | The only line of the input contains a single integer *k* (0<=≤<=*k*<=≤<=9). | Print 2*k* lines consisting of 2*k* characters each. The *j*-th character of the *i*-th line must be equal to '<=*<=' if the *j*-th coordinate of the *i*-th vector is equal to <=-<=1, and must be equal to '<=+<=' if it's equal to <=+<=1. It's guaranteed that the answer always exists.
If there are many correct answers,... | [
"2\n"
] | [
"++**\n+*+*\n++++\n+**+"
] | Consider all scalar products in example:
- Vectors 1 and 2: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( + 1) + ( - 1)·( - 1) = 0 - Vectors 1 and 3: ( + 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) + ( - 1)·( + 1) = 0 - Vectors 1 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( - 1) + ( - 1)·( + 1) = 0 - Vectors 2 and 3: ... | 1,500 | [
{
"input": "2",
"output": "++++\n+*+*\n++**\n+**+"
},
{
"input": "1",
"output": "++\n+*"
},
{
"input": "3",
"output": "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*"
},
{
"input": "0",
"output": "+"
},
{
"input": "4",
"output":... | 1,689,364,961 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689364961.548565")# 1689364961.548585 | Title: Harmony Analysis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave t... | ```python
print("_RANDOM_GUESS_1689364961.548565")# 1689364961.548585
``` | 0 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,504,557,250 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 77 | 307,200 | n = int(input())
ratings = [(i,int(x)) for i,x in enumerate(input().split())]
out = [0]*n
ratings = sorted(ratings, key = lambda x: x[1], reverse=True)
pos = 0
score = 0
count = 1
for r in ratings:
r_score = r[1]
if r_score != score:
score = r_score
pos +=count
count = 1
... | Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n = int(input())
ratings = [(i,int(x)) for i,x in enumerate(input().split())]
out = [0]*n
ratings = sorted(ratings, key = lambda x: x[1], reverse=True)
pos = 0
score = 0
count = 1
for r in ratings:
r_score = r[1]
if r_score != score:
score = r_score
pos +=count
coun... | 3 | |
883 | E | Field of Wonders | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length *n*, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already reveale... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | [
"4\na**d\n2\nabcd\nacbd\n",
"5\nlo*er\n2\nlover\nloser\n",
"3\na*a\n2\naaa\naba\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | 0 | [
{
"input": "4\na**d\n2\nabcd\nacbd",
"output": "2"
},
{
"input": "5\nlo*er\n2\nlover\nloser",
"output": "0"
},
{
"input": "3\na*a\n2\naaa\naba",
"output": "1"
},
{
"input": "1\n*\n1\na",
"output": "1"
},
{
"input": "1\n*\n1\nz",
"output": "1"
},
{
"inp... | 1,650,816,613 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | _, w, m = input(), input(), int(input())
ws = set()
for _ in range(m):
q = input()
for a, b in zip(w, q):
if a!='*' and a!=b or a=='*' and b in w:
break
else:
ws.add(q)
ans, all = set(), set()
for i, c in enumerate(w):
if c!='*': continue
l = set()
for q in ws:
l.add(q[i])
if not all: all = l
else: al... | Title: Field of Wonders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several tur... | ```python
_, w, m = input(), input(), int(input())
ws = set()
for _ in range(m):
q = input()
for a, b in zip(w, q):
if a!='*' and a!=b or a=='*' and b in w:
break
else:
ws.add(q)
ans, all = set(), set()
for i, c in enumerate(w):
if c!='*': continue
l = set()
for q in ws:
l.add(q[i])
if not all: all = l... | 0 | |
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,674,627,693 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | # -*- coding: utf-8 -*-
# @Author: Fei_xiangShi
# @Date: 2023-01-25 14:18:18
# @Last Modified by: FXS
# @Last Modified time: 2023-01-25 14:21:29
n = int(input())
for _ in range(n):
a = input()
if len(a) < 11:
print(a)
else:
print(a[0]+str(len(a)-2)+a[-1]) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
# -*- coding: utf-8 -*-
# @Author: Fei_xiangShi
# @Date: 2023-01-25 14:18:18
# @Last Modified by: FXS
# @Last Modified time: 2023-01-25 14:21:29
n = int(input())
for _ in range(n):
a = input()
if len(a) < 11:
print(a)
else:
print(a[0]+str(len(a)-2)+a[-1])
``` | 3.969 |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,684,007,644 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | v1=int(input())
v2=list(map(int,input().split()))
s=0
j=0
for i in range(1,v1):
if s>v2[i-1]:
s-=1
if v2[i]<v2[i-1] :
s+=v2[i-1]-v2[i]
elif v2[i]==v2[i-1] and v2[i]>0:
s+=v2[i]
else:
if s>=1:
j+=s-1
else:
j+=1
... | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
v1=int(input())
v2=list(map(int,input().split()))
s=0
j=0
for i in range(1,v1):
if s>v2[i-1]:
s-=1
if v2[i]<v2[i-1] :
s+=v2[i-1]-v2[i]
elif v2[i]==v2[i-1] and v2[i]>0:
s+=v2[i]
else:
if s>=1:
j+=s-1
else:
... | 0 | |
774 | C | Maximum Number | PROGRAMMING | 1,200 | [
"*special",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ... | The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. | Print the maximum integer which can be shown on the display of Stepan's newest device. | [
"2\n",
"3\n"
] | [
"1\n",
"7\n"
] | none | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "11"
},
{
"input": "5",
"output": "71"
},
{
"input": "6",
"output": "111"
},
{
"input": "85651",
"output": "711111111111111111111111111111111111111111111111... | 1,491,409,249 | 2,749 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 4,608,000 | n = int(input())
ans = ''
if n % 2 == 0:
for i in range(n//2):
ans += '1'
else:
for i in range(n//2-1):
ans += '1'
ans += '7'
print(ans) | Title: Maximum Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 o... | ```python
n = int(input())
ans = ''
if n % 2 == 0:
for i in range(n//2):
ans += '1'
else:
for i in range(n//2-1):
ans += '1'
ans += '7'
print(ans)
``` | 0 | |
851 | B | Arpa and an exam about geometry | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ... | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | 1,000 | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"i... | 1,504,538,941 | 3,241 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 61 | 0 | import math
ax,ay,bx,by,cx,cy = map(int,input().split())
btx = (ax + cx) / 2.0
bty = (ay + cy) / 2.0
f = math.sqrt(pow(ax-btx,2)+pow(ay-bty,2))
a = math.sqrt(pow(bx-btx,2)+pow(by-bty,2))
c = math.sqrt(pow(cx-btx,2)+pow(cy-bty,2))
if (a == f)and c==f:
print("Yes")
else: print("No") | Title: Arpa and an exam about geometry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle... | ```python
import math
ax,ay,bx,by,cx,cy = map(int,input().split())
btx = (ax + cx) / 2.0
bty = (ay + cy) / 2.0
f = math.sqrt(pow(ax-btx,2)+pow(ay-bty,2))
a = math.sqrt(pow(bx-btx,2)+pow(by-bty,2))
c = math.sqrt(pow(cx-btx,2)+pow(cy-bty,2))
if (a == f)and c==f:
print("Yes")
else: print("No")
``` | 0 | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,619,336,452 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 124 | 409,600 | n=int(input())
a={*map(int,input().split())}
k=0
for i in range(1,n+1):
if i not in a:k+=1
print(k) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
n=int(input())
a={*map(int,input().split())}
k=0
for i in range(1,n+1):
if i not in a:k+=1
print(k)
``` | 3 | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha... | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,510,233,313 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 764 | 20,070,400 | n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
for i in range(n//2):
if i % 2 == 0:
print(a[-i - 1], end=' ')
else:
print(a[i], end=' ')
for i in range(n//2, n):
if i % 2 == 0:
print(a[i], end=' ')
else:
print(a... | Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p... | ```python
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
for i in range(n//2):
if i % 2 == 0:
print(a[-i - 1], end=' ')
else:
print(a[i], end=' ')
for i in range(n//2, n):
if i % 2 == 0:
print(a[i], end=' ')
else:
... | 3 | |
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *... | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num... | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"ou... | 1,688,974,219 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n, k, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
if a[k-1] < b[m-1]:
print("YES")
else:
print("NO") | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi... | ```python
n, k, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
if a[k-1] < b[m-1]:
print("YES")
else:
print("NO")
``` | -1 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,443,869,360 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 0 | def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
#f.readline()
#input()
get = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split("|")]
scale = get()
q = input()
if abs(len(scale[0]) - len(scale[1]))%2 != len(q)%2 or abs(len(scale[0]) - ... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
#f.readline()
#input()
get = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split("|")]
scale = get()
q = input()
if abs(len(scale[0]) - len(scale[1]))%2 != len(q)%2 or abs(len(sc... | 3 | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,619,968,505 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n,m=map(int,input().split())
s=list(intput())
for i in range(m):
l,r,c1,c2=input().split()
l=int(l)
r=int(r)
for j in range(l-1,r):
if s[j]==c1:
s[j]=c2
print("".join(s)) | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
n,m=map(int,input().split())
s=list(intput())
for i in range(m):
l,r,c1,c2=input().split()
l=int(l)
r=int(r)
for j in range(l-1,r):
if s[j]==c1:
s[j]=c2
print("".join(s))
``` | -1 | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,649,393,381 | 2,147,483,647 | Python 3 | OK | TESTS | 75 | 62 | 409,600 | #!/usr/bin/env python
import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
x1,y1 = map(int, wtf[0].split())
x2,y2 = map(int, wtf[1].split())
print(max(abs(y1-y2),abs(x1-x2))) | Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
#!/usr/bin/env python
import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
x1,y1 = map(int, wtf[0].split())
x2,y2 = map(int, wtf[1].split())
print(max(abs(y1-y2),abs(x1-x2)))
``` | 3 | |
292 | B | Network Topology | PROGRAMMING | 1,200 | [
"graphs",
"implementation"
] | null | null | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them... | The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*... | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo... | [
"4 3\n1 2\n2 3\n3 4\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n"
] | [
"bus topology\n",
"ring topology\n",
"star topology\n",
"unknown topology\n"
] | none | 1,000 | [
{
"input": "4 3\n1 2\n2 3\n3 4",
"output": "bus topology"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "ring topology"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "star topology"
},
{
"input": "4 4\n1 2\n2 3\n3 1\n1 4",
"output": "unknown topology"
},
{
"i... | 1,610,863,780 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | n,m = map(int, input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
edgeCount = [0]
for i in range(1,n+1):
edgeCount.append(len(adj[i]))
edgeCountCount = [0 for i in range(n+1)]
for i in edgeCount:
edgeCountCo... | Title: Network Topology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in... | ```python
n,m = map(int, input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
edgeCount = [0]
for i in range(1,n+1):
edgeCount.append(len(adj[i]))
edgeCountCount = [0 for i in range(n+1)]
for i in edgeCount:
e... | 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,693,621,994 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 265 | 2,560,000 | # LUOGU_RID: 123536784
n=int(input())
ans=1
x=list(input().split());
while n>0:
n-=1
ans*=int(x[n])
print(ans) | 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
# LUOGU_RID: 123536784
n=int(input())
ans=1
x=list(input().split());
while n>0:
n-=1
ans*=int(x[n])
print(ans)
``` | 3 | |
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<... | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": ... | 1,504,021,908 | 2,808 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 46 | 0 | # cook your dish here
r,d=map(int,input().strip().split(' '))
n=int(input())
k=0
for i in range(n):
x,y,r1=map(int,input().strip().split(' '))
dis=pow(x*x+y*y,.5)
if(dis+r1<=r and dis-r1>=d):
k+=1
print(k) | Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center... | ```python
# cook your dish here
r,d=map(int,input().strip().split(' '))
n=int(input())
k=0
for i in range(n):
x,y,r1=map(int,input().strip().split(' '))
dis=pow(x*x+y*y,.5)
if(dis+r1<=r and dis-r1>=d):
k+=1
print(k)
``` | 0 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,657,796,792 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | def calc_hours(a, b):
hours = a
a = int(a/b)
if a >= 1:
hours += calc_hours(a, b)
return hours
a_b = input()
a = int(a_b.split()[0])
b = int(a_b.split()[1])
hours = calc_hours(a, b)
print(hours) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
def calc_hours(a, b):
hours = a
a = int(a/b)
if a >= 1:
hours += calc_hours(a, b)
return hours
a_b = input()
a = int(a_b.split()[0])
b = int(a_b.split()[1])
hours = calc_hours(a, b)
print(hours)
``` | 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,617,989,811 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a=input()
s='hello'
for i in a:
if i not in s:
a=a.replace(i,'')
x=[]
new=[]
for i in a:
x.append(i)
prev=None
for i in x:
if i!='l':
if i!=prev:
new.append(i)
prev=i
else:
prev=i
new.append('l')
new=''.join(new)
if new.count('l'... | 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
a=input()
s='hello'
for i in a:
if i not in s:
a=a.replace(i,'')
x=[]
new=[]
for i in a:
x.append(i)
prev=None
for i in x:
if i!='l':
if i!=prev:
new.append(i)
prev=i
else:
prev=i
new.append('l')
new=''.join(new)
if new... | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is... | In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n"
] | [
"Yes\nYes\nYes\nNo\nNo\nYes\n"
] | First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | 0 | [
{
"input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000",
"output": "Yes\nYes\nYes\nNo\nNo\nYes"
},
{
"input": "3\n1 1\n8 27\n1000 1331",
"output": "Yes\nNo\nNo"
},
{
"input": "1\n12004 18012002",
"output": "Yes"
},
{
"input": "1\n3331 11095561",
"output": "Yes... | 1,592,402,634 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 49 | 1,000 | 26,419,200 | from sys import stdin
test = stdin.readlines()
n = int(test[0])
output = []
for i in range(1, n + 1):
a, b = map(int, test[i].split())
p = a * b
root = round(p ** (1 / 3))
ok = root ** 3 == p and a % root == b % root == 0
output.append('Yes' if ok else 'No')
print('\n'.join(output))
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who ... | ```python
from sys import stdin
test = stdin.readlines()
n = int(test[0])
output = []
for i in range(1, n + 1):
a, b = map(int, test[i].split())
p = a * b
root = round(p ** (1 / 3))
ok = root ** 3 == p and a % root == b % root == 0
output.append('Yes' if ok else 'No')
print('\n'.join... | 0 | |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,522,530,869 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 93 | 7,065,600 | n=int(input())
i=n+1
while True:
d=str(i)
if d.count('8')>=1:
print(i-n)
break
else:
i+=1
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
n=int(input())
i=n+1
while True:
d=str(i)
if d.count('8')>=1:
print(i-n)
break
else:
i+=1
``` | 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,679,976,967 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 124 | 5,939,200 | import sys
def count_ones(n, l, r):
def split(list1):
for i in range(len(list1)):
if list1[i] > 1:
list1 = list1[:i] + [list1[i] // 2, list1[i] % 2, list1[i] // 2] + list1[i + 1:]
return split(list1)
return list1
lst = [n]
lst = split(lst)
sum... | 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
import sys
def count_ones(n, l, r):
def split(list1):
for i in range(len(list1)):
if list1[i] > 1:
list1 = list1[:i] + [list1[i] // 2, list1[i] % 2, list1[i] // 2] + list1[i + 1:]
return split(list1)
return list1
lst = [n]
lst = split(ls... | -1 | |
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,436,104 | 3,504 | Python 3 | OK | TESTS | 133 | 93 | 0 | def is_palindrome(s):
for i in range(len(s) // 2):
if s[i] != s[~i]:
return False
return True
def max_anti(s, visited):
if len(s) <= 1:
return 0
ts = tuple(s)
if ts in visited:
return 0
visited.add(ts)
if is_palindrome(s):
return max(max_anti(s[1... | 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 is_palindrome(s):
for i in range(len(s) // 2):
if s[i] != s[~i]:
return False
return True
def max_anti(s, visited):
if len(s) <= 1:
return 0
ts = tuple(s)
if ts in visited:
return 0
visited.add(ts)
if is_palindrome(s):
return max(ma... | 3 | |
53 | D | Physical Education | PROGRAMMING | 1,500 | [
"sortings"
] | D. Physical Education | 2 | 256 | Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the height of the *i*-th student in the line and *n* is the number of s... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=300) which is the number of students. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) which represent the height of the student occupying the *i*-th place must possess. The third line contains *n* space-separated integers *b**i* (... | In the first line print an integer *k* (0<=≤<=*k*<=≤<=106) which is the number of moves. It is not required to minimize *k* but it must not exceed 106. Then print *k* lines each containing two space-separated integers. Line *p**i*, *p**i*<=+<=1 (1<=≤<=*p**i*<=≤<=*n*<=-<=1) means that Vasya should swap students occupyin... | [
"4\n1 2 3 2\n3 2 1 2\n",
"2\n1 100500\n1 100500\n"
] | [
"4\n2 3\n1 2\n3 4\n2 3\n",
"0\n"
] | none | 2,000 | [
{
"input": "4\n1 2 3 2\n3 2 1 2",
"output": "4\n2 3\n1 2\n3 4\n2 3"
},
{
"input": "2\n1 100500\n1 100500",
"output": "0"
},
{
"input": "3\n652586118 652586118 652586118\n652586118 652586118 652586118",
"output": "3\n2 3\n1 2\n2 3"
},
{
"input": "4\n681106577 681106577 6750771... | 1,652,221,425 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 186 | 102,400 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
f = 0
for i in range(n):
for j in range(i,n):
if a[i] == b[j]:
f = j
break
# print(f)
for j in range(f, i, -1):
temp = b[j]
b[j] = b[j-1]
... | Title: Physical Education
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=.... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
f = 0
for i in range(n):
for j in range(i,n):
if a[i] == b[j]:
f = j
break
# print(f)
for j in range(f, i, -1):
temp = b[j]
b[j] = b[... | 3.953309 |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,699,283,080 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 12,390,400 | n=int(input())
xi=list(map(int,input().split()))
xi.sort()
q=int(input())
for i in range(q):
copyn=n
copyxi=xi[:]
m=int(input())
position=0
while copyn>1:
marker=copyn//2
if copyxi[marker]<=m:
copyxi=copyxi[marker:]
position+=marker
else:... | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
n=int(input())
xi=list(map(int,input().split()))
xi.sort()
q=int(input())
for i in range(q):
copyn=n
copyxi=xi[:]
m=int(input())
position=0
while copyn>1:
marker=copyn//2
if copyxi[marker]<=m:
copyxi=copyxi[marker:]
position+=marker
... | 0 | |
803 | C | Maximal GCD | PROGRAMMING | 1,900 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010). | If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them. | [
"6 3\n",
"8 2\n",
"5 3\n"
] | [
"1 2 3\n",
"2 6\n",
"-1\n"
] | none | 0 | [
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 10000000... | 1,586,523,880 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 307,200 | inp=input()
sum_inp=int(inp.split(" ")[0])
k=int(inp.split(" ")[1])
def solve():
if (k*(k+1))/2>sum_inp:
return -1
def divisors(n):
div_list=[]
for i in range(1, int(n/2)+1):
if n%i==0:
div_list.append(i)
return div_list
div_lis... | Title: Maximal GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Grea... | ```python
inp=input()
sum_inp=int(inp.split(" ")[0])
k=int(inp.split(" ")[1])
def solve():
if (k*(k+1))/2>sum_inp:
return -1
def divisors(n):
div_list=[]
for i in range(1, int(n/2)+1):
if n%i==0:
div_list.append(i)
return div_list
... | 0 | |
68 | A | Irrational problem | PROGRAMMING | 1,100 | [
"implementation",
"number theory"
] | A. Irrational problem | 2 | 256 | Little Petya was given this problem for homework:
You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x*)<==<=*x*.
It is a pity that Petya forgot the order in which the remainders should be taken and wr... | First line of the input will contain 6 integers, separated by spaces: *p*1,<=*p*2,<=*p*3,<=*p*4,<=*a*,<=*b* (1<=≤<=*p*1,<=*p*2,<=*p*3,<=*p*4<=≤<=1000,<=0<=≤<=*a*<=≤<=*b*<=≤<=31415).
It is guaranteed that numbers *p*1,<=*p*2,<=*p*3,<=*p*4 will be pairwise distinct. | Output the number of integers in the given range that have the given property. | [
"2 7 1 8 2 8\n",
"20 30 40 50 0 100\n",
"31 41 59 26 17 43\n"
] | [
"0\n",
"20\n",
"9\n"
] | none | 500 | [
{
"input": "2 7 1 8 2 8",
"output": "0"
},
{
"input": "20 30 40 50 0 100",
"output": "20"
},
{
"input": "31 41 59 26 17 43",
"output": "9"
},
{
"input": "1 2 3 4 0 0",
"output": "1"
},
{
"input": "1 2 3 4 1 1",
"output": "0"
},
{
"input": "1 2 999 1000... | 1,570,519,215 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 248 | 0 | q=input()
p1,p2,p3,p4,a,b=map(int,q.split())
p=min(p1,p2,p3,p4)
c=0
if p>b:
c=b-a+1
elif p>a:
c=p-a
else:
c=0
print(c)
| Title: Irrational problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya was given this problem for homework:
You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x... | ```python
q=input()
p1,p2,p3,p4,a,b=map(int,q.split())
p=min(p1,p2,p3,p4)
c=0
if p>b:
c=b-a+1
elif p>a:
c=p-a
else:
c=0
print(c)
``` | 3.938 |
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,194,412 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a = list(input().lower())
for i in a:
if i not in ['a', 'e','i', 'o','u','y']:
print('·'+ i, 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
a = list(input().lower())
for i in a:
if i not in ['a', 'e','i', 'o','u','y']:
print('·'+ i, end='')
``` | 0 | |
812 | C | Sagheer and Nubian Market | PROGRAMMING | 1,500 | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<... | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the... | 1,500 | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"outp... | 1,673,878,934 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n,s=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l=0
r=n+1
while r-l>1:
d=(l+r)//2
su=0
for i in range(d):
su+=a[i]+(i+1)*d
if su<=s:
l=d
else:
r=d
su=0
for i in range(l):
su+=a[i]+(i+1)*l
print(l,su) | Title: Sagheer and Nubian Market
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. T... | ```python
n,s=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l=0
r=n+1
while r-l>1:
d=(l+r)//2
su=0
for i in range(d):
su+=a[i]+(i+1)*d
if su<=s:
l=d
else:
r=d
su=0
for i in range(l):
su+=a[i]+(i+1)*l
print(l,su)
``` | 0 | |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,529,243,725 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 202 | 1,126,400 | def find(arr1,elem,i):
if(arr1[i][0] == elem):
return i
else:
return find(arr1,elem,arr1[i][0])
[n,k] = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
arr = []
arr1 = []
for i in range(n):
arr.append((i,-1*p[i],c[i]))
arr1.append((i,-1*c[i]))
fin... | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
def find(arr1,elem,i):
if(arr1[i][0] == elem):
return i
else:
return find(arr1,elem,arr1[i][0])
[n,k] = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
arr = []
arr1 = []
for i in range(n):
arr.append((i,-1*p[i],c[i]))
arr1.append((i,-1*c[i... | -1 | |
946 | C | String Transformation | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number... | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | 0 | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaen... | 1,576,460,537 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 155 | 2,252,800 | s = input().strip()
n = len(s)
tail = [0] * 26
f = [0] * n
for i in range(n):
if s[i] == 'a':
f[i] = 1
else:
f[i] = -int(1e9)
for i in range(n):
x = ord(s[i]) - ord('a')
for j in range(x, 26):
f[i] = max(f[i], f[tail[j]] + 1)
tail[x] = i
for i in... | Title: String Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be rep... | ```python
s = input().strip()
n = len(s)
tail = [0] * 26
f = [0] * n
for i in range(n):
if s[i] == 'a':
f[i] = 1
else:
f[i] = -int(1e9)
for i in range(n):
x = ord(s[i]) - ord('a')
for j in range(x, 26):
f[i] = max(f[i], f[tail[j]] + 1)
tail[x] = i... | 0 | |
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not ... | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20... | 1,694,940,971 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 62 | 0 | k = int(input())
n = list(map(int, input().split()))
n.sort()
g = ''
for i in range(k):
g += str(n[i])+ ' '
print(g) | Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the bo... | ```python
k = int(input())
n = list(map(int, input().split()))
n.sort()
g = ''
for i in range(k):
g += str(n[i])+ ' '
print(g)
``` | 3 | |
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,071,301 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 409,600 | import string
n,k=list(map(int,input().split()))
alph=string.ascii_letters
seq=alph[:k]
print(seq*int((n/k)),seq[:int(n//k)],sep='')
| Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
import string
n,k=list(map(int,input().split()))
alph=string.ascii_letters
seq=alph[:k]
print(seq*int((n/k)),seq[:int(n//k)],sep='')
``` | 0 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,683,029,582 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a, b, c, d = int(input()).split()
if ((a+b>c and b+c>a and c+a>b) or (a+c>d and c+d>a and a+d>c) or (b+c>d and c+d>b and b+d>c)):
print("Triangle")
elif (a+b==c or a+b==d or a+c==d or a+c==b or b+c==a or b+c==d or c+d==a or c+d==b):
print("Segment")
else:
print("Impossible") | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
a, b, c, d = int(input()).split()
if ((a+b>c and b+c>a and c+a>b) or (a+c>d and c+d>a and a+d>c) or (b+c>d and c+d>b and b+d>c)):
print("Triangle")
elif (a+b==c or a+b==d or a+c==d or a+c==b or b+c==a or b+c==d or c+d==a or c+d==b):
print("Segment")
else:
print("Impossible")
``` | -1 |
471 | D | MUH and Cube Walls | PROGRAMMING | 1,800 | [
"string suffix structures",
"strings"
] | null | null | Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of di... | The first line contains two integers *n* and *w* (1<=≤<=*n*,<=*w*<=≤<=2·105) — the number of towers in the bears' and the elephant's walls correspondingly. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the heights of the towers in the bears' wall. The third line contains *w* integers *b**i* (1<=... | Print the number of segments in the bears' wall where Horace can "see an elephant". | [
"13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2\n"
] | [
"2"
] | The picture to the left shows Horace's wall from the sample, the picture to the right shows the bears' wall. The segments where Horace can "see an elephant" are in gray. | 2,000 | [
{
"input": "13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2",
"output": "2"
},
{
"input": "5 1\n8 71 1 24 2\n31",
"output": "5"
},
{
"input": "6 3\n2 2 2 2 2 2\n5 5 5",
"output": "4"
},
{
"input": "1 1\n576560149\n691846236",
"output": "1"
},
{
"input": "10 5\n5 10 8 1... | 1,617,361,778 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 1 | 108 | 2,150,400 | def computeLPS():
m = len(pat)
i, j = 1, 0
lps = [0 for i in range(m)]
while i < m:
if pat[i] == pat[j]:
j += 1
lps[i] = j
i += 1
else:
if j == 0:
i += 1
else:
j = lps(j - 1)
... | Title: MUH and Cube Walls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of ... | ```python
def computeLPS():
m = len(pat)
i, j = 1, 0
lps = [0 for i in range(m)]
while i < m:
if pat[i] == pat[j]:
j += 1
lps[i] = j
i += 1
else:
if j == 0:
i += 1
else:
j = lps... | -1 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,619,081,664 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 0 | n = int(input())
string = input()
x = 1
for i in range(n):
if string[i] == '1':
x += 1
else:
print(x)
exit()
print(x - 1)
| Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n = int(input())
string = input()
x = 1
for i in range(n):
if string[i] == '1':
x += 1
else:
print(x)
exit()
print(x - 1)
``` | 3 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,653,928,517 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | s, t = input(), input()
s = [ord(s[0]) - ord('a') + 1, int(s[1])]
t = [ord(t[0]) - ord('a') + 1, int(t[1])]
count = 0
p = []
while (s != t):
if (s[0] != t[0] and s[1] != t[1]):
if (s[0] < t[0]):
if (s[1] < t[1]):
s[0] += 1
s[1] += 1
p.... | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
s, t = input(), input()
s = [ord(s[0]) - ord('a') + 1, int(s[1])]
t = [ord(t[0]) - ord('a') + 1, int(t[1])]
count = 0
p = []
while (s != t):
if (s[0] != t[0] and s[1] != t[1]):
if (s[0] < t[0]):
if (s[1] < t[1]):
s[0] += 1
s[1] += 1
... | 3.954 |
207 | D4 | The Beaver's Problem - 3 | PROGRAMMING | 2,100 | [] | null | null | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its su... | The first line contains integer *id* (0<=≤<=*id*<=≤<=106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are ... | Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to. | [] | [] | none | 10 | [
{
"input": "19000\nGROUP OF FIVE MEETING ENDS\nWASHINGTON, April 8 - A meeting of finance ministers and\ncentral bankers of the Group of Five ended after nearly three\nand a half hours.\nWest German Finance Minister Gerhard Stoltenberg and\nBritish Chancellor of the Exchequer Nigel Lawson declined to\ncomment o... | 1,673,005,805 | 2,147,483,647 | Python 3 | OK | TESTS4 | 5 | 46 | 0 | # LUOGU_RID: 98853652
print(1)######## | Title: The Beaver's Problem - 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subje... | ```python
# LUOGU_RID: 98853652
print(1)########
``` | 3 | |
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=... | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"in... | 1,415,541,413 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | import sys
import math
n = int(sys.stdin.readline())
k = [0] * 7
k[int(sys.stdin.readline())] += 1
res = 1
for i in range(n):
a, b = [int(x) for x in (sys.stdin.readline()).split()]
if(k[a] > 0 and k[b] > 0):
res += 1
k[a] += 1
k[b] += 1
if(res >= n - 1):
print("YES")
... | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other... | ```python
import sys
import math
n = int(sys.stdin.readline())
k = [0] * 7
k[int(sys.stdin.readline())] += 1
res = 1
for i in range(n):
a, b = [int(x) for x in (sys.stdin.readline()).split()]
if(k[a] > 0 and k[b] > 0):
res += 1
k[a] += 1
k[b] += 1
if(res >= n - 1):
pri... | 0 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,623,707,300 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 154 | 0 | import sys
def get_ints(): return [int(x) for x in sys.stdin.readline().strip().split()]
def get_string(): return sys.stdin.readline().strip()
s=get_string()
sar=[get_string() for i in range(10)]
for i in range(8):
str=s[i*10:i*10+10]
for j in range(len(sar)):
if(str==sar[j]):
... | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
import sys
def get_ints(): return [int(x) for x in sys.stdin.readline().strip().split()]
def get_string(): return sys.stdin.readline().strip()
s=get_string()
sar=[get_string() for i in range(10)]
for i in range(8):
str=s[i*10:i*10+10]
for j in range(len(sar)):
if(str==sar[j]):
... | 3.9615 |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,622,894,101 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 218 | 0 | n=int(input())
arr=list(map(int,input().split(" ")))
pos=[]
neg=[]
zero=[]
for i in range(len(arr)):
if arr[i]>0:
pos.append(arr[i])
elif arr[i]==0:
zero.append(arr[i])
else:
neg.append(arr[i])
if len(pos)==0:
#print("yes no elements in positive")
pos.append(n... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
n=int(input())
arr=list(map(int,input().split(" ")))
pos=[]
neg=[]
zero=[]
for i in range(len(arr)):
if arr[i]>0:
pos.append(arr[i])
elif arr[i]==0:
zero.append(arr[i])
else:
neg.append(arr[i])
if len(pos)==0:
#print("yes no elements in positive")
po... | 3 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,485,974,145 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | inp = input().split(" ")
n = int(inp[0])
k = int(inp[1])
n += 1
while(True):
if (n ℅ k == 0):
break
n += 1
print(n) | Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
inp = input().split(" ")
n = int(inp[0])
k = int(inp[1])
n += 1
while(True):
if (n ℅ k == 0):
break
n += 1
print(n)
``` | -1 | |
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,695,858,089 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | import math
number, position = [int(x) for x in input().split()]
if position <= (number+1)/2:
n = 2 * position -1
else:
n = 2 * (position - (number + 1) / 2)
print(abs(n))
| 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
import math
number, position = [int(x) for x in input().split()]
if position <= (number+1)/2:
n = 2 * position -1
else:
n = 2 * (position - (number + 1) / 2)
print(abs(n))
``` | 0 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,625,081,191 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 122 | 0 | s=input()
t=input()
count=0
i=0
x=s[0]
while i<len(t):
if x==t[i]:
count+=1
x=s[count]
i+=1
print(count+1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s=input()
t=input()
count=0
i=0
x=s[0]
while i<len(t):
if x==t[i]:
count+=1
x=s[count]
i+=1
print(count+1)
``` | 3 | |
234 | G | Practice | PROGRAMMING | 1,600 | [
"constructive algorithms",
"divide and conquer",
"implementation"
] | null | null | Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* players in "Losewille Rangers". Each player on the team has a number — a unique integer from 1 ... | A single input line contains integer *n* (2<=≤<=*n*<=≤<=1000). | In the first line print *m* — the minimum number of practices the coach will have to schedule. Then print the descriptions of the practices in *m* lines.
In the *i*-th of those lines print *f**i* — the number of players in the first team during the *i*-th practice (1<=≤<=*f**i*<=<<=*n*), and *f**i* numbers from 1 t... | [
"2\n",
"3\n"
] | [
"1\n1 1\n",
"2\n2 1 2\n1 1\n"
] | none | 0 | [
{
"input": "2",
"output": "1\n1 1"
},
{
"input": "3",
"output": "2\n2 1 2\n1 1"
},
{
"input": "4",
"output": "2\n2 1 2\n2 1 3"
},
{
"input": "5",
"output": "3\n3 1 2 3\n3 1 2 4\n1 1"
},
{
"input": "6",
"output": "3\n3 1 2 3\n4 1 2 4 5\n2 1 4"
},
{
"inp... | 1,623,760,413 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 248 | 3,276,800 | from math import *
f1=open('input.txt','r')
n=int(f1.readline())
f1.close()
a=[[] for i in range(int(log(n,2))+1)]
def f(l,r,d=0):
global a
if l!=r:
m=(l+r)//2
a[d]+=list(range(l,m+1))
f(l,m,d+1)
f(m+1,r,d+1)
f(1,n)
b=0
for i in range(len(a)):
if a[i]:
... | Title: Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* p... | ```python
from math import *
f1=open('input.txt','r')
n=int(f1.readline())
f1.close()
a=[[] for i in range(int(log(n,2))+1)]
def f(l,r,d=0):
global a
if l!=r:
m=(l+r)//2
a[d]+=list(range(l,m+1))
f(l,m,d+1)
f(m+1,r,d+1)
f(1,n)
b=0
for i in range(len(a)):
if a[i]... | 3 | |
225 | B | Well-known Numbers | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"number theory"
] | null | null | Numbers *k*-bonacci (*k* is integer, *k*<=><=1) are a generalization of Fibonacci numbers and are determined as follows:
- *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=<<=*k*; - *F*(*k*,<=*k*)<==<=1; - *F*(*k*,<=*n*)<==<=*F*(*k*,<=*n*<=-<=1)<=+<=*F*(*k*,<=*n*<=-<=2)<=+<=...<=+<=*F*(*k*,<=*n*<=-<=*k*), fo... | The first line contains two integers *s* and *k* (1<=≤<=*s*,<=*k*<=≤<=109; *k*<=><=1). | In the first line print an integer *m* (*m*<=≥<=2) that shows how many numbers are in the found representation. In the second line print *m* distinct integers *a*1,<=*a*2,<=...,<=*a**m*. Each printed integer should be a *k*-bonacci number. The sum of printed integers must equal *s*.
It is guaranteed that the answer ex... | [
"5 2\n",
"21 5\n"
] | [
"3\n0 2 3\n",
"3\n4 1 16\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "3\n0 2 3"
},
{
"input": "21 5",
"output": "3\n4 1 16"
},
{
"input": "1 1000",
"output": "2\n1 0 "
},
{
"input": "1000000000 1000000000",
"output": "14\n536870912 268435456 134217728 33554432 16777216 8388608 1048576 524288 131072 32768 16384 2... | 1,441,297,830 | 1,349 | PyPy 3 | OK | TESTS | 70 | 218 | 0 | s,k=list(map(int,input().split(' ')))
a=[0,1,1]
while a[-1]<s:
if len(a)<k:
a.append(sum(a))
else:
t=0
for i in range(k):
t+=a[-i-1]
a.append(t)
if s==a[-1]:
print(2)
print(0,a[-1])
else:
use=[]
for i in range(len(a)):
if s>=a[-... | Title: Well-known Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Numbers *k*-bonacci (*k* is integer, *k*<=><=1) are a generalization of Fibonacci numbers and are determined as follows:
- *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=<<=*k*; - *F*(*k*,<=*k*)<==<=1; - ... | ```python
s,k=list(map(int,input().split(' ')))
a=[0,1,1]
while a[-1]<s:
if len(a)<k:
a.append(sum(a))
else:
t=0
for i in range(k):
t+=a[-i-1]
a.append(t)
if s==a[-1]:
print(2)
print(0,a[-1])
else:
use=[]
for i in range(len(a)):
... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,610,219,109 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | m, n = input().split()
board = int(m) * int(n)
print(int(board / 2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m, n = input().split()
board = int(m) * int(n)
print(int(board / 2))
``` | 3.969 |
0 | none | none | none | 0 | [
"none"
] | null | null | 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 ... | 0 | [
{
"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,430,381,132 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 4,710,400 | n=int(input())
p=input().split()
l=[]
i=0
while i<n:
l.append(int(p[i]))
i=i+1
s=l[0]
for i in range(1,n):
s=s+l[i]+i*(l[i]-1)
print(s)
| Title: none
Time Limit: None seconds
Memory Limit: None 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* questions; the que... | ```python
n=int(input())
p=input().split()
l=[]
i=0
while i<n:
l.append(int(p[i]))
i=i+1
s=l[0]
for i in range(1,n):
s=s+l[i]+i*(l[i]-1)
print(s)
``` | 3 | |
895 | C | Square Subsets | PROGRAMMING | 2,000 | [
"bitmasks",
"combinatorics",
"dp",
"math"
] | null | null | Petya was late for the lesson too. The teacher gave him an additional task. For some array *a* Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer.
Two ways are considered different if sets of indexes of ele... | First line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array.
Second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=70) — the elements of the array. | Print one integer — the number of different ways to choose some elements so that their product is a square of a certain integer modulo 109<=+<=7. | [
"4\n1 1 1 1\n",
"4\n2 2 2 2\n",
"5\n1 2 4 5 8\n"
] | [
"15\n",
"7\n",
"7\n"
] | In first sample product of elements chosen by any way is 1 and 1 = 1<sup class="upper-index">2</sup>. So the answer is 2<sup class="upper-index">4</sup> - 1 = 15.
In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is ... | 1,750 | [
{
"input": "4\n1 1 1 1",
"output": "15"
},
{
"input": "4\n2 2 2 2",
"output": "7"
},
{
"input": "5\n1 2 4 5 8",
"output": "7"
},
{
"input": "1\n64",
"output": "1"
},
{
"input": "5\n2 2 2 2 2",
"output": "15"
},
{
"input": "6\n1 2 3 4 5 6",
"output"... | 1,584,599,974 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 4,000 | 41,472,000 | from sys import stdin
def find_prime(max_value):
assert max_value >= 2
result = [2]
for i in range(3, max_value):
state = 1
for item in result:
if item * item > i:
break
elif i % item == 0:
state = -1
brea... | Title: Square Subsets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya was late for the lesson too. The teacher gave him an additional task. For some array *a* Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their produc... | ```python
from sys import stdin
def find_prime(max_value):
assert max_value >= 2
result = [2]
for i in range(3, max_value):
state = 1
for item in result:
if item * item > i:
break
elif i % item == 0:
state = -1
... | 0 | |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,582,170,581 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | full = ""
for i in range(1,400):
full += str(i)
n = int(input())
print(full[n-1]) | Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
full = ""
for i in range(1,400):
full += str(i)
n = int(input())
print(full[n-1])
``` | 3 | |
735 | D | Taxes | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while fo... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt. | Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax. | [
"4\n",
"27\n"
] | [
"2\n",
"3\n"
] | none | 1,750 | [
{
"input": "4",
"output": "2"
},
{
"input": "27",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "2000000000",
"output": "2"
},
{
"input": "26",
"output": ... | 1,562,399,220 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = input()
if (a==2) print("1")
elif (a%2==0) print("2")
else print("3") | Title: Taxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not ... | ```python
a = input()
if (a==2) print("1")
elif (a%2==0) print("2")
else print("3")
``` | -1 | |
629 | C | Famil Door and Brackets | PROGRAMMING | 2,000 | [
"dp",
"strings"
] | null | null | As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length *n* more than any other strings!
The sequence of round brackets is called valid if and only if:
1... | First line contains *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100<=000,<=*n*<=-<=*m*<=≤<=2000) — the desired length of the string and the length of the string bought by Gabi, respectively.
The second line contains string *s* of length *m* consisting of characters '(' and ')' only. | Print the number of pairs of string *p* and *q* such that *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets modulo 109<=+<=7. | [
"4 1\n(\n",
"4 4\n(())\n",
"4 3\n(((\n"
] | [
"4\n",
"1\n",
"0\n"
] | In the first sample there are four different valid pairs:
1. *p* = "(", *q* = "))" 1. *p* = "()", *q* = ")" 1. *p* = "", *q* = "())" 1. *p* = "", *q* = ")()"
In the second sample the only way to obtain a desired string is choose empty *p* and *q*.
In the third sample there is no way to get a valid sequence of b... | 1,750 | [
{
"input": "4 1\n(",
"output": "4"
},
{
"input": "4 4\n(())",
"output": "1"
},
{
"input": "4 3\n(((",
"output": "0"
},
{
"input": "875 50\n)))((())()))((()(())))))())))((((((()))))))()(((((",
"output": "0"
},
{
"input": "1980 464\n))(()()))(((((((((()))))))(()((((... | 1,455,990,456 | 4,356 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 31 | 0 | n,m = map(int,input().split())
s = input()
if n % 2 == 0:
p = 0
q = 0
p2 = -10000000
for i in range(m):
if s[i] == "(":
p -= 1
q += 1
else:
p += 1
q -= 1
if p > p2:
p2 = p
num = 0
if p2 > 0:
... | Title: Famil Door and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets o... | ```python
n,m = map(int,input().split())
s = input()
if n % 2 == 0:
p = 0
q = 0
p2 = -10000000
for i in range(m):
if s[i] == "(":
p -= 1
q += 1
else:
p += 1
q -= 1
if p > p2:
p2 = p
num = 0
if p2 ... | 0 | |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,699,371,815 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n,k=map(int,input().split())
arr = [int(x) for x in input.split()]
next_round=[x for x in arr if(x>0 and x>=arr[k-1])]
print(len(next_round)) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
n,k=map(int,input().split())
arr = [int(x) for x in input.split()]
next_round=[x for x in arr if(x>0 and x>=arr[k-1])]
print(len(next_round))
``` | -1 | |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,642,231,753 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 25 | 2,000 | 9,216,000 | def longestString(N, S):
ans = 0
for i in range (N - 1, 0, -1):
if S[ : i] == S[N - i :]:
if S[ : i] in S[1 : N - 1]:
ans = i
break
if not ans:
return "Just a legend"
return S[ : ans]
x=input()
print(longestStri... | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
def longestString(N, S):
ans = 0
for i in range (N - 1, 0, -1):
if S[ : i] == S[N - i :]:
if S[ : i] in S[1 : N - 1]:
ans = i
break
if not ans:
return "Just a legend"
return S[ : ans]
x=input()
print(l... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 0 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,619,042,744 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 90 | 2,000 | 10,342,400 | def isEquivalent(at, bt):
size = len(at)
if(size % 2 == 1):
return at == bt
mid = size//2
a1 = at[:mid]
a2 = at[mid:]
b1 = bt[:mid]
b2 = bt[mid:]
return (isEquivalent(a1, b1) and isEquivalent(a2, b2)) or (isEquivalent(a1, b2) and isEquivalent(a2, b1))
a = input(... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into t... | ```python
def isEquivalent(at, bt):
size = len(at)
if(size % 2 == 1):
return at == bt
mid = size//2
a1 = at[:mid]
a2 = at[mid:]
b1 = bt[:mid]
b2 = bt[mid:]
return (isEquivalent(a1, b1) and isEquivalent(a2, b2)) or (isEquivalent(a1, b2) and isEquivalent(a2, b1))
... | 0 | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,650,140,879 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 40 | 93 | 2,252,800 | from collections import deque
n, m = map(int,input().split())
d = list(map(int,input().split()))
sm = sum(d)
ok = -1
for i in range(n):
if sm == 0:
break
for j in range(n):
if d[j] != 0:
if d[j] <= m:
sm -= d[j]
d[j] = 0
ok = j + 1
... | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
from collections import deque
n, m = map(int,input().split())
d = list(map(int,input().split()))
sm = sum(d)
ok = -1
for i in range(n):
if sm == 0:
break
for j in range(n):
if d[j] != 0:
if d[j] <= m:
sm -= d[j]
d[j] = 0
ok =... | 0 | |
424 | C | Magic Formulas | PROGRAMMING | 1,600 | [
"math"
] | null | null | People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas:
Here, "mod" means the operation of taking the residue after dividing.
The expression means applying ... | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=106). The next line contains *n* integers: *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=2·109). | The only line of output should contain a single integer — the value of *Q*. | [
"3\n1 2 3\n"
] | [
"3\n"
] | none | 1,500 | [
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n65535 0",
"output": "65534"
},
{
"input": "10\n1356106972 165139648 978829595 410669403 873711167 287346624 117863440 228957745 835903650 1575323015",
"output": "948506286"
},
{... | 1,679,130,000 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n=int(input())
lst=list(map(int,input().split()))
m=0
for i in lst:
m=m^i
print(m^n)
| Title: Magic Formulas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas:
He... | ```python
n=int(input())
lst=list(map(int,input().split()))
m=0
for i in lst:
m=m^i
print(m^n)
``` | 0 | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,686,623,195 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 78 | 1,331,200 | from collections import Counter
s = input()
bank = dict(Counter(input()))
yay = 0
for letter in s:
if letter in bank and bank[letter] > 0:
bank[letter] -= 1
yay += 1
print(yay, len(s) - yay)
| Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
from collections import Counter
s = input()
bank = dict(Counter(input()))
yay = 0
for letter in s:
if letter in bank and bank[letter] > 0:
bank[letter] -= 1
yay += 1
print(yay, len(s) - yay)
``` | 0 | |
163 | E | e-Government | PROGRAMMING | 2,800 | [
"data structures",
"dfs and similar",
"dp",
"strings",
"trees"
] | null | null | The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis.
We know that any of the *k* citizens can become a member of the Embezzland government. The citizens' surnames are *a*1,<=*a*2,<=...,<=*a**k*. All surnames... | The first line contains space-separated integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105) — the number of queries to the system and the number of potential government members.
Next *k* lines contain the surnames *a*1,<=*a*2,<=...,<=*a**k*, one per line. All surnames are pairwise different.
Next *n* lines contain queries... | For any "calculate politicization" operation print on a separate line the degree of the politicization of the given text. Print nothing for other operations. | [
"7 3\na\naa\nab\n?aaab\n-2\n?aaab\n-3\n?aaab\n+2\n?aabbaa\n"
] | [
"6\n4\n3\n6\n"
] | none | 2,500 | [] | 1,681,378,036 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 11,673,600 | def count_substring_occurrences(substring, text):
return sum(1 for i in range(len(text) - len(substring) + 1) if text[i:i + len(substring)] == substring)
def main():
n, k = map(int, input().split())
surnames = [input().strip() for _ in range(k)]
gov_members = set(range(k))
for _ in range(n... | Title: e-Government
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis.
We know that any of the *k* citizens can become a member... | ```python
def count_substring_occurrences(substring, text):
return sum(1 for i in range(len(text) - len(substring) + 1) if text[i:i + len(substring)] == substring)
def main():
n, k = map(int, input().split())
surnames = [input().strip() for _ in range(k)]
gov_members = set(range(k))
for _ ... | 0 | |
999 | A | Mishka and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ... | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are... | Print one integer — the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, M... | 0 | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1... | 1,623,426,335 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 62 | 0 | n,p=map(int,input().split())
l=list(map(int,input().split()))
x=0
ans=0
while x<len(l):
if p>=l[x]:
l.pop(x)
ans+=1
else:
break
y=len(l)-1
while y>0:
if p>=l[y]:
ans+=1
l.pop(y)
y-=1
else:
break
print(ans)
... | Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his... | ```python
n,p=map(int,input().split())
l=list(map(int,input().split()))
x=0
ans=0
while x<len(l):
if p>=l[x]:
l.pop(x)
ans+=1
else:
break
y=len(l)-1
while y>0:
if p>=l[y]:
ans+=1
l.pop(y)
y-=1
else:
break
print(a... | 3 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,670,484,777 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 122 | 307,200 | N = 100001
primes = [1]*N
def sieve():
primes[1] = 0
for p in range(2, int(N*0.5)+1):
if primes[p] == 1:
for i in range(2*p, N, p):
primes[i] = 0
def almostPrimes(n):
res = 0
# 6 is First almost primes no
for i in range(6, n+1):
count = 0
for j in range(2, int(i**0.5)+1):
if (i %... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
N = 100001
primes = [1]*N
def sieve():
primes[1] = 0
for p in range(2, int(N*0.5)+1):
if primes[p] == 1:
for i in range(2*p, N, p):
primes[i] = 0
def almostPrimes(n):
res = 0
# 6 is First almost primes no
for i in range(6, n+1):
count = 0
for j in range(2, int(i**0.5)+1):
... | -1 |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,510,438,340 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | input_file = open("input.txt", "r")
output_file = open("outpute.txt", "w")
secInDay = 86400
n = input_file.readline().split()
t = int(n[-1])
n = int(n[0])
#print(n, t)
a = input_file.readline().split()
i = -1
while t > 0:
i += 1
t -= secInDay - int(a[i])
print(i+1)
output_file.write(str(i))
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
input_file = open("input.txt", "r")
output_file = open("outpute.txt", "w")
secInDay = 86400
n = input_file.readline().split()
t = int(n[-1])
n = int(n[0])
#print(n, t)
a = input_file.readline().split()
i = -1
while t > 0:
i += 1
t -= secInDay - int(a[i])
print(i+1)
output_file.write(s... | -1 | |
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,689,116,888 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n = int(input())
l = list(map(int, input().split()))
worst, best, am= l[0], l[0], 0
for c in l:
if c > best:
best = c; am += 1
elif c < worst:
worst = c; am += 1
print(am)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
l = list(map(int, input().split()))
worst, best, am= l[0], l[0], 0
for c in l:
if c > best:
best = c; am += 1
elif c < worst:
worst = c; am += 1
print(am)
``` | 3 | |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,599,966,273 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 389 | 11,366,400 | def dfs(visited,sv,arr,A):
visited[sv]=True
A.append(arr[sv])
for i in graph[sv]:
if not visited[i]:
dfs(visited,i,arr,A)
def solve(graph,arr,n):
visited=[False for _ in range(n)]
ans=0
for i in range(n):
if not visited[i]:
A=[]
dfs(visited,i,arr,A)
... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
def dfs(visited,sv,arr,A):
visited[sv]=True
A.append(arr[sv])
for i in graph[sv]:
if not visited[i]:
dfs(visited,i,arr,A)
def solve(graph,arr,n):
visited=[False for _ in range(n)]
ans=0
for i in range(n):
if not visited[i]:
A=[]
dfs(visited,i,ar... | -1 | |
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk... | 1,518,706,265 | 965 | Python 3 | OK | TESTS | 48 | 62 | 5,632,000 | def pal(s):
if(s==s[::-1]):
return 1;
else:
return 0
k=input()
if(pal(k)==1):
print(k)
else:
print(k+k[::-1]) | Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co... | ```python
def pal(s):
if(s==s[::-1]):
return 1;
else:
return 0
k=input()
if(pal(k)==1):
print(k)
else:
print(k+k[::-1])
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,619,506,870 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 0 | word = input()
c=0
y=False
cl=''
for i in range(0, len(word)):
cl = word[i]
y = cl.isupper()
if y == True:
c = c+1
if c > (len(word)/2):
print(word.upper())
else:
print(word.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
word = input()
c=0
y=False
cl=''
for i in range(0, len(word)):
cl = word[i]
y = cl.isupper()
if y == True:
c = c+1
if c > (len(word)/2):
print(word.upper())
else:
print(word.lower())
``` | 3.9615 |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,546,641,401 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | s=input()
n=int(input())
a=list(map(int,input().split()))
sum1=0
i=1
for c in s:
sum1+=a[ord(c)-ord('a')]*i
i+=1
a.sort()
for j in range(26-n,26):
i+=1
sum1+=a[j]*i
print(sum1)
| Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
s=input()
n=int(input())
a=list(map(int,input().split()))
sum1=0
i=1
for c in s:
sum1+=a[ord(c)-ord('a')]*i
i+=1
a.sort()
for j in range(26-n,26):
i+=1
sum1+=a[j]*i
print(sum1)
``` | 0 | |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,513,929,150 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 998 | 16,588,800 | m=input()
cont=0
cont2=0
B=[]
C=[]
for i in m :
if i == "(" :
B.append(i)
if i == ")" :
if len(B)!=0:
if B.pop() == "(" :
cont+=1
else:cont2+=1
print(cont*2)
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
m=input()
cont=0
cont2=0
B=[]
C=[]
for i in m :
if i == "(" :
B.append(i)
if i == ")" :
if len(B)!=0:
if B.pop() == "(" :
cont+=1
else:cont2+=1
print(cont*2)
``` | 3.869301 |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,692,482,116 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | p = int(input("Ingresa el peso de la sandía: "))
if p % 2 == 0 and p > 2:
print("YES")
else:
print("NO")
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
p = int(input("Ingresa el peso de la sandía: "))
if p % 2 == 0 and p > 2:
print("YES")
else:
print("NO")
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He pain... | The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides ex... | Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. | [
"1 1 1 1 1 1\n",
"1 2 1 2 1 2\n"
] | [
"6\n",
"13\n"
] | This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espress... | 0 | [
{
"input": "1 1 1 1 1 1",
"output": "6"
},
{
"input": "1 2 1 2 1 2",
"output": "13"
},
{
"input": "2 4 5 3 3 6",
"output": "83"
},
{
"input": "45 19 48 18 46 21",
"output": "6099"
},
{
"input": "66 6 65 6 66 5",
"output": "5832"
},
{
"input": "7 5 4 8 ... | 1,437,582,481 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | import sys
(a1, a2, a3, a4, a5, a6) = map(int, input().split())
def calc(h):
res = 0
cur = 1
while cur <= h:
res += cur + cur - 1
cur += 1
return res
ax1 = a4
ax2 = a6
ans = calc(ax1 + ax2 + a5) - calc(ax1) - calc(ax2) - calc(a2)
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centime... | ```python
import sys
(a1, a2, a3, a4, a5, a6) = map(int, input().split())
def calc(h):
res = 0
cur = 1
while cur <= h:
res += cur + cur - 1
cur += 1
return res
ax1 = a4
ax2 = a6
ans = calc(ax1 + ax2 + a5) - calc(ax1) - calc(ax2) - calc(a2)
print(ans)
``` | 3 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,697,806,522 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a = int(input())
b = list(map(int, input().split()))
if b.index(min(b)) > b.index(max(a)):
print (-1 + a - 1)
else:
print(-1 + a) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
a = int(input())
b = list(map(int, input().split()))
if b.index(min(b)) > b.index(max(a)):
print (-1 + a - 1)
else:
print(-1 + a)
``` | -1 | |
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexit... | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ... | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"inp... | 1,598,471,586 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 0 | n, a, b = map(int, input().split())
l=list(map(int, input().split()))
l.sort()
if l[a+1]-l[a]>0:
print(l[a+1]-l[a])
else:
print(0)
| Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th... | ```python
n, a, b = map(int, input().split())
l=list(map(int, input().split()))
l.sort()
if l[a+1]-l[a]>0:
print(l[a+1]-l[a])
else:
print(0)
``` | -1 | |
843 | B | Interactive LowerBound | PROGRAMMING | 2,000 | [
"brute force",
"interactive",
"probabilities"
] | null | null | This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to *x*.
More formally, there is a singly liked list built on an array of *n* elements. Element with index *i* contains two integers: *value**i* ... | The first line contains three integers *n*, *start*, *x* (1<=≤<=*n*<=≤<=50000, 1<=≤<=*start*<=≤<=*n*, 0<=≤<=*x*<=≤<=109) — the number of elements in the list, the index of the first element and the integer *x*. | To print the answer for the problem, print ! ans, where ans is the minimum integer in the list greater than or equal to *x*, or -1, if there is no such integer. | [
"5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4\n"
] | [
"? 1\n? 2\n? 3\n? 4\n? 5\n! 81"
] | You can read more about singly linked list by the following link: [https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list](https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list)
The illustration for the first sample case. Start and finish elements are marked dark. <img class="tex-graphics" src="https://e... | 1,000 | [
{
"input": "5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4",
"output": "81\n1003"
},
{
"input": "5 1 6\n1 2\n2 3\n3 4\n4 5\n5 -1",
"output": "-1\n1002"
},
{
"input": "1 1 0\n0 -1",
"output": "0\n2"
},
{
"input": "1 1 2\n0 -1",
"output": "-1\n1002"
},
{
"input": "1 1 100000... | 1,509,454,736 | 2,147,483,647 | Python 3 | OK | TESTS | 171 | 139 | 716,800 | from random import sample
from sys import stdout
read=lambda :map(int,input().split())
def ask(x):
print('? {}'.format(x))
stdout.flush()
return tuple(read())
def answer(x):
print('! {}'.format(x))
stdout.flush()
exit(0)
n,st,x=read()
a=[ask(st)]
if a[0][0]>=x: answer(a[0][0])
for i in sample(range(1,n+1),m... | Title: Interactive LowerBound
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to *x*.
More formally, there is a si... | ```python
from random import sample
from sys import stdout
read=lambda :map(int,input().split())
def ask(x):
print('? {}'.format(x))
stdout.flush()
return tuple(read())
def answer(x):
print('! {}'.format(x))
stdout.flush()
exit(0)
n,st,x=read()
a=[ask(st)]
if a[0][0]>=x: answer(a[0][0])
for i in sample(rang... | 3 | |
294 | B | Shaass and Bookshelf | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | Shaass has *n* books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the *i*-th book is *t**i* and its pages' width is equal to *w**i*. The thickness of each book is either 1 or 2. All books have the same page heights.
Shaass puts the bo... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). Each of the next *n* lines contains two integers *t**i* and *w**i* denoting the thickness and width of the *i*-th book correspondingly, (1<=≤<=*t**i*<=≤<=2,<=1<=≤<=*w**i*<=≤<=100). | On the only line of the output print the minimum total thickness of the vertical books that we can achieve. | [
"5\n1 12\n1 3\n2 15\n2 5\n2 1\n",
"3\n1 10\n2 1\n2 4\n"
] | [
"5\n",
"3\n"
] | none | 1,000 | [
{
"input": "5\n1 12\n1 3\n2 15\n2 5\n2 1",
"output": "5"
},
{
"input": "3\n1 10\n2 1\n2 4",
"output": "3"
},
{
"input": "10\n2 10\n2 4\n2 8\n2 3\n2 5\n2 6\n1 2\n1 10\n1 10\n2 5",
"output": "12"
},
{
"input": "1\n2 7",
"output": "2"
},
{
"input": "50\n1 24\n1 16\n1... | 1,631,956,335 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 26 | 109 | 21,708,800 | n=int(input())
a=[0]*n
for i in range(n):
a[i]=list(map(int,input().split()))
s=sum(x[1] for x in a)
x=10000
dp=[0]*x
for v,w in a:
for i in range(x-1,v-1,-1):
dp[i]=max(dp[i],dp[i-v]+w)
for i in range(x):
if i>=s-dp[i]:
print(i)
break | Title: Shaass and Bookshelf
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has *n* books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the *i*-th book is *t**i* and its pages' width is equal to *w**... | ```python
n=int(input())
a=[0]*n
for i in range(n):
a[i]=list(map(int,input().split()))
s=sum(x[1] for x in a)
x=10000
dp=[0]*x
for v,w in a:
for i in range(x-1,v-1,-1):
dp[i]=max(dp[i],dp[i-v]+w)
for i in range(x):
if i>=s-dp[i]:
print(i)
break
``` | 0 | |
387 | A | George and Sleep | PROGRAMMING | 900 | [
"implementation"
] | null | null | George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ... | The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≤<=*hh*<=≤<=23, 00<=≤<=*mm*<=≤<=59. | In the single line print time *p* — the time George went to bed in the format similar to the format of the time in the input. | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n"
] | In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all. | 500 | [
{
"input": "05:50\n05:44",
"output": "00:06"
},
{
"input": "00:00\n01:00",
"output": "23:00"
},
{
"input": "00:01\n00:00",
"output": "00:01"
},
{
"input": "23:59\n23:59",
"output": "00:00"
},
{
"input": "23:44\n23:55",
"output": "23:49"
},
{
"input": "... | 1,391,096,312 | 511 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 62 | 409,600 | s = input()
p = input()
t1 = int(s[len(s) - 2:len(s)]) - int(p[len(p) - 2:len(p)])
k = 0
if t1 < 0:
t1 += 60
k = 1
t0 = int(s[:2]) - int(p[:2]) + k
while t0 < 0:
t0 += 24
t0 %= 24
res = str(t0) + ':'
if len(res) < 3:
res = '0' + res
ss = '0' + str(t1)
ss = ss[-2:]
res += ss
print(res) | Title: George and Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when Geor... | ```python
s = input()
p = input()
t1 = int(s[len(s) - 2:len(s)]) - int(p[len(p) - 2:len(p)])
k = 0
if t1 < 0:
t1 += 60
k = 1
t0 = int(s[:2]) - int(p[:2]) + k
while t0 < 0:
t0 += 24
t0 %= 24
res = str(t0) + ':'
if len(res) < 3:
res = '0' + res
ss = '0' + str(t1)
ss = ss[-2:]
res += ss
pr... | 0 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,698,145,849 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | l, b = map(int, input().split())
years = 1
while l <= b:
l = 3 * l
b = 2 * b
years += 1
print(years - 1) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
l, b = map(int, input().split())
years = 1
while l <= b:
l = 3 * l
b = 2 * b
years += 1
print(years - 1)
``` | 3 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,694,017,696 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 62 | 0 | d,e=map(int,input().split())
cnt=0
while d<=e:
d=d*3
e=e*2
cnt+=1
print(cnt) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
d,e=map(int,input().split())
cnt=0
while d<=e:
d=d*3
e=e*2
cnt+=1
print(cnt)
``` | 3 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,677,487,628 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n = int(input())
home = []
guest = {}
for i in range(n):
h,a = input().split()
h = int(h)
a = int(a)
home.append(h)
if guest.get(a) == None:
guest[a] = 1
else:
guest[a] += 1
count = 0
for i in home:
if guest.get(i) != None:
count += guest[i]
print(coun... | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
n = int(input())
home = []
guest = {}
for i in range(n):
h,a = input().split()
h = int(h)
a = int(a)
home.append(h)
if guest.get(a) == None:
guest[a] = 1
else:
guest[a] += 1
count = 0
for i in home:
if guest.get(i) != None:
count += guest[i]
... | 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,696,044,005 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | limit, idx = input().split()
limit, idx = int(limit), int(idx)
if idx>limit/2:
idx -= int(limit/2)+1
print(2*idx)
else:
print(2*idx-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
limit, idx = input().split()
limit, idx = int(limit), int(idx)
if idx>limit/2:
idx -= int(limit/2)+1
print(2*idx)
else:
print(2*idx-1)
``` | 0 | |
322 | A | Ciel and Dancing | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. | In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. | [
"2 1\n",
"2 2\n"
] | [
"2\n1 1\n2 1\n",
"3\n1 1\n1 2\n2 2\n"
] | In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | 500 | [
{
"input": "2 1",
"output": "2\n1 1\n2 1"
},
{
"input": "2 2",
"output": "3\n1 1\n1 2\n2 2"
},
{
"input": "1 1",
"output": "1\n1 1"
},
{
"input": "2 3",
"output": "4\n1 1\n1 2\n1 3\n2 3"
},
{
"input": "4 4",
"output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4"
}... | 1,569,616,023 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 248 | 0 | n,m=map(int,input().split())
print(m+n-1)
for i in range(1,m+1):
print(1,i)
for i in range(2,n+1):
print(i,1)
| Title: Ciel and Dancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. B... | ```python
n,m=map(int,input().split())
print(m+n-1)
for i in range(1,m+1):
print(1,i)
for i in range(2,n+1):
print(i,1)
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,694,517,768 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | weight = int(input())
chasti = int(input())
if chasti % 2 ==0:
if weight % chasti == 0:
print("Yes")
else:
print("No") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
weight = int(input())
chasti = int(input())
if chasti % 2 ==0:
if weight % chasti == 0:
print("Yes")
else:
print("No")
``` | -1 |
602 | B | Approximating a Constant Range | PROGRAMMING | 1,400 | [
"dp",
"implementation",
"two pointers"
] | null | null | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000). | Print a single number — the maximum length of an almost constant range of the given sequence. | [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] | [
"4\n",
"5\n"
] | In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10]. | 1,000 | [
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 ... | 1,679,262,119 | 2,147,483,647 | Python 3 | OK | TESTS | 107 | 264 | 7,065,600 | n = int(input())
a = [int(x) for x in input().split()]
d = {}
for x in a:
d[x] = 0
ans = 0
j = 0
m = 0
for i in range(n):
while j < n and m <= 2:
if d[a[j]] == 0 and m == 2:
break
elif d[a[j]] == 0:
m += 1
d[a[j]] += 1
j += 1
ans = max(ans, j - i)
d[a[i]] -= 1
... | Title: Approximating a Constant Range
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo... | ```python
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for x in a:
d[x] = 0
ans = 0
j = 0
m = 0
for i in range(n):
while j < n and m <= 2:
if d[a[j]] == 0 and m == 2:
break
elif d[a[j]] == 0:
m += 1
d[a[j]] += 1
j += 1
ans = max(ans, j - i)
d[a[i... | 3 | |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on... | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4... | 1,685,465,445 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | import sys
input = sys.stdin.readline
for _ in range(1):#int(input())):
n = int(input())
a = []
if (n % 4 == 0 or n % 4 == 2):
for i in range(1,n+1):
if (i % 4 == 0 or i % 4 == 1):
a.append(i)
if (n % 4 == 0):
print(0)
else:
... | Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help P... | ```python
import sys
input = sys.stdin.readline
for _ in range(1):#int(input())):
n = int(input())
a = []
if (n % 4 == 0 or n % 4 == 2):
for i in range(1,n+1):
if (i % 4 == 0 or i % 4 == 1):
a.append(i)
if (n % 4 == 0):
print(0)
el... | 0 | |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th... | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5... | 1,477,086,194 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | x,y,a,b = map(int,input().split())
if a % x == 0 :
start = a
else :
start = (a//x +1)*x
n = 0
while start <= b :
if start % y == 0 :
n += 1
start += x
print(b) | Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub ... | ```python
x,y,a,b = map(int,input().split())
if a % x == 0 :
start = a
else :
start = (a//x +1)*x
n = 0
while start <= b :
if start % y == 0 :
n += 1
start += x
print(b)
``` | 0 | |
992 | A | Nastya and an Array | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. | Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. | [
"5\n1 1 1 1 1\n",
"3\n2 0 -1\n",
"4\n5 -6 -5 1\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | 500 | [
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "3\n2 0 -1",
"output": "2"
},
{
"input": "4\n5 -6 -5 1",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n21794 -79194",
"output": "2"
},
{
"input": "3\n-63526 95085 -5239",
... | 1,619,520,922 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 156 | 7,782,400 | n=int(input())
li=list(map(int,input().split()))
li.sort()
if(len(set(li))==1 and li[0]!=0):
print(1)
elif(len(set(li))==1 and li[0]==0):
print(0)
else:
c=0
for i in set(li):
if i!=0:
c=c+1
print(c)
| Title: Nastya and an Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second ... | ```python
n=int(input())
li=list(map(int,input().split()))
li.sort()
if(len(set(li))==1 and li[0]!=0):
print(1)
elif(len(set(li))==1 and li[0]==0):
print(0)
else:
c=0
for i in set(li):
if i!=0:
c=c+1
print(c)
``` | 3 | |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question corr... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment... | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 2... | 1,689,410,456 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | from collections import deque
t = 1#int(input())
for _ in range(t):
n = int(input())
d = list(map(int,input().split()))
cnt = 0
ok = 0
l,r = 0,0
for i in range(1,n):
if d[i - 1] > d[i]:
if ok:
print('No')
exit()
cnt +=... | Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your frie... | ```python
from collections import deque
t = 1#int(input())
for _ in range(t):
n = int(input())
d = list(map(int,input().split()))
cnt = 0
ok = 0
l,r = 0,0
for i in range(1,n):
if d[i - 1] > d[i]:
if ok:
print('No')
exit()
... | 0 | |
932 | B | Recursive Queries | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"dfs and similar"
] | null | null | Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. | The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9). | For each query, print a single line containing the answer for that query. | [
"4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n",
"4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n"
] | [
"1\n4\n0\n8\n",
"3\n1\n1\n5\n"
] | In the first example:
- *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4 | 1,000 | [
{
"input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4",
"output": "1\n4\n0\n8"
},
{
"input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4",
"output": "3\n1\n1\n5"
}
] | 1,518,709,235 | 3,935 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 2,000 | 5,632,000 | def proiz(a):
t = 1
a=str(a)
for i in range(len(a)):
if a[i]!='0':
t=t*int(a[i])
return t
def rsult(a):
a=int(a)
if a<10:
return a
else:
return rsult(proiz(a))
q=int(input())
for i in range(q):
l, r, k=input().split()
l =int(l)
... | Title: Recursive Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x*... | ```python
def proiz(a):
t = 1
a=str(a)
for i in range(len(a)):
if a[i]!='0':
t=t*int(a[i])
return t
def rsult(a):
a=int(a)
if a<10:
return a
else:
return rsult(proiz(a))
q=int(input())
for i in range(q):
l, r, k=input().split()
l ... | 0 | |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,665,143,199 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | c = ['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']
u = [x.upper() for x in c]
n = [str(x) for x in range(10)]
sp = ["!", "?", ".", ",", "_"]
s = str(input())
nc = 0
nu = 0
nn = 0
nsp = 0
for i in range(len(s)):
i... | Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
c = ['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']
u = [x.upper() for x in c]
n = [str(x) for x in range(10)]
sp = ["!", "?", ".", ",", "_"]
s = str(input())
nc = 0
nu = 0
nn = 0
nsp = 0
for i in range(len(s... | 0 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,627,482,649 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 124 | 6,963,200 | n = int(input())
s = list(map(int, input().split()))
ba = 0
bi = 0
ch = 0
for i in range(0,n):
if i % 3 == 0:
ch += s[i]
elif i % 2 == 0:
ba += s[i]
else:
bi += s[i]
if max(ba, bi, ch) == ba:
print('back')
elif max(ba, bi, ch) == bi:
print('biceps')
else:
... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n = int(input())
s = list(map(int, input().split()))
ba = 0
bi = 0
ch = 0
for i in range(0,n):
if i % 3 == 0:
ch += s[i]
elif i % 2 == 0:
ba += s[i]
else:
bi += s[i]
if max(ba, bi, ch) == ba:
print('back')
elif max(ba, bi, ch) == bi:
print('biceps')
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are *n* bottles on the ground, the *i*-th bottle is located at position (*x**i*,<=*y**i*). Both Adil a... | First line of the input contains six integers *a**x*, *a**y*, *b**x*, *b**y*, *t**x* and *t**y* (0<=≤<=*a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*t**x*,<=*t**y*<=≤<=109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of bo... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The ... | [
"3 1 1 2 0 0\n3\n1 1\n2 1\n2 3\n",
"5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3\n"
] | [
"11.084259940083\n",
"33.121375178000\n"
] | Consider the first sample.
Adil will use the following path: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/37eea809c04afe04f2670475cc5b21df4a90afd1.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Bera will use the following path: <img align="middle" class="tex-formula" src="https:... | 0 | [
{
"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3",
"output": "11.084259940083"
},
{
"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3",
"output": "33.121375178000"
},
{
"input": "107 50 116 37 104 118\n12\n16 78\n95 113\n112 84\n5 88\n54 85\n112 80\n19 98\n25 14\n48 76\n95 70\n77 94\n38 32",
... | 1,627,328,876 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 24 | 780 | 31,948,800 | import math
def getdist(x,y,a,c):
return math.sqrt((x-a)**2+(c-y)**2)
def main(n,points,start):
x1,y1=start[0],start[1]
x2,y2=start[2],start[3]
x3,y3=start[4],start[5]
dist=[]
dist_p1=[]
dist_p2=[]
for i in range(len(points)):
x4,y4=points[i]
dist.append(getdist(x4... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are *n* bott... | ```python
import math
def getdist(x,y,a,c):
return math.sqrt((x-a)**2+(c-y)**2)
def main(n,points,start):
x1,y1=start[0],start[1]
x2,y2=start[2],start[3]
x3,y3=start[4],start[5]
dist=[]
dist_p1=[]
dist_p2=[]
for i in range(len(points)):
x4,y4=points[i]
dist.append(... | 0 | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,668,439,180 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | n, m, k = [int(x) for x in input().split()]
Matrix = [[0 for i in range(m)] for j in range(n)]
for u in range(1, k+1):
r, c = [int(x) for x in input().split()]
Matrix[r-1][c-1] = u
run = [[0, 0], [1, 0], [0, 1], [1, 1]]
step = 99999999
for i in range(m-1):
for j in range(n-1):
z = 0
... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
n, m, k = [int(x) for x in input().split()]
Matrix = [[0 for i in range(m)] for j in range(n)]
for u in range(1, k+1):
r, c = [int(x) for x in input().split()]
Matrix[r-1][c-1] = u
run = [[0, 0], [1, 0], [0, 1], [1, 1]]
step = 99999999
for i in range(m-1):
for j in range(n-1):
z =... | 0 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,612,548,942 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 124 | 10,444,800 | n, b, d = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
now = 0
for u in range(n):
now += a[u]
if now > d:
ans += 1
now = 0
print(ans) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
now = 0
for u in range(n):
now += a[u]
if now > d:
ans += 1
now = 0
print(ans)
``` | 0 | |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,650,597,993 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | inp = [input(), input(), input()]
inp = [sum(1 for i in j if i in 'aeiou') for j in inp]
print(inp == [5,7,5]) | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
inp = [input(), input(), input()]
inp = [sum(1 for i in j if i in 'aeiou') for j in inp]
print(inp == [5,7,5])
``` | 0 |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,697,831,071 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 46 | 102,400 | n = int(input())
a = []
flag = 1
for i in range(n):
row = list(input())
a.append(row)
if row[0] == 'O' and row[1] == 'O' and flag:
flag = 0
row[0] = row[1] = '+'
elif row[3] == 'O' and row[4] == 'O' and flag:
flag = 0
row[3] = row[4] = '+'
if flag:
... | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
n = int(input())
a = []
flag = 1
for i in range(n):
row = list(input())
a.append(row)
if row[0] == 'O' and row[1] == 'O' and flag:
flag = 0
row[0] = row[1] = '+'
elif row[3] == 'O' and row[4] == 'O' and flag:
flag = 0
row[3] = row[4] = '+'
if... | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,558,534,406 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 218 | 0 | r,b,g=[int(x) for x in input().split()]
su=int(0)
m=min(r,g,b)
su+=m
r=r-m
g=g-m
b=b-m
su+=r//3
su+=g//3
su+=b//3
print(su) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
r,b,g=[int(x) for x in input().split()]
su=int(0)
m=min(r,g,b)
su+=m
r=r-m
g=g-m
b=b-m
su+=r//3
su+=g//3
su+=b//3
print(su)
``` | 0 | |
424 | A | Squats | PROGRAMMING | 900 | [
"implementation"
] | null | null | Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ethe... | The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. | In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. | [
"4\nxxXx\n",
"2\nXX\n",
"6\nxXXxXx\n"
] | [
"1\nXxXx\n",
"1\nxX\n",
"0\nxXXxXx\n"
] | none | 500 | [
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "2\nXX",
"output": "1\nxX"
},
{
"input": "6\nxXXxXx",
"output": "0\nxXXxXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "22\nXXxXXxxXxXxXXXX... | 1,458,416,531 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 | import sys
import itertools
n, m = map(int, input('').split())
newlist = []
lst = list(map(int ,input().split()))
for i in range(1,n+1):
for combin in itertools.combinations(lst, i):
combin = list(combin)
if sum(combin) % m == 0 and combin != []:
print('YES')
... | Title: Squats
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to ... | ```python
import sys
import itertools
n, m = map(int, input('').split())
newlist = []
lst = list(map(int ,input().split()))
for i in range(1,n+1):
for combin in itertools.combinations(lst, i):
combin = list(combin)
if sum(combin) % m == 0 and combin != []:
print('YES')
... | -1 | |
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de... | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ... | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low... | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n????????... | 1,698,717,071 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | def go(i, pos):
cnt = 0
if i == len(t):
return int(pos == endpos)
if t[i] == '+':
cnt += go(i + 1, pos + 1)
elif t[i] == '-':
cnt += go(i + 1, pos - 1)
else:
cnt += go(i + 1, pos + 1)
cnt += go(i + 1, pos - 1)
return cnt
s = input()
t = in... | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go... | ```python
def go(i, pos):
cnt = 0
if i == len(t):
return int(pos == endpos)
if t[i] == '+':
cnt += go(i + 1, pos + 1)
elif t[i] == '-':
cnt += go(i + 1, pos - 1)
else:
cnt += go(i + 1, pos + 1)
cnt += go(i + 1, pos - 1)
return cnt
s = input... | 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.