contestId int64 0 1.01k | index stringclasses 40
values | name stringlengths 2 54 | type stringclasses 2
values | rating int64 0 3.4k | tags listlengths 0 7 | title stringclasses 393
values | time-limit stringclasses 7
values | memory-limit stringclasses 6
values | problem-description stringlengths 0 2.97k | input-specification stringlengths 4 1.87k | output-specification stringlengths 4 1.12k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 3.5k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 1
value | testset stringclasses 9
values | passedTestCount int64 1 402 | timeConsumedMillis int64 15 8.06k | memoryConsumedBytes int64 0 514M | code stringlengths 11 61.4k | prompt stringlengths 297 7.35k | response stringlengths 25 61.4k | score float64 2.82 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ... | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=105,<=1<=β€<=*k*<=β€<=109)Β β the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109)Β β the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
Ther... | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50... | 1,611,815,204 | 2,147,483,647 | PyPy 3 | OK | TESTS | 88 | 202 | 10,956,800 | import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
r=a[0]%k;t=0
for i in range(1,n):
if a[i]%k!=r:
print(-1)
break
else:
t+=(a[i]-a[0])//k
else:
print(t)
| Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o... | ```python
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
r=a[0]%k;t=0
for i in range(1,n):
if a[i]%k!=r:
print(-1)
break
else:
t+=(a[i]-a[0])//k
else:
print(t)
``` | 3 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=β€<=|*s*|<=β€<=50). The second line contains the string *t* (1<=β€<=|*t*|<=β€<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,677,513,194 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | input1=list(input())
instructions=list(input())
ans=1
counter1=0
counter2=0
for i in range(len(instructions)):
if instructions[counter1]==input1[counter2]:
ans+=1
counter2+=1
counter1+=1
print(ans) | 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
input1=list(input())
instructions=list(input())
ans=1
counter1=0
counter2=0
for i in range(len(instructions)):
if instructions[counter1]==input1[counter2]:
ans+=1
counter2+=1
counter1+=1
print(ans)
``` | 3 | |
552 | A | Vanya and Table | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of rectangles.
Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=β€<=*x*1<=β€<=*x*2<=β€<=100, 1<=β€<=*y*1<=β€<=*y*2<=β€<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *... | In a single line print the sum of all values in the cells of the table. | [
"2\n1 1 2 3\n2 2 3 3\n",
"2\n1 1 3 3\n1 1 3 3\n"
] | [
"10\n",
"18\n"
] | Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110
So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will ... | 500 | [
{
"input": "2\n1 1 2 3\n2 2 3 3",
"output": "10"
},
{
"input": "2\n1 1 3 3\n1 1 3 3",
"output": "18"
},
{
"input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13",
"output": "510"
},
{
"input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11",
"o... | 1,695,059,582 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 77 | 0 | def solve(x1, y1, x2, y2):
return sum((x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) for i in range(len(x1)))
def main():
n = int(input())
x1 = []
y1 = []
x2 = []
y2 = []
for _ in range(n):
x1_i, y1_i, x2_i, y2_i = map(int, input().split())
x1.append(x1_i)
... | Title: Vanya and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.
In this table, Vany... | ```python
def solve(x1, y1, x2, y2):
return sum((x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) for i in range(len(x1)))
def main():
n = int(input())
x1 = []
y1 = []
x2 = []
y2 = []
for _ in range(n):
x1_i, y1_i, x2_i, y2_i = map(int, input().split())
x1.append(x1... | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers β they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number β the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,684,257,177 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n = int(input())
m = list(map(int, input().split()))
hitler = 0
maxx = m[0]
minn = m[0]
for i in range(1, n):
if m[i] > maxx:
maxx = m[i]
hitler += 1
elif m[i] < minn:
minn = m[i]
hitler += 1
print(hitler)
| 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())
m = list(map(int, input().split()))
hitler = 0
maxx = m[0]
minn = m[0]
for i in range(1, n):
if m[i] > maxx:
maxx = m[i]
hitler += 1
elif m[i] < minn:
minn = m[i]
hitler += 1
print(hitler)
``` | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=β€<=*a*,<=*b*<=β€<=100) β the number of red and blue socks that Vasya's got. | Print two space-separated integers β the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,687,599,843 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 31 | 0 | a, b = input().split()
a, b = int(a), int(b)
print(f"{min(a, b)} {abs(a-b)//2}") | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a, b = input().split()
a, b = int(a), int(b)
print(f"{min(a, b)} {abs(a-b)//2}")
``` | 3 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,622,905,654 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 466 | 2,252,800 | from sys import *
import sys
from math import *
from collections import *
import string
import re
from bisect import *
from functools import reduce
from itertools import permutations, combinations
# import numpy as np
# def arr(): return np.random.randint(1,50,5)
t=stdin.readline
R=range
p=stdout.write
... | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
from sys import *
import sys
from math import *
from collections import *
import string
import re
from bisect import *
from functools import reduce
from itertools import permutations, combinations
# import numpy as np
# def arr(): return np.random.randint(1,50,5)
t=stdin.readline
R=range
p=std... | 3 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* β the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,695,137,693 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | s = str(input())
s1 = s.split('+')
print('+'.join(sorted(s1))) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
s = str(input())
s1 = s.split('+')
print('+'.join(sorted(s1)))
``` | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer β the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,995,058 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | #!/usr/bin/python3
n = int(input())
votes = []
for i in range(n):
a, b, c = [int(char) for char in input().split(" ")]
if sum([a, b, c]) >= 2:
votes.append(1)
print(len(votes))
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
#!/usr/bin/python3
n = int(input())
votes = []
for i in range(n):
a, b, c = [int(char) for char in input().split(" ")]
if sum([a, b, c]) >= 2:
votes.append(1)
print(len(votes))
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=β€<=*n*<=β€<=1000, 0<=β€<=*x*<=β€<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=β€<=*d**i*<=β€<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integersΒ β number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,675,424,104 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | x = list(map(int, input().split()))
s = 0
for i in range(x[0]):
y = list(map(str, input().split()))
y[1] = int(y[1])
if y[0] == '+':
x[1] = x[1] + y[1]
elif y[0] == '-':
if x[1] >= y[1]:
x[1] = x[1] - y[1]
else:
s = s+1
m = [str(x[1]),str... | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
x = list(map(int, input().split()))
s = 0
for i in range(x[0]):
y = list(map(str, input().split()))
y[1] = int(y[1])
if y[0] == '+':
x[1] = x[1] + y[1]
elif y[0] == '-':
if x[1] >= y[1]:
x[1] = x[1] - y[1]
else:
s = s+1
m = [str... | 3 | |
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | The first line of input contains string *s* containing lowercase English letters (1<=β€<=|*s*|<=β€<=1000).
The second line contains integer *k* (1<=β€<=*k*<=β€<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output"... | 1,600,822,233 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 140 | 0 |
n = input()
a = int(input())
if len(n)%a!=0:
print('NO')
else:
g = len(n)//a
p=0
if g%2==0:
for k in range(0,len(n),g):
u= n[k:k+g]
if u[:g//2]!=u[g//2:][::-1]:
print('NO')
p+=1
... | Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure ... | ```python
n = input()
a = int(input())
if len(n)%a!=0:
print('NO')
else:
g = len(n)//a
p=0
if g%2==0:
for k in range(0,len(n),g):
u= n[k:k+g]
if u[:g//2]!=u[g//2:][::-1]:
print('NO')
p+=1
... | 3 | |
259 | A | Little Elephant and Chess | PROGRAMMING | 1,000 | [
"brute force",
"strings"
] | null | null | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=Γ<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d... | The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the *j*-th character in the *i*-th line stands for the color of the *j*-th cell of the *i*-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black co... | In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. | [
"WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n",
"WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | 500 | [
{
"input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB",
"output": "YES"
},
{
"input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW",
"output": "NO"
},
{
"input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBW... | 1,664,383,513 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 92 | 0 | ans = 'YES'
for _ in range(8):
line = input()
for i in range(7):
if line[i] == line[i+1]:
ans = 'NO'
break
print(ans) | Title: Little Elephant and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=Γ<=8 checkered board, e... | ```python
ans = 'YES'
for _ in range(8):
line = input()
for i in range(7):
if line[i] == line[i+1]:
ans = 'NO'
break
print(ans)
``` | 3 | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=β€<=*n*<=β€<=100) β the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers β the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,506,868,091 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 124 | 204,800 | import math
n = int(input())
bags = int(math.pow(n,2))
#candies = math.factorial(bags)
n_bags = []
for j in range (n):
n_bags.append("")
for i in range(int(n/2)):
n_bags[j] += str((i*n)+j+1)
n_bags[j] += " "
n_bags[j] += str(bags-(j+(i*n)))
n_bags[j] += " "
#n_bags[j].append((i*n)+j+1)
#n_bags[j].appen... | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
import math
n = int(input())
bags = int(math.pow(n,2))
#candies = math.factorial(bags)
n_bags = []
for j in range (n):
n_bags.append("")
for i in range(int(n/2)):
n_bags[j] += str((i*n)+j+1)
n_bags[j] += " "
n_bags[j] += str(bags-(j+(i*n)))
n_bags[j] += " "
#n_bags[j].append((i*n)+j+1)
#n_bag... | 3 | |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=β€<=*n*<=β€<=2Β·105) β the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,561,187,507 | 2,147,483,647 | PyPy 3 | OK | TESTS | 67 | 202 | 14,540,800 | n = int(input())
l = list(map(int,input().split()))
k = l.count(1)
h = l.count(2)
if k>h:
print(h+(k-h)//3)
else:
print(k) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
n = int(input())
l = list(map(int,input().split()))
k = l.count(1)
h = l.count(2)
if k>h:
print(h+(k-h)//3)
else:
print(k)
``` | 3 | |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,527,923,037 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 93 | 7,065,600 | word = input()
if word == word[::-1]:
for i in range(len(word)):
slicedWord = word[i + 1:]
if slicedWord != slicedWord[::-1]:
print(len(word) - i - 1)
break
if len(slicedWord) == 0:
print(0)
break
else:
print(len(word)) | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
word = input()
if word == word[::-1]:
for i in range(len(word)):
slicedWord = word[i + 1:]
if slicedWord != slicedWord[::-1]:
print(len(word) - i - 1)
break
if len(slicedWord) == 0:
print(0)
break
else:
print(len(word... | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number β the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,699,752,063 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | s = input()
if len(s) == 2:
print(0)
else:
print(len(set(s[1:-1].split(', '))))
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
s = input()
if len(s) == 2:
print(0)
else:
print(len(set(s[1:-1].split(', '))))
``` | 3 | |
831 | A | Unimodal Array | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arra... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1<=000) β the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | 500 | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input":... | 1,651,685,616 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 46 | 0 | # -*- coding: utf-8 -*-
"""831.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1hYxPSks58iBj6lqO-ZFgsg_7bcRbm3l3
"""
#https://codeforces.com/contest/831/problem/A Unimodal Array
a=int(input())
b=list(map(int,input().split()))
i=1
while i<a and ... | Title: Unimodal Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may ... | ```python
# -*- coding: utf-8 -*-
"""831.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1hYxPSks58iBj6lqO-ZFgsg_7bcRbm3l3
"""
#https://codeforces.com/contest/831/problem/A Unimodal Array
a=int(input())
b=list(map(int,input().split()))
i=1
whil... | 3 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=β€<=*n*,<=*k*<=β€<=100). The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=109) β the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer β the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,589,023,440 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 186 | 6,656,000 | [n, k] = [int(x) for x in input().split()]
L = [x for x in input().split()]
c = 0
for i in L:
if i.count('4') + i.count('7') <= k: c += 1
print(c)
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
[n, k] = [int(x) for x in input().split()]
L = [x for x in input().split()]
c = 0
for i in L:
if i.count('4') + i.count('7') <= k: c += 1
print(c)
``` | 3 | |
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,694,688,779 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 78 | 13,209,600 | n = int(input())
li = list(map(int, input().split()))
c = 0
k = 0
for i in range(n):
if li[i] == -1 and c < 1:
k += 1
else:
c += li[i]
print(k)
"""
4
abacaba
acaba
abacaba
acab
""" | 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
n = int(input())
li = list(map(int, input().split()))
c = 0
k = 0
for i in range(n):
if li[i] == -1 and c < 1:
k += 1
else:
c += li[i]
print(k)
"""
4
abacaba
acaba
abacaba
acab
"""
``` | 3 | |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,492,357,420 | 520 | Python 3 | OK | TESTS | 63 | 77 | 5,529,600 | l=input()
s=[]
for i in l:
if(i=='V'):
s.append(1)
else:
s.append(0)
ls=len(s)
i=0
maxc = 0
c = 0
while i+1<ls:
if(s[i]==1 and s[i+1]==0):
c+=1
i+=1
maxc = max(maxc,c)
j=0
while j<ls:
if(s[j]==1):
s[j]=0
else:
s[j]=1
i=0
c=0
while i+1<ls:
if(s[i]==1 and s[i+1]==0):
c+=1... | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
l=input()
s=[]
for i in l:
if(i=='V'):
s.append(1)
else:
s.append(0)
ls=len(s)
i=0
maxc = 0
c = 0
while i+1<ls:
if(s[i]==1 and s[i+1]==0):
c+=1
i+=1
maxc = max(maxc,c)
j=0
while j<ls:
if(s[j]==1):
s[j]=0
else:
s[j]=1
i=0
c=0
while i+1<ls:
if(s[i]==1 and s[i+1]==0)... | 3 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,690,058,110 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 514 | 28,569,600 | n = int(input())
v = []
for i in range(n):
name = input()
v.append(name)
# v contains all names in the initial order
# now we have to process the list in reverse order
s = set() # should use set() for set
for i in range(n-1, -1, -1): # start from the last index, dec by 1, stop at -1
name = v[i]
if nam... | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
n = int(input())
v = []
for i in range(n):
name = input()
v.append(name)
# v contains all names in the initial order
# now we have to process the list in reverse order
s = set() # should use set() for set
for i in range(n-1, -1, -1): # start from the last index, dec by 1, stop at -1
name = v[i]... | 3 | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=β€<=*i*<=β€<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=β€<=*n*<=β€<=100,<=0<=β€<=*c*<=β€<=100), β the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=β€<=*x**i*<=β€<=100... | Print a single integer β the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,398,866,754 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 77 | 0 |
s = input().rstrip().split(' ')
n, c = int (s[0]), int(s[1])
x = input().rstrip().split(' ')
max = int (x[0]) - int (x[1]) - c
for i in range (1, n - 1):
if int (x[i]) - int (x[i + 1]) - c > max:
max = int (x[i]) - int (x[i+1]) - c
if max < 0:
max = 0
print (max)
| Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
s = input().rstrip().split(' ')
n, c = int (s[0]), int(s[1])
x = input().rstrip().split(' ')
max = int (x[0]) - int (x[1]) - c
for i in range (1, n - 1):
if int (x[i]) - int (x[i + 1]) - c > max:
max = int (x[i]) - int (x[i+1]) - c
if max < 0:
max = 0
print (max)
``` | 3 | |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number β the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,694,080,862 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | a=str(input(""))
b=0
f=-1
c=''
d=''
while a[f]!=" ":
d=a[f]+d
f=f-1
while a[b]!=" " :
c=c+a[b]
b=b+1
e=int(c)
g=int(d)
for i in range(0,g):
if e%10==0:
e=e/10
else:
e=e-1
print(int(e)) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
a=str(input(""))
b=0
f=-1
c=''
d=''
while a[f]!=" ":
d=a[f]+d
f=f-1
while a[b]!=" " :
c=c+a[b]
b=b+1
e=int(c)
g=int(d)
for i in range(0,g):
if e%10==0:
e=e/10
else:
e=e-1
print(int(e))
``` | 3 | |
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the p... | The input contains a single line, containing string *s* (1<=β€<=|*s*|<=<=β€<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"i... | 1,696,898,167 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 154 | 0 | import sys
input = sys.stdin.readline
from collections import Counter , defaultdict
def instr():
return input()[:-1]
import math
############################
w = instr()
c = Counter(w)
f = sum(x%2 != 0 for x in c.values())
if f == 0 :
print("First")
else :
print("First" if f%2 != 0 else "Sec... | Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The... | ```python
import sys
input = sys.stdin.readline
from collections import Counter , defaultdict
def instr():
return input()[:-1]
import math
############################
w = instr()
c = Counter(w)
f = sum(x%2 != 0 for x in c.values())
if f == 0 :
print("First")
else :
print("First" if f%2 != 0... | 3 | |
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | β I experienced so many great things.
β You gave me memories like dreams... But I have to leave now...
β One last request, can you...
β Help me solve a Codeforces problem?
β ......
β What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation with... | The first line contains two integers *k* and *p* (1<=β€<=*k*<=β€<=105,<=1<=β€<=*p*<=β€<=109). | Output single integerΒ β answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "7... | 1,607,101,986 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 171 | 2,150,400 | k, p = map(int, input().split())
res = 0
for i in range(1, k+1):
res += int(str(i)+(str(i)[::-1]))
res %= p
print(res) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
β I experienced so many great things.
β You gave me memories like dreams... But I have to leave now...
β One last request, can you...
β Help me solve a Codeforces problem?
β ......
β What?
Chtholly has been thi... | ```python
k, p = map(int, input().split())
res = 0
for i in range(1, k+1):
res += int(str(i)+(str(i)[::-1]))
res %= p
print(res)
``` | 3 | |
158 | B | Taxi | PROGRAMMING | 1,100 | [
"*special",
"greedy",
"implementation"
] | null | null | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=β€<=*s**i*<=β€<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers.... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=β€<=*s**i*<=β€<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group. | Print the single number β the minimum number of taxis necessary to drive all children to Polycarpus. | [
"5\n1 2 4 3 3\n",
"8\n2 3 4 4 2 1 3 1\n"
] | [
"4\n",
"5\n"
] | In the first test we can sort the children into four cars like this:
- the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly).
There a... | 1,000 | [
{
"input": "5\n1 2 4 3 3",
"output": "4"
},
{
"input": "8\n2 3 4 4 2 1 3 1",
"output": "5"
},
{
"input": "5\n4 4 4 4 4",
"output": "5"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "4\n3 ... | 1,696,672,999 | 2,147,483,647 | Python 3 | OK | TESTS | 105 | 156 | 3,481,600 | def min_taxis(groups):
counts = [groups.count(i) for i in range(1, 5)]
return counts[3] + counts[2] + (counts[1]*2 + max(0, counts[0] - counts[2]) + 3) // 4
# ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ
n = int(input())
groups = list(map(int, input().split()))
result = min_taxis(groups)
print(result)
| Title: Taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=β€<=*s**i*<=β€<=4), and they want to go to Polycarpu... | ```python
def min_taxis(groups):
counts = [groups.count(i) for i in range(1, 5)]
return counts[3] + counts[2] + (counts[1]*2 + max(0, counts[0] - counts[2]) + 3) // 4
# ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ
n = int(input())
groups = list(map(int, input().split()))
result = min_taxis(groups)
print(result)
``` | 3 | |
149 | C | Division into Teams | PROGRAMMING | 1,500 | [
"greedy",
"math",
"sortings"
] | null | null | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the ... | The first line contains the only integer *n* (2<=β€<=*n*<=β€<=105) which represents the number of guys in the yard. The next line contains *n* positive space-separated integers, *a**i* (1<=β€<=*a**i*<=β€<=104), the *i*-th number represents the *i*-th boy's playing skills. | On the first line print an integer *x* β the number of boys playing for the first team. On the second line print *x* integers β the individual numbers of boys playing for the first team. On the third line print an integer *y* β the number of boys playing for the second team, on the fourth line print *y* integers β the ... | [
"3\n1 2 1\n",
"5\n2 3 3 1 1\n"
] | [
"2\n1 2 \n1\n3 \n",
"3\n4 1 3 \n2\n5 2 \n"
] | Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2β-β1|β=β1ββ€β1) is fulfilled, th... | 1,500 | [
{
"input": "3\n1 2 1",
"output": "2\n1 2 \n1\n3 "
},
{
"input": "5\n2 3 3 1 1",
"output": "3\n4 1 3 \n2\n5 2 "
},
{
"input": "10\n2 2 2 2 2 2 2 1 2 2",
"output": "5\n8 2 4 6 9 \n5\n1 3 5 7 10 "
},
{
"input": "10\n2 3 3 1 3 1 1 1 2 2",
"output": "5\n4 7 1 10 3 \n5\n6 8 9 2... | 1,669,996,809 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 280 | 9,830,400 | n = int(input())
a = list(map(int,input().split()))
b = list(range(1,n+1))
z = sorted(list(zip(a,b)))
x = []
y = []
sx = 0
sy = 0
for i,j in z:
if sx<=sy:
x.append(j)
sx+=i
else:
y.append(j)
sy+=i
print(len(x))
print(*x)
print(len(y))
print(*y) | Title: Division into Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some... | ```python
n = int(input())
a = list(map(int,input().split()))
b = list(range(1,n+1))
z = sorted(list(zip(a,b)))
x = []
y = []
sx = 0
sy = 0
for i,j in z:
if sx<=sy:
x.append(j)
sx+=i
else:
y.append(j)
sy+=i
print(len(x))
print(*x)
print(len(y))
print(*y)
``` | 3 | |
436 | A | Feed with Candy | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.
One day, Om Nom visited his friend Evan. Evan has *n* candies of two types (fruit drops and caramel drops), the *i*-th candy hangs at the height of *h**i* centimeters ab... | The first line contains two integers, *n* and *x* (1<=β€<=*n*,<=*x*<=β€<=2000) β the number of sweets Evan has and the initial height of Om Nom's jump.
Each of the following *n* lines contains three integers *t**i*,<=*h**i*,<=*m**i* (0<=β€<=*t**i*<=β€<=1;Β 1<=β€<=*h**i*,<=*m**i*<=β€<=2000) β the type, height and the mass of... | Print a single integer β the maximum number of candies Om Nom can eat. | [
"5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5\n"
] | [
"4\n"
] | One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario:
1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3β+β4β=β7... | 1,000 | [
{
"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5",
"output": "4"
},
{
"input": "5 2\n1 15 2\n1 11 2\n0 17 2\n0 16 1\n1 18 2",
"output": "0"
},
{
"input": "6 2\n1 17 3\n1 6 1\n0 4 2\n1 10 1\n1 7 3\n1 5 1",
"output": "0"
},
{
"input": "7 2\n1 14 1\n1 9 2\n0 6 3\n0 20 2\n0 4... | 1,426,598,581 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 545 | 819,200 | from copy import deepcopy
def getBetter(h, a):
maxi = -1
im = -1
for i in range(len(a)):
if (h >= a[i][0]):
if (maxi < a[i][1]):
im = i
maxi = a[i][1]
return(im, maxi)
n, h0 = map(int, input().split())
lolipops0 = [[], []]
for i in ... | Title: Feed with Candy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.
One day, Om Nom visited his friend Evan. Evan has *n* candies of two... | ```python
from copy import deepcopy
def getBetter(h, a):
maxi = -1
im = -1
for i in range(len(a)):
if (h >= a[i][0]):
if (maxi < a[i][1]):
im = i
maxi = a[i][1]
return(im, maxi)
n, h0 = map(int, input().split())
lolipops0 = [[], []]
... | 3 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=β€<=*m*<=β€<=*n*<=β€<=100) β amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=β€<=*a**i*<=β€<=1000) β prices of the TV sets. | Output the only number β the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,687,679,840 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | #F
n, m = [int(x) for x in input().split()]
total = int(0)
a = [int(x) for x in input().split()]
a.sort()
for i in range(m):
if (a[i]<=0):
total+=a[i]
else :
break
print(total*-1)
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
#F
n, m = [int(x) for x in input().split()]
total = int(0)
a = [int(x) for x in input().split()]
a.sort()
for i in range(m):
if (a[i]<=0):
total+=a[i]
else :
break
print(total*-1)
``` | 3.977 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=Γ<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=β€<=<=*n*,<=*m*,<=*a*<=β€<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,695,700,468 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | n, m, a = map(int, input().split())
width_stones = -(-n // a)
length_stones = -(-m // a)
total_stones = width_stones * length_stones
print(total_stones) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = map(int, input().split())
width_stones = -(-n // a)
length_stones = -(-m // a)
total_stones = width_stones * length_stones
print(total_stones)
``` | 3.969 |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builderβs kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=β€<=*N*<=β€<=1000) β the number of bars at Vasyaβs disposal. The second line contains *N* space-separated integers *l**i* β the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers β the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,592,203,350 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 374 | 307,200 | n=int(input())
lst=list(map(int,input().split(' ')))
lstc={}
for i in range(n):
if(lst[i] in lstc.keys()):
continue
else:
count=0
for j in range(n):
if(lst[i]==lst[j]):
count+=1
lstc[lst[i]]=count
height=max(lstc.values())
print(he... | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builderβs kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n=int(input())
lst=list(map(int,input().split(' ')))
lstc={}
for i in range(n):
if(lst[i] in lstc.keys()):
continue
else:
count=0
for j in range(n):
if(lst[i]==lst[j]):
count+=1
lstc[lst[i]]=count
height=max(lstc.values())... | 3.905928 |
592 | A | PawnChess | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named Β«PawnChessΒ».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed... | The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the ... | Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board. | [
"........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n"
] | [
"A\n",
"B\n"
] | In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4,β5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner. | 500 | [
{
"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.",
"output": "B"
},
{
"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.",
"output": "A"
},
{
"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n......... | 1,489,420,890 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 109 | 23,142,400 | grid = []
for k in range(8):
grid.append(input())
bbc = [] #blocked black columns
bwc = [] #blocked white columns
#first processing : downwards
white = 8
for k in range(8):
for j in range(8):
if grid[k][j] == "B":
bbc.append(j)
if grid[k][j] == "W" and not j in bbc and white == 8... | Title: PawnChess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named Β«PawnChessΒ».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of ... | ```python
grid = []
for k in range(8):
grid.append(input())
bbc = [] #blocked black columns
bwc = [] #blocked white columns
#first processing : downwards
white = 8
for k in range(8):
for j in range(8):
if grid[k][j] == "B":
bbc.append(j)
if grid[k][j] == "W" and not j in bbc and ... | 3 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=β€<=*n*<=β€<=2000;Β 1<=β€<=*k*<=β€<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=β€<=*y**i*<=β€<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number β the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,658,973,787 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 1,843,200 | n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
for i in range(n):
arr[i] = (5-arr[i])-k
ans = 0
for i in range(n):
if arr[i] >=0:
ans += 1
print(ans//3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
for i in range(n):
arr[i] = (5-arr[i])-k
ans = 0
for i in range(n):
if arr[i] >=0:
ans += 1
print(ans//3)
``` | 3 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2Β·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100)Β β the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2Β·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integerΒ β the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,529,501,681 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 155 | 614,400 | n,m=list(map(int,input().split()))
c=0
for i in range(n):
l=list(map(int,input().split()))
for i in range(0,len(l),2):
if l[i]==0 and l[i+1]==1 or l[i]==1 and l[i+1]==1 or l[i]==1 and l[i+1]==0:
c+=1
i+=1
#i+=1
print(c) | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
n,m=list(map(int,input().split()))
c=0
for i in range(n):
l=list(map(int,input().split()))
for i in range(0,len(l),2):
if l[i]==0 and l[i+1]==1 or l[i]==1 and l[i+1]==1 or l[i]==1 and l[i+1]==0:
c+=1
i+=1
#i+=1
print(c)
``` | 3 | |
44 | C | Holidays | PROGRAMMING | 1,300 | [
"implementation"
] | C. Holidays | 2 | 256 | School holidays come in Berland. The holidays are going to continue for *n* days. The students of school β*N* are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people a... | The first input line contains two numbers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100) β the number of days in Berland holidays and the number of people in charge of the watering respectively. The next *m* lines contain the description of the duty schedule. Each line contains two integers *a**i* and *b**i* (1<=β€<=*a**i*<=β€<=*... | Print "OK" (without quotes), if the schedule does not contain mistakes. Otherwise you have to find the minimal number of a day when the flowers will not be watered or will be watered multiple times, and output two integers β the day number and the number of times the flowers will be watered that day. | [
"10 5\n1 2\n3 3\n4 6\n7 7\n8 10\n",
"10 5\n1 2\n2 3\n4 5\n7 8\n9 10\n",
"10 5\n1 2\n3 3\n5 7\n7 7\n7 10\n"
] | [
"OK\n",
"2 2\n",
"4 0\n"
] | Keep in mind that in the second sample the mistake occurs not only on the second day, but also on the sixth day, when nobody waters the flowers. However, you have to print the second day, i.e. the day with the minimal number. | 0 | [
{
"input": "10 5\n1 2\n3 3\n4 6\n7 7\n8 10",
"output": "OK"
},
{
"input": "10 5\n1 2\n2 3\n4 5\n7 8\n9 10",
"output": "2 2"
},
{
"input": "10 5\n1 2\n3 3\n5 7\n7 7\n7 10",
"output": "4 0"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n4 5",
"output": "OK"
},
{
"input": "100 5... | 1,563,266,875 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 310 | 0 | n,m = map(int,input().split())
Ln = [0]*n
while m!=0:
a,b = map(int,input().split())
for i in range(a,b+1):
Ln[i-1]+=1
m-=1
for i in range(0,len(Ln)):
if Ln[i]==0 :
print(i+1,0)
exit(0)
elif Ln[i]>1:
print(i+1,Ln[i])
exit(0)
print('OK')
exit(0)
... | Title: Holidays
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
School holidays come in Berland. The holidays are going to continue for *n* days. The students of school β*N* are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the ... | ```python
n,m = map(int,input().split())
Ln = [0]*n
while m!=0:
a,b = map(int,input().split())
for i in range(a,b+1):
Ln[i-1]+=1
m-=1
for i in range(0,len(Ln)):
if Ln[i]==0 :
print(i+1,0)
exit(0)
elif Ln[i]>1:
print(i+1,Ln[i])
exit(0)
print('OK')... | 3.9225 |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=β€<=*k*<=β€<=1000, 1<=β€<=*r*<=β€<=9)Β β the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9Β·117β=β1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,678,481,167 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 62 | 0 | inp = input().split()
inp = [int(x) for x in inp]
a=0
for i in range(15):
if(i>0):
if(inp[0]%10==0 or (inp[0]-inp[1])%10==0 or ((inp[0]*i)-inp[1])%10==0 or (inp[0]*i)%10==0):# :
a=i
break
print(a) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
inp = input().split()
inp = [int(x) for x in inp]
a=0
for i in range(15):
if(i>0):
if(inp[0]%10==0 or (inp[0]-inp[1])%10==0 or ((inp[0]*i)-inp[1])%10==0 or (inp[0]*i)%10==0):# :
a=i
break
print(a)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,570,801,198 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | s=input()
t=input()
x=0
if len(s)>len(t) or len(s)<len(t):
print('NO')
else:
for i in range(len(s)):
if s[i]==t[-i-1]:
x=x+1
if x==len(s):
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s=input()
t=input()
x=0
if len(s)>len(t) or len(s)<len(t):
print('NO')
else:
for i in range(len(s)):
if s[i]==t[-i-1]:
x=x+1
if x==len(s):
print('YES')
else:
print('NO')
``` | 3.9455 |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of lines in the description. Then follow *n* lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,684,592,469 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 186 | 0 | n = int(input())
d = {}
ans = ""
m = 0
for i in range(n):
s = input()
if s not in d:
d[s] = 0
d[s] += 1
if d[s] > m:
m = d[s]
ans = s
print(ans) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
d = {}
ans = ""
m = 0
for i in range(n):
s = input()
if s not in d:
d[s] = 0
d[s] += 1
if d[s] > m:
m = d[s]
ans = s
print(ans)
``` | 3.9535 |
127 | B | Canvas Frames | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=β€<=*a**i*<=β€<=100). | Print the single number β the maximum number of frames Nicholas can make for his future canvases. | [
"5\n2 4 3 2 3\n",
"13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n",
"4\n3 3 3 5\n"
] | [
"1",
"3",
"0"
] | none | 1,000 | [
{
"input": "5\n2 4 3 2 3",
"output": "1"
},
{
"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9",
"output": "3"
},
{
"input": "4\n3 3 3 5",
"output": "0"
},
{
"input": "2\n3 5",
"output": "0"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "14\... | 1,669,039,342 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 93 | 62 | 0 | import math
n = int(input())
sticks = list(map(int,input().split()))
sticks.sort()
pair = 0
count = 1
for index in range(len(sticks)-1):
if sticks[index] == sticks[index+1]:
count = count + 1
if index == len(sticks)-2:
pair = pair + math.floor(count/2)
else:
... | Title: Canvas Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin w... | ```python
import math
n = int(input())
sticks = list(map(int,input().split()))
sticks.sort()
pair = 0
count = 1
for index in range(len(sticks)-1):
if sticks[index] == sticks[index+1]:
count = count + 1
if index == len(sticks)-2:
pair = pair + math.floor(count/2)
el... | 3 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=β€<=*k*<=β€<=1000, 1<=β€<=*r*<=β€<=9)Β β the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9Β·117β=β1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,684,598,231 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | l = input()
list1 = l.split(" ")
k = int(list1[0])
r = int(list1[1])
count =0
sum = 0
flag = 0
while flag == 0 :
sum += k
count += 1
if sum%10 ==0 :
flag = 1
print (count)
else :
sum -= r
if sum % 10 == 0:
flag = 1
print(count)
... | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
l = input()
list1 = l.split(" ")
k = int(list1[0])
r = int(list1[1])
count =0
sum = 0
flag = 0
while flag == 0 :
sum += k
count += 1
if sum%10 ==0 :
flag = 1
print (count)
else :
sum -= r
if sum % 10 == 0:
flag = 1
print(... | 3 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$)Β β the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$)Β β the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,647,595,854 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | a=int(input())
gr=0
pu=0
bl=0
ore=0
r=0
y=0
p=0
for i in range(a):
v=input()
if v=='purple':
pu=v
p+=1
if v=='green':
gr=v
p+=1
if v=='blue':
bl=v
p+=1
if v=='orange':
ore=v
p+=1
if v=='red':
r=v
... | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
a=int(input())
gr=0
pu=0
bl=0
ore=0
r=0
y=0
p=0
for i in range(a):
v=input()
if v=='purple':
pu=v
p+=1
if v=='green':
gr=v
p+=1
if v=='blue':
bl=v
p+=1
if v=='orange':
ore=v
p+=1
if v=='red':
... | 3 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2Β·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100)Β β the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2Β·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integerΒ β the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,553,883,135 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 0 | # import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
l=list(map(int,input().split()))
n=l[0]
m=l[1]
count=0
for i in range(n):
p=list(map(int,input().split()))
for j in range(0,len(p)-1,2):
if(p[j]==1 or p[j+1]==1):
count+=1
print(count)
| Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
l=list(map(int,input().split()))
n=l[0]
m=l[1]
count=0
for i in range(n):
p=list(map(int,input().split()))
for j in range(0,len(p)-1,2):
if(p[j]==1 or p[j+1]==1):
count+=1
print(count)
``` | 3 | |
981 | C | Useful Decomposition | PROGRAMMING | 1,400 | [
"implementation",
"trees"
] | null | null | Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa... | The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$)Β β the edges of the tree. It is guaranteed that the given edges form a tree. | If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of ... | [
"4\n1 2\n2 3\n3 4\n",
"6\n1 2\n2 3\n3 4\n2 5\n3 6\n",
"5\n1 2\n1 3\n1 4\n1 5\n"
] | [
"Yes\n1\n1 4\n",
"No\n",
"Yes\n4\n1 2\n1 3\n1 4\n1 5\n"
] | The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see ... | 1,250 | [
{
"input": "4\n1 2\n2 3\n3 4",
"output": "Yes\n1\n1 4"
},
{
"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6",
"output": "No"
},
{
"input": "5\n1 2\n1 3\n1 4\n1 5",
"output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"
},
{
"input": "2\n1 2",
"output": "Yes\n1\n1 2"
},
{
"input": "8\n1 2\n1... | 1,527,435,141 | 2,541 | PyPy 3 | OK | TESTS | 47 | 936 | 9,420,800 | n = int(input())
orders = [0 for i in range(n)]
for i in range(n-1):
a, b = [int(j) -1 for j in input().split()]
orders[a] += 1
orders[b] += 1
roots = []
leafs = []
for i, x in enumerate(orders):
if x > 2:
roots.append(i)
elif x == 2:
pass
elif x == 1:
leafs.append(i)
... | Title: Useful Decomposition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
Th... | ```python
n = int(input())
orders = [0 for i in range(n)]
for i in range(n-1):
a, b = [int(j) -1 for j in input().split()]
orders[a] += 1
orders[b] += 1
roots = []
leafs = []
for i, x in enumerate(orders):
if x > 2:
roots.append(i)
elif x == 2:
pass
elif x == 1:
leafs.a... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line β the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,591,246,644 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 109 | 0 | def ultra(n,m):
ans=''
for i in range(len(n)):
if(n[i]==m[i]):
ans+='0'
else:
ans+='1'
return ans
if __name__ == "__main__":
n=input()
m=input()
print(ultra(n,m)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
def ultra(n,m):
ans=''
for i in range(len(n)):
if(n[i]==m[i]):
ans+='0'
else:
ans+='1'
return ans
if __name__ == "__main__":
n=input()
m=input()
print(ultra(n,m))
``` | 3.97275 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,674,719,877 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | t = list(input())
s = input()
i=0
j=len(t)-1
while(i<j):
t[i],t[j] = t[j],t[i]
i=i+1
j=j-1
x = "".join(t)
if(x==s):
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
t = list(input())
s = input()
i=0
j=len(t)-1
while(i<j):
t[i],t[j] = t[j],t[i]
i=i+1
j=j-1
x = "".join(t)
if(x==s):
print("YES")
else:
print("NO")
``` | 3.977 |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=β€<=*m*<=β€<=*n*<=β€<=100) β amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=β€<=*a**i*<=β€<=1000) β prices of the TV sets. | Output the only number β the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,663,424,934 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | n,m=list(map(int,input().split()))
lis=list(map(int,input().split()))
lis.sort()
sum=0
for i in range(m):
if(lis[i]<0):
sum=sum+lis[i]
print(abs(sum)) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n,m=list(map(int,input().split()))
lis=list(map(int,input().split()))
lis.sort()
sum=0
for i in range(m):
if(lis[i]<0):
sum=sum+lis[i]
print(abs(sum))
``` | 3.977 |
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,682,051,234 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | T = int(input())
i=0
while i<T:
word = input()
if(len(word)>10):
print(word[0],len(word)-2,word[-1],sep="")
else:
print(word)
i+=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
T = int(input())
i=0
while i<T:
word = input()
if(len(word)>10):
print(word[0],len(word)-2,word[-1],sep="")
else:
print(word)
i+=1
``` | 3.969 |
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | The first line contains two space-separated integers *n*,<=*v* (1<=β€<=*n*<=β€<=50;Β 104<=β€<=*v*<=β€<=106) β the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=β€<=*k**i*<=β€<=50) the number of items of the *i*-th seller. Then go *k**i* space... | In the first line, print integer *p* β the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=β€<=*q**i*<=β€<=*n*) β the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the... | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 100... | 1,585,640,870 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | a,b=map(int,input().split());k=[]
for i in range(1,a+1):
c,*d=map(int,input().split())
if min(d)<b:k+=[i]
print(len(k),"\n",*k)
| Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the... | ```python
a,b=map(int,input().split());k=[]
for i in range(1,a+1):
c,*d=map(int,input().split())
if min(d)<b:k+=[i]
print(len(k),"\n",*k)
``` | 3 | |
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T... | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=β€<=*n*<=β€<=100,<=0<=β€<=*P*1,<=*P*2,<=*P*3<=β€<=100,<=1<=β€<=*T*1,<=*T*2<=β€<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=β€<=*l**i*<=<... | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "5287... | 1,674,683,181 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | n, P1, P2, P3, T1, T2=map(int,input().split())
s=0
for i in range(n):
l,r=map(int,input().split())
if i==0:
t=l
if T1>=(l-t):
s+=(l-t)*P1
else:
s+=T1*P1
if T2>=(l-T1-t):
s+=(l-T1-t)*P2
else:
s+=T2*P2
s+=(l-T1-T2-t)... | Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f... | ```python
n, P1, P2, P3, T1, T2=map(int,input().split())
s=0
for i in range(n):
l,r=map(int,input().split())
if i==0:
t=l
if T1>=(l-t):
s+=(l-t)*P1
else:
s+=T1*P1
if T2>=(l-T1-t):
s+=(l-T1-t)*P2
else:
s+=T2*P2
s+=(... | 3.938 |
725 | B | Food on the Plane | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats... | The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=β€<=*n*<=β€<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. | Print one integerΒ β the number of seconds Vasya has to wait until he gets his lunch. | [
"1f\n",
"2d\n",
"4a\n",
"5e\n"
] | [
"1\n",
"10\n",
"11\n",
"18\n"
] | In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisl... | 1,000 | [
{
"input": "1f",
"output": "1"
},
{
"input": "2d",
"output": "10"
},
{
"input": "4a",
"output": "11"
},
{
"input": "5e",
"output": "18"
},
{
"input": "2c",
"output": "13"
},
{
"input": "1b",
"output": "5"
},
{
"input": "1000000000000000000d... | 1,610,378,357 | 2,147,483,647 | Python 3 | OK | TESTS | 119 | 77 | 0 | c=input();n,s,d=int(c[:-1]),c[-1],{'a':4,'b':5,'c':6,'d':3,'e':2,'f':1}
x=(n//4*2+(n-1)%2-2*(n%4==0))*6+d[s]+n
print(x-1 if (n-1)%4<2 else x-3) | Title: Food on the Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' ... | ```python
c=input();n,s,d=int(c[:-1]),c[-1],{'a':4,'b':5,'c':6,'d':3,'e':2,'f':1}
x=(n//4*2+(n-1)%2-2*(n%4==0))*6+d[s]+n
print(x-1 if (n-1)%4<2 else x-3)
``` | 3 | |
574 | A | Bear and Elections | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elect... | The first line contains single integer *n* (2<=β€<=*n*<=β€<=100) - number of candidates.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate ... | Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. | [
"5\n5 1 11 2 8\n",
"4\n1 8 8 8\n",
"2\n7 6\n"
] | [
"4\n",
"6\n",
"0\n"
] | In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9,β1,β7,β2,β8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate ... | 500 | [
{
"input": "5\n5 1 11 2 8",
"output": "4"
},
{
"input": "4\n1 8 8 8",
"output": "6"
},
{
"input": "2\n7 6",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "10\n100 200 57 99 1 1000 200 200 200 500",
"output": "451"
},
{
"input": "16\... | 1,665,167,303 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 1,740,800 | n=int(input())
arr=list(map(int,input().split()))
t=ans=arr.pop(0)
mx=max(arr)
i=1
while (ans)<=mx:
ans+=1
arr.remove(mx)
arr.append(mx-1)
mx=max(arr)
print(ans-t) | Title: Bear and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for e... | ```python
n=int(input())
arr=list(map(int,input().split()))
t=ans=arr.pop(0)
mx=max(arr)
i=1
while (ans)<=mx:
ans+=1
arr.remove(mx)
arr.append(mx-1)
mx=max(arr)
print(ans-t)
``` | 3 | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=β€<=*n*<=β€<=50) β the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer β the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,695,229,318 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n = input()
n = int(n)
stones = input()
ans = 0
for i in range(1, n):
if stones[i] == stones[i-1]:
ans = ans + 1
print(ans)
| Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
n = input()
n = int(n)
stones = input()
ans = 0
for i in range(1, n):
if stones[i] == stones[i-1]:
ans = ans + 1
print(ans)
``` | 3 | |
792 | B | Counting-out Rhyme | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T... | The first line contains two integer numbers *n* and *k* (2<=β€<=*n*<=β€<=100, 1<=β€<=*k*<=β€<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=β€<=*a**i*<=β€<=109). | Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step. | [
"7 5\n10 4 11 4 1\n",
"3 2\n2 5\n"
] | [
"4 2 5 6 1 \n",
"3 2 \n"
] | Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader... | 0 | [
{
"input": "7 5\n10 4 11 4 1",
"output": "4 2 5 6 1 "
},
{
"input": "3 2\n2 5",
"output": "3 2 "
},
{
"input": "2 1\n1",
"output": "2 "
},
{
"input": "2 1\n2",
"output": "1 "
},
{
"input": "2 1\n3",
"output": "2 "
},
{
"input": "10 7\n5 10 4 3 8 10 6",... | 1,637,303,391 | 291 | PyPy 3-64 | OK | TESTS | 22 | 62 | 0 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
l = sorted(list(range(1, n+1)))
c = 0
t = []
for i in [int(j) for j in input().split()]:
c = (c+i)%len(l)
t.append(l[c])
l = l[:c]+l[c+1:]
print(*t)
| Title: Counting-out Rhyme
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In ... | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
l = sorted(list(range(1, n+1)))
c = 0
t = []
for i in [int(j) for j in input().split()]:
c = (c+i)%len(l)
t.append(l[c])
l = l[:c]+l[c+1:]
print(*t)
``` | 3 | |
412 | A | Poster | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a l... | The first line contains two integers, *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=100) β the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or di... | In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th ac... | [
"2 2\nR1\n",
"2 1\nR1\n",
"6 4\nGO?GO!\n"
] | [
"PRINT 1\nLEFT\nPRINT R\n",
"PRINT R\nRIGHT\nPRINT 1\n",
"RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n"
] | Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | 500 | [
{
"input": "2 2\nR1",
"output": "PRINT 1\nLEFT\nPRINT R"
},
{
"input": "2 1\nR1",
"output": "PRINT R\nRIGHT\nPRINT 1"
},
{
"input": "6 4\nGO?GO!",
"output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"
},
{
"input": "7 3\n... | 1,397,838,629 | 1,229 | Python 3 | OK | TESTS | 43 | 62 | 0 | n,k=map(int,input('').split())
lozung=list(input())
if n-k<k:
for i in range(k,n):
print('RIGHT')
for i in reversed(range(0,n)):
print ('PRINT ',lozung[i])
if i!=0:print('LEFT')
else:
# print('2')
for i in reversed(range(0,k-1)):
print('LEFT')... | Title: Poster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the... | ```python
n,k=map(int,input('').split())
lozung=list(input())
if n-k<k:
for i in range(k,n):
print('RIGHT')
for i in reversed(range(0,n)):
print ('PRINT ',lozung[i])
if i!=0:print('LEFT')
else:
# print('2')
for i in reversed(range(0,k-1)):
pri... | 3 | |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,697,015,876 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | n=int(input())
ch=input()
m=0
letter='abcdefghijklmnopqrstuvwxyz'
for i in letter:
if i not in ch.lower():
m=1
if m==1:
print("No")
else:
print("Yes")
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
n=int(input())
ch=input()
m=0
letter='abcdefghijklmnopqrstuvwxyz'
for i in letter:
if i not in ch.lower():
m=1
if m==1:
print("No")
else:
print("Yes")
``` | 3 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=β€<=*n*<=β€<=50) β the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* β the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4ββ β7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,568,028,194 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 218 | 0 | import sys
n = int(input())
s = input()
i = 0
for ch in s:
if(ch != '4' and ch != '7'):
print('NO')
sys.exit(0)
n = int(n/2)
if(sum(map(int,s[:n])) == sum(map(int, s[-n:]))):
print("YES")
else:
print('NO')
| Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
import sys
n = int(input())
s = input()
i = 0
for ch in s:
if(ch != '4' and ch != '7'):
print('NO')
sys.exit(0)
n = int(n/2)
if(sum(map(int,s[:n])) == sum(map(int, s[-n:]))):
print("YES")
else:
print('NO')
``` | 3 | |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=β€<=*n*,<=*t*<=β€<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,698,452,541 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | q, r = map(int, input().split())
t1 = input()
t = []
for o in t1:
t.append(o)
for j in range(r):
i = 0
while i < len(t)-1:
if t[i] == 'B' and t[i + 1] == 'G':
t[i], t[i + 1] = t[i + 1], t[i]
i += 2
else:
i += 1
t1 = ''.join(t)
print(t1)
| Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
q, r = map(int, input().split())
t1 = input()
t = []
for o in t1:
t.append(o)
for j in range(r):
i = 0
while i < len(t)-1:
if t[i] == 'B' and t[i + 1] == 'G':
t[i], t[i + 1] = t[i + 1], t[i]
i += 2
else:
i += 1
t1 = ''.join(t)
print... | 3 | |
912 | B | New Year's Eve | PROGRAMMING | 1,300 | [
"bitmasks",
"constructive algorithms",
"number theory"
] | null | null | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a d... | The sole string contains two integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=1018). | Output one numberΒ β the largest possible xor-sum. | [
"4 3\n",
"6 6\n"
] | [
"7\n",
"7\n"
] | In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | 1,000 | [
{
"input": "4 3",
"output": "7"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "1022 10",
"output": "1023"
},
{
"input": "415853337373441 52",
"output": "562949953421311"
},
{
"input": "75 12",
"output": "127"
... | 1,516,725,943 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 77 | 5,632,000 | n , k = map(int , input().split())
l = list(bin(n))[2:]
if k == 1: print(n)
else:
print ((1 << len(l)) -1)
| Title: New Year's Eve
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co... | ```python
n , k = map(int , input().split())
l = list(bin(n))[2:]
if k == 1: print(n)
else:
print ((1 << len(l)) -1)
``` | 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,673,285,663 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | teams = int(input())
homeKit = [None] * teams
guestKit = [None] * teams
for i in range(teams):
homeKit[i], guestKit[i] = map(int, input().split())
guestUni = 0
for i in range(teams):
for j in range(teams):
if i == j:
continue
if homeKit[i] == guestKit[j]:
guestUni += 1
print(guestUni)
... | 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
teams = int(input())
homeKit = [None] * teams
guestKit = [None] * teams
for i in range(teams):
homeKit[i], guestKit[i] = map(int, input().split())
guestUni = 0
for i in range(teams):
for j in range(teams):
if i == j:
continue
if homeKit[i] == guestKit[j]:
guestUni += 1
print(guestUni)
... | 3 | |
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy ... | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) β the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the inp... | Print a single integer β the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti... | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n... | 1,555,662,827 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 124 | 307,200 | def main():
[n_games, n_bills] = [int(_) for _ in input().split()]
game_prices = [0] + [int(_) for _ in input().split()]
bills = [0] + [int(_) for _ in input().split()]
last_game = 0
last_bill = 0
count_games_bought = 0
while last_game < n_games and last_bill < n_bills:
last_bill +... | Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ... | ```python
def main():
[n_games, n_bills] = [int(_) for _ in input().split()]
game_prices = [0] + [int(_) for _ in input().split()]
bills = [0] + [int(_) for _ in input().split()]
last_game = 0
last_bill = 0
count_games_bought = 0
while last_game < n_games and last_bill < n_bills:
l... | 3 | |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,695,174,378 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | a = input().lower()
b = input().lower()
abi = True
for i in range(len(a)):
if a[i] > b[i]:
print('1')
abi = False
break
elif a[i] < b[i]:
print('-1')
abi = False
break
if abi:
print('0')
| Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
a = input().lower()
b = input().lower()
abi = True
for i in range(len(a)):
if a[i] > b[i]:
print('1')
abi = False
break
elif a[i] < b[i]:
print('-1')
abi = False
break
if abi:
print('0')
``` | 3.977 |
847 | M | Weather Tomorrow | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where... | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=100) β the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=β€<=*t**i*<=β€<=1000)Β β where *t**i* is the average temperature in the *i*-th day. | Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000. | [
"5\n10 5 0 -5 -10\n",
"4\n1 1 1 1\n",
"3\n5 1 -5\n",
"2\n900 1000\n"
] | [
"-15\n",
"1\n",
"-5\n",
"1100\n"
] | In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is β-β10β-β5β=ββ-β15.
In the second example the sequence of the average temperatures is an arithmetic pro... | 0 | [
{
"input": "5\n10 5 0 -5 -10",
"output": "-15"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "3\n5 1 -5",
"output": "-5"
},
{
"input": "2\n900 1000",
"output": "1100"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 5 8",
"output... | 1,680,878,020 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | n = int(input())
vals = list(map(int,(input().split())))
arith = True
diff = vals[0]-vals[1]
for i in range(n-1):
if vals[i]-vals[i+1]!=diff:
arith = False
break
if arith:
print(vals[-1]-diff)
else:
print(vals[-1]) | Title: Weather Tomorrow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya ... | ```python
n = int(input())
vals = list(map(int,(input().split())))
arith = True
diff = vals[0]-vals[1]
for i in range(n-1):
if vals[i]-vals[i+1]!=diff:
arith = False
break
if arith:
print(vals[-1]-diff)
else:
print(vals[-1])
``` | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=β€<=*n*<=β€<=100) β the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=100) β the number of cookies in the *i*-th bag. | Print in the only line the only number β the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies β 5β+β3β=β8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,638,820,906 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 122 | 0 | n=int(input())
l=list(map(int,input().split()))
Sum=sum(l)
if(Sum%2==0):
print(len([i for i in l if i%2==0]))
else:
print(len([i for i in l if(i%2==1)]))
| Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n=int(input())
l=list(map(int,input().split()))
Sum=sum(l)
if(Sum%2==0):
print(len([i for i in l if i%2==0]))
else:
print(len([i for i in l if(i%2==1)]))
``` | 3 | |
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=β€<=*a*<=β€<=35).
Output a single integer. | The input contains a single integer *a* (0<=β€<=*a*<=β€<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output... | 1,496,787,250 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 0 | if __name__ == "__main__":
a = [1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
4096,
8092,
16184,
32368,
64736,
129472,
258944,
517888,
1035776,
2071552,
4143104,
8286208,
16572416,
33144832,
66289664,
132579328,
265158656,
530317312,
1060634624,
21212... | Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=β€<=*a*<=β€<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=β€<=*a*<=β€<=35).
Output Specification:
Output a single integer.
De... | ```python
if __name__ == "__main__":
a = [1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
4096,
8092,
16184,
32368,
64736,
129472,
258944,
517888,
1035776,
2071552,
4143104,
8286208,
16572416,
33144832,
66289664,
132579328,
265158656,
530317312,
106063462... | 3 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=β€<=*n*<=β€<=100) β the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string β the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,694,614,508 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 46 | 0 | def solve():
size = input()
s = input()
print('1' * ('1' in s) + '0' * s.count('0'))
if __name__ == "__main__":
solve()
| Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
def solve():
size = input()
s = input()
print('1' * ('1' in s) + '0' * s.count('0'))
if __name__ == "__main__":
solve()
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road networkΒ β for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to... | The first line of the input contains two integers *n* and *m* (2<=β€<=*n*<=β€<=400, 0<=β€<=*m*<=β€<=*n*(*n*<=-<=1)<=/<=2)Β β the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=β€<=*u*,<=*v*<=β€<=*n*, *u*<=... | Output one integerΒ β the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. | [
"4 2\n1 3\n3 4\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n"
] | [
"2\n",
"-1\n",
"3\n"
] | In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codefo... | 0 | [
{
"input": "4 2\n1 3\n3 4",
"output": "2"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "-1"
},
{
"input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2",
"output": "3"
},
{
"input": "5 4\n1 2\n3 2\n3 4\n5 4",
"output": "4"
},
{
"input": "3 1\n1 2",
"output": "... | 1,697,337,545 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 59 | 482 | 8,192,000 | n, m = map(int, input().split())
a = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
u, v = map(int, input().split())
a[u][v] = 1
a[v][u] = 1
def bfs(x):
fila = [(1, 0)]
visitados = [0] * (n + 1)
while fila:
u, v = fila.pop(0)
for i in range(1, n + 1):... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road networkΒ β for each pair of different towns *x* and *y*, there is a bidirectional road between towns... | ```python
n, m = map(int, input().split())
a = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
u, v = map(int, input().split())
a[u][v] = 1
a[v][u] = 1
def bfs(x):
fila = [(1, 0)]
visitados = [0] * (n + 1)
while fila:
u, v = fila.pop(0)
for i in range(... | 3 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=β€<=*r*<=β€<=105, <=-<=105<=β€<=*x*,<=*y*,<=*x*',<=*y*'<=β€<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer β minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0,β2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,558,280,225 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | import math
r, x, y, x1, y1 = map(int, input().split())
print(math.ceil(math.sqrt((x-x1)**2 + (y-y1)**2)/(2*r)))
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
import math
r, x, y, x1, y1 = map(int, input().split())
print(math.ceil(math.sqrt((x-x1)**2 + (y-y1)**2)/(2*r)))
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=β€<=*n*<=β€<=1000, 0<=β€<=*x*<=β€<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=β€<=*d**i*<=β€<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integersΒ β number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,595,099,463 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 6,758,400 |
n,x = map(int,input().split())
count=0
for _ in range(n):
c,v = input().split()
v=int(v)
if(c=='+'):
x=x+v
if(c=='-'):
if(v<=x):
x=x-v
else:
count += 1
print(x,count) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
n,x = map(int,input().split())
count=0
for _ in range(n):
c,v = input().split()
v=int(v)
if(c=='+'):
x=x+v
if(c=='-'):
if(v<=x):
x=x-v
else:
count += 1
print(x,count)
``` | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer β the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,712,626 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n = int(input())
count = 0
for i in range(n):
m = list(map(int,input().split()))
k = m.count(1)
if k >= 2:
count += 1
print(count) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input())
count = 0
for i in range(n):
m = list(map(int,input().split()))
k = m.count(1)
if k >= 2:
count += 1
print(count)
``` | 3 | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=β€<=*a*,<=*b*<=β€<=109). The second line contains one integer *n*, the number of queries (1<=β€<=*n*<=β€<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=β€<=*low*<=β€<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,539,538,075 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 592 | 614,400 | def gcd(a,b):
while a>0:
x=a
a=b%a
b=x
return(x)
def Bsearch1(L,x):
beg=0
last=len(L)-1
while beg<=last:
mid=(beg+last)//2
if x==L[mid]:
return(mid)
elif(x>L[mid]):
beg=mid+1
else:
last=mid-1
... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
def gcd(a,b):
while a>0:
x=a
a=b%a
b=x
return(x)
def Bsearch1(L,x):
beg=0
last=len(L)-1
while beg<=last:
mid=(beg+last)//2
if x==L[mid]:
return(mid)
elif(x>L[mid]):
beg=mid+1
else:
l... | 3.850856 |
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,678,625,050 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | def stringcheck(s):
word="hello"
req="h"
c=0
for ch in s:
if c==5:
break
if ch==req:
c+=1
if c<5:
req=word[c]
if c==5:
print("YES")
else:
print("NO")
s=input()
stringcheck(s) | 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
def stringcheck(s):
word="hello"
req="h"
c=0
for ch in s:
if c==5:
break
if ch==req:
c+=1
if c<5:
req=word[c]
if c==5:
print("YES")
else:
print("NO")
s=input()
stringch... | 3.969 |
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=β€<=|*s*|<=β€<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=β€<=*k*<=β€<=26). | Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*',β'*h*',β'*o*',β'*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for... | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhe... | 1,503,595,172 | 2,672 | Python 3 | OK | TESTS | 41 | 77 | 0 | s = input()
x = int(input())
if x > len(s):
print('impossible')
elif x < len(set(s)):
print(0)
else:
print(x - len(set(s))) | Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it... | ```python
s = input()
x = int(input())
if x > len(s):
print('impossible')
elif x < len(set(s)):
print(0)
else:
print(x - len(set(s)))
``` | 3 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=β€<=|*s*|<=β€<=50). The second line contains the string *t* (1<=β€<=|*t*|<=β€<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,688,667,351 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 19 | 124 | 0 | s = input()
t = input()
count=1
si=0
for i in range(len(t)):
if t[i] == s[si]:
count+=1
si+=1
print(count) | 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=1
si=0
for i in range(len(t)):
if t[i] == s[si]:
count+=1
si+=1
print(count)
``` | 3 | |
137 | C | History | PROGRAMMING | 1,500 | [
"sortings"
] | null | null | Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the Wo... | The first input line contains integer *n* (1<=β€<=*n*<=β€<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=β€<=*a**i*<=<<=*b**i*<=β€<=109) β the beginning and the end of the *i*-th... | Print the only integer β the answer to the problem. | [
"5\n1 10\n2 9\n3 8\n4 7\n5 6\n",
"5\n1 100\n2 50\n51 99\n52 98\n10 60\n",
"1\n1 1000000000\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third β in the second and the second β in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | 1,500 | [
{
"input": "5\n1 10\n2 9\n3 8\n4 7\n5 6",
"output": "4"
},
{
"input": "5\n1 100\n2 50\n51 99\n52 98\n10 60",
"output": "4"
},
{
"input": "1\n1 1000000000",
"output": "0"
},
{
"input": "2\n100 1000\n500 1500",
"output": "0"
},
{
"input": "4\n1 100\n50 150\n120 200\... | 1,588,083,198 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 872 | 78,950,400 | import sys
from math import log2,floor,ceil,sqrt,gcd
import bisect
# from collections import deque
sys.setrecursionlimit(10**5)
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return... | Title: History
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other ... | ```python
import sys
from math import log2,floor,ceil,sqrt,gcd
import bisect
# from collections import deque
sys.setrecursionlimit(10**5)
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, ... | 3 | |
520 | B | Two Buttons | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs",
"greedy",
"implementation",
"math",
"shortest paths"
] | null | null | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | The first and the only line of the input contains two distinct integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=104), separated by a space . | Print a single number β the minimum number of times one needs to push the button required to get the number *m* out of number *n*. | [
"4 6\n",
"10 1\n"
] | [
"2\n",
"9\n"
] | In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times. | 1,000 | [
{
"input": "4 6",
"output": "2"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "2 10",
"outpu... | 1,698,290,071 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 61 | 1,228,800 | from collections import deque
n, m = map(int, input().split())
queue = deque([(n, 0)])
visited = set()
while queue:
current, clicks = queue.popleft()
if current == m:
print(clicks)
break
if current * 2 not in visited and current * 2 <= 10**4:
queue.append((cur... | Title: Two Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by t... | ```python
from collections import deque
n, m = map(int, input().split())
queue = deque([(n, 0)])
visited = set()
while queue:
current, clicks = queue.popleft()
if current == m:
print(clicks)
break
if current * 2 not in visited and current * 2 <= 10**4:
queue.a... | 3 | |
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | The first line contains two integers *x*,<=*y* (<=-<=109<=β€<=*x*,<=*y*<=β€<=109,<=*x*<=β <=0,<=*y*<=β <=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 β the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-... | 1,602,661,831 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 186 | 0 | n=input().split()
x,y=int(n[0]),int(n[1])
if x>0 and y>0:
print(0,x+y,x+y,0)
elif x>0 and y<0:
print(0,y-x,x-y,0)
elif x<0 and y>0:
print(x-y,0,0,y-x)
else:
print(x+y,0,0,x+y) | Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ... | ```python
n=input().split()
x,y=int(n[0]),int(n[1])
if x>0 and y>0:
print(0,x+y,x+y,0)
elif x>0 and y<0:
print(0,y-x,x-y,0)
elif x<0 and y>0:
print(x-y,0,0,y-x)
else:
print(x+y,0,0,x+y)
``` | 3 | |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | The first line contains two integers *n* and *x* (1<=β€<=*n*<=β€<=100, 0<=β€<=*x*<=β€<=100)Β β the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integerΒ β the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
... | 1,671,815,291 | 191 | PyPy 3 | OK | TESTS | 39 | 93 | 0 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, x = map(int, input().split())
a = list(map(int, input().split()))
l = 105
cnt = [0] * l
for i in a:
cnt[i] += 1
ans = 0
for i in range(x):
if not cnt[i]:
ans += 1
ans += cnt[x]
print(ans) | Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in ... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, x = map(int, input().split())
a = list(map(int, input().split()))
l = 105
cnt = [0] * l
for i in a:
cnt[i] += 1
ans = 0
for i in range(x):
if not cnt[i]:
ans += 1
ans += cnt[x]
print(ans)
``` | 3 | |
327 | A | Flipping Game | PROGRAMMING | 1,200 | [
"brute force",
"dp",
"implementation"
] | null | null | Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=β€<=*i*<=β€<=*j*<=β€<=*n*) and flips all values *a**k* for which their positions are in... | The first line of the input contains an integer *n* (1<=β€<=*n*<=β€<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. | Print an integer β the maximal number of 1s that can be obtained after exactly one move. | [
"5\n1 0 0 1 0\n",
"4\n1 0 0 1\n"
] | [
"4\n",
"4\n"
] | In the first case, flip the segment from 2 to 5 (*i*β=β2,β*j*β=β5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].
In the second case, flipping only the second and the third element (*i*β=β2,β*j*β=β3) will turn all nu... | 500 | [
{
"input": "5\n1 0 0 1 0",
"output": "4"
},
{
"input": "4\n1 0 0 1",
"output": "4"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "8\n1 0 0 0 1 0 0 0",
"output": "7"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... | 1,692,787,446 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 154 | 1,740,800 | n = int(input())
a = list(map(int, input().split()))
max_ones = 0
for i in range(n):
for j in range(i, n):
temp = a.copy()
for k in range(i, j+1):
temp[k] = 1 - temp[k]
max_ones = max(max_ones, temp.count(1))
print(max_ones)
| Title: Flipping Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *... | ```python
n = int(input())
a = list(map(int, input().split()))
max_ones = 0
for i in range(n):
for j in range(i, n):
temp = a.copy()
for k in range(i, j+1):
temp[k] = 1 - temp[k]
max_ones = max(max_ones, temp.count(1))
print(max_ones)
``` | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,591,859,419 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | n = int(input())
l = list(map(int,input().split()))
if n<3:
if n%2==0:
if sum(l)%2==0:
print(3)
else:
print(2)
else:
if sum(l)%2==0:
print(2)
else:
print(3)
else:
mod = sum(l)%(n+1)
mod = n+1-mod
if mod>=... | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())
l = list(map(int,input().split()))
if n<3:
if n%2==0:
if sum(l)%2==0:
print(3)
else:
print(2)
else:
if sum(l)%2==0:
print(2)
else:
print(3)
else:
mod = sum(l)%(n+1)
mod = n+1-mod
... | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=β€<=*x**i*,<=*y**i*,<=*z**i*<=β€<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,537,700,196 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 0 | n = int(input())
xs, ys, zs = 0, 0, 0
for i in range(n):
l = [int(k) for k in input().split(' ')]
x, y, z = l[0], l[1], l[2]
xs, ys, zs = xs+x, ys+y, zs+z
if (xs==0) and (ys==0) and (zs==0):
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
xs, ys, zs = 0, 0, 0
for i in range(n):
l = [int(k) for k in input().split(' ')]
x, y, z = l[0], l[1], l[2]
xs, ys, zs = xs+x, ys+y, zs+z
if (xs==0) and (ys==0) and (zs==0):
print('YES')
else:
print('NO')
``` | 3.938 |
336 | B | Vasily the Bear and Fly | PROGRAMMING | 1,900 | [
"math"
] | null | null | One beautiful day Vasily the bear painted 2*m* circles of the same radius *R* on a coordinate plane. Circles with numbers from 1 to *m* had centers at points (2*R*<=-<=*R*,<=0), (4*R*<=-<=*R*,<=0), ..., (2*Rm*<=-<=*R*,<=0), respectively. Circles with numbers from *m*<=+<=1 to 2*m* had centers at points (2*R*<=-<=*R*,<=... | The first line contains two integers *m*,<=*R* (1<=β€<=*m*<=β€<=105, 1<=β€<=*R*<=β€<=10). | In a single line print a single real number β the answer to the problem. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"1 1\n",
"2 2\n"
] | [
"2.0000000000\n",
"5.4142135624\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/9fe384073741e20965ddc4bf162afd3a604b6b39.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the second sample | 1,000 | [
{
"input": "1 1",
"output": "2.0000000000"
},
{
"input": "2 2",
"output": "5.4142135624"
},
{
"input": "100000 3",
"output": "200002.4853316681"
},
{
"input": "2344 5",
"output": "7817.4790439982"
},
{
"input": "999 10",
"output": "6668.3010410807"
},
{
... | 1,377,735,208 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 686 | 0 | import math
m,R = map (int,input().split())
D = math.sqrt (2) * R
result = 0
def sum_dist (n):
return n*(n+1)*R + 2*D*n
for i in range (1,m+1):
result += 2*R
if i-1 > 0: result += 2*R + D
if m-i > 0: result += 2*R + D
if i-2 > 0: result += sum_dist (i-2)
if m-i-1 > 0: result += sum_dist (m-i-1)
p... | Title: Vasily the Bear and Fly
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One beautiful day Vasily the bear painted 2*m* circles of the same radius *R* on a coordinate plane. Circles with numbers from 1 to *m* had centers at points (2*R*<=-<=*R*,<=0), (4*R*<=-<=*R*,<=0), ..., (2*Rm*<=... | ```python
import math
m,R = map (int,input().split())
D = math.sqrt (2) * R
result = 0
def sum_dist (n):
return n*(n+1)*R + 2*D*n
for i in range (1,m+1):
result += 2*R
if i-1 > 0: result += 2*R + D
if m-i > 0: result += 2*R + D
if i-2 > 0: result += sum_dist (i-2)
if m-i-1 > 0: result += sum_dist ... | 3 | |
427 | B | Prison Transfer | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city.
For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of th... | The first line of input will contain three space separated integers *n*Β (1<=β€<=*n*<=β€<=2Β·105), *t*Β (0<=β€<=*t*<=β€<=109) and *c*Β (1<=β€<=*c*<=β€<=*n*). The next line will contain *n* space separated integers, the *i**th* integer is the severity *i**th* prisoner's crime. The value of crime severities will be non-negative an... | Print a single integer β the number of ways you can choose the *c* prisoners. | [
"4 3 3\n2 3 1 1\n",
"1 1 1\n2\n",
"11 4 2\n2 2 0 7 3 2 2 4 9 1 4\n"
] | [
"2\n",
"0\n",
"6\n"
] | none | 1,000 | [
{
"input": "4 3 3\n2 3 1 1",
"output": "2"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "11 4 2\n2 2 0 7 3 2 2 4 9 1 4",
"output": "6"
},
{
"input": "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 ... | 1,696,006,223 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 80 | 109 | 22,630,400 | import sys
n, t, c = map(int, input().split())
vec = [-1]
for i, temp in enumerate(map(int, sys.stdin.readline().split())):
if temp > t:
vec.append(i)
vec.append(n)
ans = 0
for i in range(1, len(vec)):
diff = vec[i] - vec[i - 1] - 1
ans += max(diff - c + 1, 0)
sys.stdout.write(s... | Title: Prison Transfer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city.
For this reason, he made the *n* ... | ```python
import sys
n, t, c = map(int, input().split())
vec = [-1]
for i, temp in enumerate(map(int, sys.stdin.readline().split())):
if temp > t:
vec.append(i)
vec.append(n)
ans = 0
for i in range(1, len(vec)):
diff = vec[i] - vec[i - 1] - 1
ans += max(diff - c + 1, 0)
sys.stdo... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line β the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,635,769,339 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 4,300,800 | a=input()
b=input()
res=[]
for i in range(len(a)):
if a[i]!=b[i]:
res.append('1')
else:
res.append('0')
print(*res,sep='')
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a=input()
b=input()
res=[]
for i in range(len(a)):
if a[i]!=b[i]:
res.append('1')
else:
res.append('0')
print(*res,sep='')
``` | 3.980489 |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation β the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub>β=β3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits β that results in number 11010<sub class="lower-index">2</sub>β=β26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,618,995,477 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 218 | 2,355,200 | s = input()
for idx in range(len(s)):
if s[idx] == "0":
break
print(s[:idx]+s[idx+1:]) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
s = input()
for idx in range(len(s)):
if s[idx] == "0":
break
print(s[:idx]+s[idx+1:])
``` | 3 | |
468 | C | Hack it! | PROGRAMMING | 2,500 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen... | The first line contains a single integer *a*Β (1<=β€<=*a*<=β€<=1018). | Print two integers: *l*,<=*r*Β (1<=β€<=*l*<=β€<=*r*<=<<=10200) β the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. | [
"46\n",
"126444381000032\n"
] | [
"1 10\n",
"2333333 2333333333333\n"
] | none | 1,500 | [
{
"input": "46",
"output": "1 10"
},
{
"input": "126444381000032",
"output": "2333333 2333333333333"
},
{
"input": "69645082595",
"output": "613752823618441225798858488535 713259406474207764329704856394"
},
{
"input": "70602205995",
"output": "11 2492213340204320744986569... | 1,424,004,438 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 62 | 0 | a=int(input())
x=a-((10**20)*45*21+1)%a
print(1+x,10**21+x) | Title: Hack it!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X ... | ```python
a=int(input())
x=a-((10**20)*45*21+1)%a
print(1+x,10**21+x)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,692,485,672 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | def way_too_long_words(txt_arr):
res = []
for input_txt in txt_arr:
n = len(input_txt)
if n <= 10:
res.append(input_txt)
else:
res.append(input_txt[0] + str(n-2) + input_txt[-1])
return res
if __name__ == "__main__":
n = int(input())
txt_a... | 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
def way_too_long_words(txt_arr):
res = []
for input_txt in txt_arr:
n = len(input_txt)
if n <= 10:
res.append(input_txt)
else:
res.append(input_txt[0] + str(n-2) + input_txt[-1])
return res
if __name__ == "__main__":
n = int(input())
... | 3.9845 |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,524,523,715 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 171 | 20,582,400 |
#k=int(input())
#n,m=map(int,input().split())
import sys
#a=list(map(int,input().split()))
#b=list(map(int,input().split()))
import math
n=int(input())
a=list(map(int,input().split()))
ss=sum(a);
s=0
for i in range(n):
s+=a[i]
if(2*s>=ss):
print(i+1)
sys.exit()
| Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
#k=int(input())
#n,m=map(int,input().split())
import sys
#a=list(map(int,input().split()))
#b=list(map(int,input().split()))
import math
n=int(input())
a=list(map(int,input().split()))
ss=sum(a);
s=0
for i in range(n):
s+=a[i]
if(2*s>=ss):
print(i+1)
sys... | 3 | |
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ... | The first line contains three integers *n*, *m*, and *k* (2<=β€<=*n*<=β€<=100, 1<=β€<=*m*<=β€<=*n*, 1<=β€<=*k*<=β€<=100)Β β the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=... | Print one integerΒ β the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k*β=β20 dollars, Zane can buy only house 5. The distance from house *m*β=β1 to house 5 is 10β+β10β+β10β+β10β=β40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m*β=β3 and house 6 are only 30 meters away, while house *m*β=β3 a... | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"outpu... | 1,559,807,370 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 0 | n,m,k=map(int,input().split())
m-=1
l=[int(x) for x in input().split()]
q=[]
for i in range(n):
if l[i]!=0 and l[i]<=k:
q.append((abs(i-m))*10)
print(min(q))
| Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li... | ```python
n,m,k=map(int,input().split())
m-=1
l=[int(x) for x in input().split()]
q=[]
for i in range(n):
if l[i]!=0 and l[i]<=k:
q.append((abs(i-m))*10)
print(min(q))
``` | 3 | |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-... | The single line contains two numbers, *n* and *t* (1<=β€<=*n*<=β€<=100, 2<=β€<=*t*<=β€<=10) β the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, β the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input"... | 1,665,214,610 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 46 | 0 | n,t = map(int,input().split())
s = '1'
i = 1
while i <= n-1:
s += '0'
i += 1
w = s + '0'
num1 = int(s)
num2 = int(w)
while num1 < num2:
if num1 % t == 0:
print(num1)
break
else:
num1 += 1
if num1 == num2:
print(-1) | Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larg... | ```python
n,t = map(int,input().split())
s = '1'
i = 1
while i <= n-1:
s += '0'
i += 1
w = s + '0'
num1 = int(s)
num2 = int(w)
while num1 < num2:
if num1 % t == 0:
print(num1)
break
else:
num1 += 1
if num1 == num2:
print(-1)
``` | 3 | |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,492,357,293 | 393 | Python 3 | OK | TESTS | 63 | 62 | 5,529,600 | s = input().strip()
s = s.replace("VK", "*")
cnt = sum(map(lambda x: x=="*",s))
if "VV" in s or "KK" in s:
cnt +=1
print(cnt) | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
s = input().strip()
s = s.replace("VK", "*")
cnt = sum(map(lambda x: x=="*",s))
if "VV" in s or "KK" in s:
cnt +=1
print(cnt)
``` | 3 | |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=β€<=*a*<=β€<=2) which denotes the number of the... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,447,199,712 | 2,147,483,647 | Python 3 | OK | TESTS | 4 | 92 | 0 | fi = open('input.txt', 'r')
d, a = fi.readline().strip() == 'front', int(fi.readline()) == 1
print('L' if d == a else 'R', file=open('output.txt', 'w')) | Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through... | ```python
fi = open('input.txt', 'r')
d, a = fi.readline().strip() == 'front', int(fi.readline()) == 1
print('L' if d == a else 'R', file=open('output.txt', 'w'))
``` | 3 | |
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,698,415,903 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | l1=[]
for i in range(1,6):
l=list(map(int,input().split()))
l1.append(l)
for i in l1:
for j in i:
if j!=0:
c=i.index(j)
r=l1.index(i)
m=abs(r-2)
m=m+abs(c-2)
print(m) | 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
l1=[]
for i in range(1,6):
l=list(map(int,input().split()))
l1.append(l)
for i in l1:
for j in i:
if j!=0:
c=i.index(j)
r=l1.index(i)
m=abs(r-2)
m=m+abs(c-2)
print(m)
``` | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=β€<=*x**i*,<=*y**i*,<=*z**i*<=β€<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,671,444,940 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 154 | 0 | n = int(input())
x = []
for i in range(n):
a, b, c = map(int, input().split())
x.append([a,b,c])
s = 0
m = 0
l = 0
for i in range(n):
s += x[i][0]
m += x[i][1]
l += x[i][2]
if s == 0 and m == 0 and l == 0:
print("YES")
else:
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
x = []
for i in range(n):
a, b, c = map(int, input().split())
x.append([a,b,c])
s = 0
m = 0
l = 0
for i in range(n):
s += x[i][0]
m += x[i][1]
l += x[i][2]
if s == 0 and m == 0 and l == 0:
print("YES")
else:
print("NO")
``` | 3.9615 |
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,638,956,940 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 133 | 109 | 512,000 | """https://codeforces.com/problemset/problem/981/A
"""
s = input()
for r in range(len(s), 1, -1):
if s[:r] != s[r - 1::-1]:
print(r)
break
else:
print(0)
| 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
"""https://codeforces.com/problemset/problem/981/A
"""
s = input()
for r in range(len(s), 1, -1):
if s[:r] != s[r - 1::-1]:
print(r)
break
else:
print(0)
``` | 3 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=β€<=*n*<=β€<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,613,645,596 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | n=int(input())
m=n//2
switcher={
0:[m-1,m+1],
1:[m,m+1],
2:[m-2,m+2],
3:[m,m+1],
}
ans=switcher.get(n%4)
print(ans[0],ans[1])
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
n=int(input())
m=n//2
switcher={
0:[m-1,m+1],
1:[m,m+1],
2:[m-2,m+2],
3:[m,m+1],
}
ans=switcher.get(n%4)
print(ans[0],ans[1])
``` | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=β€<=*n*<=β€<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line β the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,558,927,402 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 140 | 0 | x = int(input())
n=1
lvl_arr = [0]
def LvL(n):
lvl_arr.append(2**(n-1)*5 + lvl_arr[n-1])
return lvl_arr[n]
while(x > LvL(n)):
n = n+1
p = ((x - lvl_arr[n-1] - 1) // 2**(n-1)) + 1
if(p == 1):
print("Sheldon")
elif(p == 2):
print("Leonard")
elif(p == 3):
print("Penny")
elif(p == 4):
... | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
x = int(input())
n=1
lvl_arr = [0]
def LvL(n):
lvl_arr.append(2**(n-1)*5 + lvl_arr[n-1])
return lvl_arr[n]
while(x > LvL(n)):
n = n+1
p = ((x - lvl_arr[n-1] - 1) // 2**(n-1)) + 1
if(p == 1):
print("Sheldon")
elif(p == 2):
print("Leonard")
elif(p == 3):
print("Penny")
elif(p ... | 3.93 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=Γ<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=β€<=<=*n*,<=*m*,<=*a*<=β€<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,683,039,348 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n,m,a=map(int,input().split())
l1=n//a
l2=m//a
if n//a<n/a:
l1=n//a+1
if m//a<m/a:
l2=m//a +1
soni=l1*l2
print(soni)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a=map(int,input().split())
l1=n//a
l2=m//a
if n//a<n/a:
l1=n//a+1
if m//a<m/a:
l2=m//a +1
soni=l1*l2
print(soni)
``` | 3.977 |
111 | A | Petya and Inequiations | PROGRAMMING | 1,400 | [
"greedy"
] | A. Petya and Inequiations | 2 | 256 | Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=β₯<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=β€<=*y* | The first line contains three space-separated integers *n*, *x* and *y* (1<=β€<=*n*<=β€<=105,<=1<=β€<=*x*<=β€<=1012,<=1<=β€<=*y*<=β€<=106).
Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. | Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. | [
"5 15 15\n",
"2 3 2\n",
"1 99 11\n"
] | [
"4\n4\n1\n1\n2\n",
"-1\n",
"11\n"
] | none | 500 | [
{
"input": "5 15 15",
"output": "11\n1\n1\n1\n1"
},
{
"input": "2 3 2",
"output": "-1"
},
{
"input": "1 99 11",
"output": "11"
},
{
"input": "100000 810000099998 1000000",
"output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n... | 1,590,925,696 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 436 | 8,089,600 |
n,x,y=map(int,input().split())
import math
an=n-1
if(x<=n-1):
if(y>=n):
for i in range(n):
print(1)
else:
print(-1)
else:
me=math.sqrt(x-an)
if(me==int(me)):
me=int(me)
if(me+an<=y):
for i in range(n-1):
print(1)
... | Title: Petya and Inequiations
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied:
- *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=β₯<=*x*- *a*1<=+<=*a*2<=+<... | ```python
n,x,y=map(int,input().split())
import math
an=n-1
if(x<=n-1):
if(y>=n):
for i in range(n):
print(1)
else:
print(-1)
else:
me=math.sqrt(x-an)
if(me==int(me)):
me=int(me)
if(me+an<=y):
for i in range(n-1):
p... | 3.875932 |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=β€<=*n*<=β€<=100). The second line contains *n* space-separated integers *r**i* (1<=β€<=*r**i*<=β€<=1000) β the circles' radii. It is guaranteed that all circles are different. | Print the single real number β total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals ΟβΓβ1<sup class="upper-index">2</sup>β=βΟ.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,683,785,948 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | # Description of the problem can be found at http://codeforces.com/problemset/problem/157/B
import math
n = int(input())
l_s = list(map(int, input().split()))
l_s.sort(reverse = True)
t = 0
for index in range(n):
t += (-1 if index % 2 == 1 else 1) * l_s[index] ** 2
print(t * math.pi) | Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
# Description of the problem can be found at http://codeforces.com/problemset/problem/157/B
import math
n = int(input())
l_s = list(map(int, input().split()))
l_s.sort(reverse = True)
t = 0
for index in range(n):
t += (-1 if index % 2 == 1 else 1) * l_s[index] ** 2
print(t * math.pi)
``` | 3 | |
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str... | The first line contains one integer number *x* (1<=β€<=*x*<=β€<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"i... | 1,691,031,915 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 | x=list(input())
x.reverse()
g=False
while len(x)>1:
if x[0]=='0' and g==False:
x.pop(0)
else:
g=True
if x[0]!=x[-1]:
print('NO')
exit()
else:
x.pop(0)
x.pop()
print("YES") | Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from righ... | ```python
x=list(input())
x.reverse()
g=False
while len(x)>1:
if x[0]=='0' and g==False:
x.pop(0)
else:
g=True
if x[0]!=x[-1]:
print('NO')
exit()
else:
x.pop(0)
x.pop()
print("YES")
``` | 3 | |
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters β the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,609,959,402 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 140 | 0 | vowels = ['a', 'e', 'i', 'o', 'u', 'y']
def word_correction(s):
result = []
result.append(s[0])
left = 0
right = 1
while right < len(s):
if not s[left] in vowels or not s[right] in vowels:
result.append(s[right])
left = right
right += 1
retur... | Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
vowels = ['a', 'e', 'i', 'o', 'u', 'y']
def word_correction(s):
result = []
result.append(s[0])
left = 0
right = 1
while right < len(s):
if not s[left] in vowels or not s[right] in vowels:
result.append(s[right])
left = right
right += 1
... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.