contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,687,623,165 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 124 | 0 | def result(n,m,lis):
k=lis
p=tuple(k)
maxx=0
for i in range(n):
a=max(k)
b=k.index(a)
maxx+=a
k[b]=a-1
p=list(p)
minn=0
i=0
c=0
while i<n:
if len(p)==0 or c==n:
break
a=min(p)
b=p.index(a)
if a==0:
p.pop(b)
i+=1
continue
minn+=a
c+=1
p[b]=a-1
i+=1
print(maxx,minn)
... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
def result(n,m,lis):
k=lis
p=tuple(k)
maxx=0
for i in range(n):
a=max(k)
b=k.index(a)
maxx+=a
k[b]=a-1
p=list(p)
minn=0
i=0
c=0
while i<n:
if len(p)==0 or c==n:
break
a=min(p)
b=p.index(a)
if a==0:
p.pop(b)
i+=1
continue
minn+=a
c+=1
p[b]=a-1
i+=1
print(maxx,mi... | 3 | |
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"out... | 1,641,559,711 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 93 | 0 | x = input().split()
temp = []
for i in x:
temp.append(int(i))
x = temp.copy()
n1 = x[0]
n2 = x[1]
k1 = x[2]
k2 = x[-1]
c1 = False
while c1==False:
if n1==0:
print("Second")
break
n1 -= 1
if n2 == 0:
print("First")
break
n2 -= 1
| Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba... | ```python
x = input().split()
temp = []
for i in x:
temp.append(int(i))
x = temp.copy()
n1 = x[0]
n2 = x[1]
k1 = x[2]
k2 = x[-1]
c1 = False
while c1==False:
if n1==0:
print("Second")
break
n1 -= 1
if n2 == 0:
print("First")
break
n2 -= 1
... | 3 | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,688,792,016 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 9,830,400 | var = input()
nums = var.split(" ")
var = input()
mont = var.split(" ")
final = 0
min = 999999999999999999999999999999999999999999999999999999999999999
for i in range(len(mont)):
mont[i] = int(mont[i])
if mont[i] < min:
min = i
for i in range(int(nums[1])):
found = 0
for j in range(len(mont)... | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
var = input()
nums = var.split(" ")
var = input()
mont = var.split(" ")
final = 0
min = 999999999999999999999999999999999999999999999999999999999999999
for i in range(len(mont)):
mont[i] = int(mont[i])
if mont[i] < min:
min = i
for i in range(int(nums[1])):
found = 0
for j in range... | 0 | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,687,469,987 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | number = int(input())
sets = []
dicti = {}
for i in range(number):
num = int(input())
if num == -1:
if len(sets)==0:
sets.append([i+1])
else:
sets[0].append(i+1)
else:
dicti[i+1]=num
print(dicti)
print(sets)
while len(dicti)!=0:
s=[]
... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
number = int(input())
sets = []
dicti = {}
for i in range(number):
num = int(input())
if num == -1:
if len(sets)==0:
sets.append([i+1])
else:
sets[0].append(i+1)
else:
dicti[i+1]=num
print(dicti)
print(sets)
while len(dicti)!=0:
... | 0 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,658,478,574 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 47 | 2,000 | 16,179,200 | n=int(input())
s=input()
arr=list(map(int,input().split()))
seco=[]
r=s.find("R")
l=s.find("L",r)
if r==-1 or l==-1:
print(-1)
else:
seco.append((arr[l]-arr[r])//2)
for i in range(n):
r=s.find("R",r+1)
l=s.find("L",r)
if r==-1 or l==-1:
print(min(seco)... | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
n=int(input())
s=input()
arr=list(map(int,input().split()))
seco=[]
r=s.find("R")
l=s.find("L",r)
if r==-1 or l==-1:
print(-1)
else:
seco.append((arr[l]-arr[r])//2)
for i in range(n):
r=s.find("R",r+1)
l=s.find("L",r)
if r==-1 or l==-1:
print... | 0 | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,646,768,087 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | (n,m)=map(int(input.split(' ')))
s = input()
for i in rang(m):
(l,r,c1,c2) = map(int(input.split(' ')))
for j in range(l-1,r-1):
if(s[j]==c1) s[j]=c2
print(s)
| Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
(n,m)=map(int(input.split(' ')))
s = input()
for i in rang(m):
(l,r,c1,c2) = map(int(input.split(' ')))
for j in range(l-1,r-1):
if(s[j]==c1) s[j]=c2
print(s)
``` | -1 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,590,009,860 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 310 | 819,200 | import string
s = input()
def x(s):
u =0
l = 0
for c in s:
if c in string.ascii_uppercase:
u+=1
else:
l+=1
if u>l:
return s.upper()
else:
return s.lower()
print(x(s))
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
import string
s = input()
def x(s):
u =0
l = 0
for c in s:
if c in string.ascii_uppercase:
u+=1
else:
l+=1
if u>l:
return s.upper()
else:
return s.lower()
print(x(s))
``` | 3.920974 |
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose thre... | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**... | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti... | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
... | 1,445,358,601 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 670 | 716,800 | def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()]
[n,m]=get()
mus={}
for z in range(n):
mus[z+1]=[]
for z in range(m):
[x,y]=get()
mus[x].append(y)
mus... | Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br... | ```python
def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()]
[n,m]=get()
mus={}
for z in range(n):
mus[z+1]=[]
for z in range(m):
[x,y]=get()
mus[x].append(y)
... | 3 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,618,138,844 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 156 | 9,523,200 | n,a,b=map(int,input().split())
x=list(map(int,input().split()))
x1=x[1:]
x1.sort()
y=sum(x)
while(a*x[0]<b*y):
y-=x1.pop()
print(n-len(x1)-1)
| Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
x1=x[1:]
x1.sort()
y=sum(x)
while(a*x[0]<b*y):
y-=x1.pop()
print(n-len(x1)-1)
``` | 3 | |
570 | E | Pig and Palindromes | PROGRAMMING | 2,300 | [
"combinatorics",
"dp"
] | null | null | Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of *n* rows and *m* columns. We enumerate the rows of the rectangle from top to bottom with numbers from 1 to *n*, and the columns — from left to right with numbers from 1 to *m*. Let's ... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=500) — the height and width of the field.
Each of the following *n* lines contains *m* lowercase English letters identifying the types of cells of the forest. Identical cells are represented by identical letters, different cells are represented by dif... | Print a single integer — the number of beautiful paths modulo 109<=+<=7. | [
"3 4\naaab\nbaaa\nabba\n"
] | [
"3"
] | Picture illustrating possibilities for the sample test.
<img class="tex-graphics" src="https://espresso.codeforces.com/bf73568d1cf80d89f66d4e472a91ae0339af83a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img class="tex-graphics" src="https://espresso.codeforces.com/1e870880d976e642be85498efab6bbd10bae8a84... | 2,500 | [
{
"input": "3 4\naaab\nbaaa\nabba",
"output": "3"
},
{
"input": "2 2\nab\naa",
"output": "2"
},
{
"input": "3 5\nqqqrw\nwqqtw\newqqq",
"output": "3"
},
{
"input": "1 5\nabbba",
"output": "1"
},
{
"input": "1 5\nabbbb",
"output": "0"
},
{
"input": "1 4\... | 1,686,281,165 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 61 | 2,560,000 | import sys
from collections import Counter
import functools
import math
import random
import sys
import os
from bisect import bisect_left,bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import nsmallest, nlargest, heapify, heappop, heappush
from io im... | Title: Pig and Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of *n* rows and *m* columns. We enumerate the rows of the rectangle from top to b... | ```python
import sys
from collections import Counter
import functools
import math
import random
import sys
import os
from bisect import bisect_left,bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import nsmallest, nlargest, heapify, heappop, heappush
... | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,602,246,771 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | s = input().rstrip('\n')
s_2 = reversed(input().rstrip('\n'))
if s == str(s_2):
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().rstrip('\n')
s_2 = reversed(input().rstrip('\n'))
if s == str(s_2):
print("YES")
else:
print("NO")
``` | 0 |
455 | D | Serega and Fun | PROGRAMMING | 2,700 | [
"data structures"
] | null | null | Serega loves fun. However, everyone has fun in the unique manner. Serega has fun by solving query problems. One day Fedor came up with such a problem.
You are given an array *a* consisting of *n* positive integers and queries to it. The queries can be of two types:
1. Make a unit cyclic shift to the right on the seg... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements of the array. The second line contains *n* integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=*n*).
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries. The next *q* lines contain the querie... | For each query of the 2-nd type print the answer on a single line. | [
"7\n6 6 2 7 4 2 5\n7\n1 3 6\n2 2 4 2\n2 2 4 7\n2 2 2 5\n1 2 6\n1 1 4\n2 1 7 3\n",
"8\n8 4 2 2 7 7 8 8\n8\n1 8 8\n2 8 1 7\n1 8 1\n1 7 3\n2 8 8 3\n1 1 4\n1 2 7\n1 4 5\n"
] | [
"2\n1\n0\n0\n",
"2\n0\n"
] | none | 2,000 | [
{
"input": "7\n6 6 2 7 4 2 5\n7\n1 3 6\n2 2 4 2\n2 2 4 7\n2 2 2 5\n1 2 6\n1 1 4\n2 1 7 3",
"output": "2\n1\n0\n0"
},
{
"input": "8\n8 4 2 2 7 7 8 8\n8\n1 8 8\n2 8 1 7\n1 8 1\n1 7 3\n2 8 8 3\n1 1 4\n1 2 7\n1 4 5",
"output": "2\n0"
},
{
"input": "10\n7 2 3 4 3 2 4 4 9 1\n10\n1 4 5\n1 1 6\n... | 1,692,748,559 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 124 | 10,240,000 | from array import array
class BitVector():
# 簡潔ではない
# コンパクトのつもり
def __init__(self, n: int):
assert 0 <= n < 4294967295
self.N = n
self.block_size = (n + 31) >> 5
# bit数 32*n/32 * 2 = 2n bit
self.bit = array('I', bytes(4*(self.block_size+1)))
self.acc = array('I', bytes(4*(s... | Title: Serega and Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Serega loves fun. However, everyone has fun in the unique manner. Serega has fun by solving query problems. One day Fedor came up with such a problem.
You are given an array *a* consisting of *n* positive integers and q... | ```python
from array import array
class BitVector():
# 簡潔ではない
# コンパクトのつもり
def __init__(self, n: int):
assert 0 <= n < 4294967295
self.N = n
self.block_size = (n + 31) >> 5
# bit数 32*n/32 * 2 = 2n bit
self.bit = array('I', bytes(4*(self.block_size+1)))
self.acc = array('I', ... | -1 | |
355 | A | Vasya and Digital Root | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<... | The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). | In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. | [
"4 4\n",
"5 1\n",
"1 0\n"
] | [
"5881\n",
"36172\n",
"0\n"
] | For the first test sample *dr*(5881) = *dr*(22) = 4.
For the second test sample *dr*(36172) = *dr*(19) = *dr*(10) = 1. | 500 | [
{
"input": "4 4",
"output": "5881"
},
{
"input": "5 1",
"output": "36172"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "8 7",
"output": "49722154"
},
{
"input": "487 0",
"output": "No solution"
},
{
"input": "1000 5",
"output": "854193955406789... | 1,381,811,842 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 307,200 | #import fileinput
import sys
#k,d = next(fileinput.input()).split(' ')
#for line in fileinput.input():
#k,d = line.split(' ')
#print(k + ' ' + d)
for line in sys.stdin:
k,d = [int(x) for x in line.split(' ')]
if d == 0:
if k == 1:
print(0)
else:
print(... | Title: Vasya and Digital Root
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=... | ```python
#import fileinput
import sys
#k,d = next(fileinput.input()).split(' ')
#for line in fileinput.input():
#k,d = line.split(' ')
#print(k + ' ' + d)
for line in sys.stdin:
k,d = [int(x) for x in line.split(' ')]
if d == 0:
if k == 1:
print(0)
else:
... | 3 | |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,697,381,439 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | def main():
n,k=map(int , input().split())
a = [int(i) for i in input().split()]
x,ans = a[k-1] , 0
for i in range(len(a)):
ans += 1 if a[i] > 0 and a[i] >= x else 0
print(ans)
main() | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
def main():
n,k=map(int , input().split())
a = [int(i) for i in input().split()]
x,ans = a[k-1] , 0
for i in range(len(a)):
ans += 1 if a[i] > 0 and a[i] >= x else 0
print(ans)
main()
``` | 3 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | 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*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,658,264,132 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 |
num = int(input())
data = list(map(int, input().split()))
maax = max(data)
count = 0
for i in range(num):
if data[i] == maax:
count = count + 1
if count <= (num + 1) / 2:
print("YES")
else: print("NO") | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
num = int(input())
data = list(map(int, input().split()))
maax = max(data)
count = 0
for i in range(num):
if data[i] == maax:
count = count + 1
if count <= (num + 1) / 2:
print("YES")
else: print("NO")
``` | 0 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,550,226,732 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 248 | 0 | n, m = map(int, input().split())
ct = (sorted([int(i) for i in input().split()]))
wt = [int(i) for i in input().split()]
k = max(ct[-1],2*ct[0])
print(k if 2 * ct[0] <= k < min(wt) else "-1") | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
n, m = map(int, input().split())
ct = (sorted([int(i) for i in input().split()]))
wt = [int(i) for i in input().split()]
k = max(ct[-1],2*ct[0])
print(k if 2 * ct[0] <= k < min(wt) else "-1")
``` | 3 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,696,865,408 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 61 | 0 | x = 0
n = int(input())
for i in range(n):
operation = input()
if "++" in operation:
x += 1
elif "--" in operation:
x -= 1
print(x) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
x = 0
n = int(input())
for i in range(n):
operation = input()
if "++" in operation:
x += 1
elif "--" in operation:
x -= 1
print(x)
``` | 3 | |
277 | A | Learning Languages | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu"
] | null | null | The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages.
Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next... | Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). | [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | 500 | [
{
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5",
"output": "0"
},
{
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1",
"output": "2"
},
{
"input": "2 2\n1 2\n0",
"output": "1"
},
{
"input": "2 2\n0\n0",
"output": "2"
},
{
"input": "5 5\n1 3\n0\n0\n2 4... | 1,646,203,764 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 |
n,m = map(int,input().split())
lang={}
nange=0
for i in range(1,n+1):
k,*l=map(int,input().split())
for li in l:
if li in lang:
lang[li].append(i)
else:
lang[li]=[i]
# print(lang)
comps=[-1]*(n+1)
for i in lang:
if len(lang[i])>1:
for j in rang... | Title: Learning Languages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have th... | ```python
n,m = map(int,input().split())
lang={}
nange=0
for i in range(1,n+1):
k,*l=map(int,input().split())
for li in l:
if li in lang:
lang[li].append(i)
else:
lang[li]=[i]
# print(lang)
comps=[-1]*(n+1)
for i in lang:
if len(lang[i])>1:
for... | 0 | |
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,690,719,199 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 77 | 1,740,800 | n, packs = map(int, input().split())
child = 0
for _ in range(n):
a, b = input().split()
b = int(b)
if a == '+':
packs += b
else:
if packs < b:
child += 1
continue
packs -= b
print(packs, child)
| 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, packs = map(int, input().split())
child = 0
for _ in range(n):
a, b = input().split()
b = int(b)
if a == '+':
packs += b
else:
if packs < b:
child += 1
continue
packs -= b
print(packs, child)
``` | 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,695,702,340 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | {
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": null... | 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
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_co... | -1 |
590 | A | Median Smoothing | PROGRAMMING | 1,700 | [
"implementation"
] | null | null | A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practi... | The first input line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=500<=000) — the length of the initial sequence.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=0 or *a**i*<==<=1), giving the initial sequence itself. | If the sequence will never become stable, print a single number <=-<=1.
Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print *n* numbers separated by a space — the resulting... | [
"4\n0 0 1 1\n",
"5\n0 1 0 1 0\n"
] | [
"0\n0 0 1 1\n",
"2\n0 0 0 0 0\n"
] | In the second sample the stabilization occurs in two steps: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a983e7baab048cbe43812cb997c15e9d7100231.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and the sequence 00000 is obviously stable. | 750 | [
{
"input": "4\n0 0 1 1",
"output": "0\n0 0 1 1"
},
{
"input": "5\n0 1 0 1 0",
"output": "2\n0 0 0 0 0"
},
{
"input": "3\n1 0 0",
"output": "0\n1 0 0"
},
{
"input": "4\n1 0 0 1",
"output": "0\n1 0 0 1"
},
{
"input": "7\n1 0 1 1 1 0 1",
"output": "1\n1 1 1 1 1 1... | 1,446,173,786 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 307,200 | import sys
num = input()
codes = input()
num = int(num)
codes = codes.split(' ')
for k in range(len(codes)):
codes[k] = int(codes[k])
new_codes = codes[:]
def met(codes):
def m3(a, i):
if(sum([a[i-1], a[i], a[i+1]]) >= 2):
return 1
return 0
for i in range(1, len(codes)-1):
new_codes[i] = m3(... | Title: Median Smoothing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in sci... | ```python
import sys
num = input()
codes = input()
num = int(num)
codes = codes.split(' ')
for k in range(len(codes)):
codes[k] = int(codes[k])
new_codes = codes[:]
def met(codes):
def m3(a, i):
if(sum([a[i-1], a[i], a[i+1]]) >= 2):
return 1
return 0
for i in range(1, len(codes)-1):
new_code... | 0 | |
612 | B | HDD is Outdated Technology | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read s... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments.
The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector. | Print the only integer — the number of time units needed to read the file. | [
"3\n3 1 2\n",
"5\n1 3 5 4 2\n"
] | [
"3\n",
"10\n"
] | In the second example the head moves in the following way:
- 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time un... | 0 | [
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "5\n1 3 5 4 2",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "40"
... | 1,700,144,610 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 24 | 140 | 20,582,400 | n = (int)(input())
a = (list)(map(int , input().split()))
pos = [0 for _ in range(n + 1)]
for _ in range(n) : pos[a[_]] = _
ans = 0
for index in range(2 , n + 1) :
ans += abs(pos[index] - pos[index - 1])
print(ans) | Title: HDD is Outdated Technology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the ... | ```python
n = (int)(input())
a = (list)(map(int , input().split()))
pos = [0 for _ in range(n + 1)]
for _ in range(n) : pos[a[_]] = _
ans = 0
for index in range(2 , n + 1) :
ans += abs(pos[index] - pos[index - 1])
print(ans)
``` | 3 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,670,185,269 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | s=input()
if s==s[::-1]:print("NO")
else:print("YES") | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
s=input()
if s==s[::-1]:print("NO")
else:print("YES")
``` | 0 | |
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A p... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15... | 1,649,207,483 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 218 | 9,420,800 | # @Chukamin ZZU_TRAIN
def main():
n = int(input())
data = list(map(int, input().split()))
flat = {}
flag = 0
wrong = 0
for i in range(n):
if data[i] != i:
flat[i] = data[i]
if data[i] in flat and flat[data[i]] == i:
flag = 1
wrong += 1... | Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<... | ```python
# @Chukamin ZZU_TRAIN
def main():
n = int(input())
data = list(map(int, input().split()))
flat = {}
flag = 0
wrong = 0
for i in range(n):
if data[i] != i:
flat[i] = data[i]
if data[i] in flat and flat[data[i]] == i:
flag = 1
... | 3 | |
55 | B | Smallest number | PROGRAMMING | 1,600 | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced... | First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) | Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | 1,000 | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3... | 1,599,268,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 307,200 | # Getting problem data from codeforces.
numbers = list(input().split(' '))
operators = list(input().split(' '))
def generateExpressionFor(numbers, operators):
expression = numbers[0]
for i in range(len(operators)):
expression+= operators[i] + numbers[i+1]
return expression
from itertools import ... | Title: Smallest number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the n... | ```python
# Getting problem data from codeforces.
numbers = list(input().split(' '))
operators = list(input().split(' '))
def generateExpressionFor(numbers, operators):
expression = numbers[0]
for i in range(len(operators)):
expression+= operators[i] + numbers[i+1]
return expression
from itertoo... | 0 |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,696,687,983 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | n = int(input())
count = 0
num = 1
while True:
num_str = str(num)
num_length = len(num_str)
if count + num_length >= n:
nth_digit = num_str[n - count - 1]
print(nth_digit)
break
count += num_length
num += 1
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
n = int(input())
count = 0
num = 1
while True:
num_str = str(num)
num_length = len(num_str)
if count + num_length >= n:
nth_digit = num_str[n - count - 1]
print(nth_digit)
break
count += num_length
num += 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,514,519,191 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 5,529,600 | n = int(input())
a = n%5
if a ==1:
print("Sheldon")
elif a == 2:
print("Penny")
elif a==3:
print("Leonard")
elif a==4:
print("Rajesh")
elif a==0:
print("Howard") | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n = int(input())
a = n%5
if a ==1:
print("Sheldon")
elif a == 2:
print("Penny")
elif a==3:
print("Leonard")
elif a==4:
print("Rajesh")
elif a==0:
print("Howard")
``` | 0 |
955 | B | Not simply beatiful strings | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a ... | The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters. | Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case. | [
"ababa\n",
"zzcxx\n",
"yeee\n"
] | [
"Yes\n",
"Yes\n",
"No\n"
] | In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | 1,000 | [
{
"input": "ababa",
"output": "Yes"
},
{
"input": "zzcxx",
"output": "Yes"
},
{
"input": "yeee",
"output": "No"
},
{
"input": "a",
"output": "No"
},
{
"input": "bbab",
"output": "No"
},
{
"input": "abcd",
"output": "Yes"
},
{
"input": "abc"... | 1,687,938,590 | 1,790 | Python 3 | OK | TESTS | 56 | 62 | 102,400 | N = 26; s = input (); cnt = dict ()
for ch in s : cnt[ch] = cnt.get (ch, 0) + 1
cnt1, cnt2 = 0, 0
for i in cnt.keys () :
if cnt[i] > 1 : cnt2 += 1
else : cnt1 += 1
if len (s) < 4 or cnt1 + cnt2 > 4 or cnt1 + cnt2 == 1: print ("No")
elif cnt1 + cnt2 == 2 : print ("Yes" if cnt2 == 2 else "No")
else : print ("... | Title: Not simply beatiful strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, abab... | ```python
N = 26; s = input (); cnt = dict ()
for ch in s : cnt[ch] = cnt.get (ch, 0) + 1
cnt1, cnt2 = 0, 0
for i in cnt.keys () :
if cnt[i] > 1 : cnt2 += 1
else : cnt1 += 1
if len (s) < 4 or cnt1 + cnt2 > 4 or cnt1 + cnt2 == 1: print ("No")
elif cnt1 + cnt2 == 2 : print ("Yes" if cnt2 == 2 else "No")
else ... | 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,691,386,876 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x= "front"
y = 1
if ( x == "back" and y == 1) or (x == "front" and y == 2) :
print("R")
else:
print("L") | 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
x= "front"
y = 1
if ( x == "back" and y == 1) or (x == "front" and y == 2) :
print("R")
else:
print("L")
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings in the set.
Each of the next *n* lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct.
The total length of the strings doesn't exceed 105. | Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings. | [
"4\nmail\nai\nlru\ncf\n",
"3\nkek\npreceq\ncheburek\n"
] | [
"cfmailru\n",
"NO\n"
] | One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum. | 0 | [
{
"input": "4\nmail\nai\nlru\ncf",
"output": "cfmailru"
},
{
"input": "3\nkek\npreceq\ncheburek",
"output": "NO"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nab\nba",
"output": "NO"
},
{
"input": "2\nac\nbc",
"output": "NO"
},
{
"input": "2\nc... | 1,689,363,623 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689363622.922278")# 1689363622.922287 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is c... | ```python
print("_RANDOM_GUESS_1689363622.922278")# 1689363622.922287
``` | 0 | |
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,455,910,252 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 78 | 409,600 | n=int(input())
s=['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']
s1=[]
for i in range(n):
s1=s[1:len(s)]+[s[0]]+[s[0]]
s=s[1:len(s)]+[s[0]]+[s[0]]
if len(s1)>=n:
break
print(s1[n-2]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n=int(input())
s=['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']
s1=[]
for i in range(n):
s1=s[1:len(s)]+[s[0]]+[s[0]]
s=s[1:len(s)]+[s[0]]+[s[0]]
if len(s1)>=n:
break
print(s1[n-2])
``` | 0 |
990 | C | Bracket Sequences Concatenation Problem | PROGRAMMING | 1,500 | [
"implementation"
] | null | null | A bracket sequence is a string containing only characters "(" and ")".
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg... | The first line contains one integer $n \, (1 \le n \le 3 \cdot 10^5)$ — the number of bracket sequences. The following $n$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $3 \cdot 10^5$. | In the single line print a single integer — the number of pairs $i, j \, (1 \le i, j \le n)$ such that the bracket sequence $s_i + s_j$ is a regular bracket sequence. | [
"3\n)\n()\n(\n",
"2\n()\n()\n"
] | [
"2\n",
"4\n"
] | In the first example, suitable pairs are $(3, 1)$ and $(2, 2)$.
In the second example, any pair is suitable, namely $(1, 1), (1, 2), (2, 1), (2, 2)$. | 0 | [
{
"input": "3\n)\n()\n(",
"output": "2"
},
{
"input": "2\n()\n()",
"output": "4"
},
{
"input": "7\n()(\n)\n)(\n())\n(((\n()()()\n()",
"output": "6"
},
{
"input": "6\n(\n((\n(((\n))))\n)))))\n))))))",
"output": "0"
},
{
"input": "9\n(()\n((())\n(\n)\n(()()(()())))\... | 1,528,778,032 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | num = int(input())
arr=[]
for i in range(num):
arr.append(input())
numofse=0
for i in range(len(arr)):
for z in range(len(arr)):
t = arr[i]+arr[z]
numOfOpem=0
for k in range(len(t)):
if(t[k]=="("):
num... | Title: Bracket Sequences Concatenation Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bracket sequence is a string containing only characters "(" and ")".
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting ... | ```python
num = int(input())
arr=[]
for i in range(num):
arr.append(input())
numofse=0
for i in range(len(arr)):
for z in range(len(arr)):
t = arr[i]+arr[z]
numOfOpem=0
for k in range(len(t)):
if(t[k]=="("):
... | -1 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,684,000,080 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
l=[l1,l2,l3]
def ch(n):
if n%2==1:
return 0
return 1
ll=[[1 for _ in range(3)] for __ in range(3)]
for i in range(3):
for j in range(3):
if l[i][j]%2==1:
ll[i][j]=ch(... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
l=[l1,l2,l3]
def ch(n):
if n%2==1:
return 0
return 1
ll=[[1 for _ in range(3)] for __ in range(3)]
for i in range(3):
for j in range(3):
if l[i][j]%2==1:
ll... | 0 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,590,241,759 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 171 | 0 | def read_tokens():
return input().strip().split()
def read_ints():
return [int(s) for s in read_tokens()]
n, d = read_ints()
arr = input()
def solve(arr: str, d: int) -> int:
# dp[i] = min(dp[i-1], dp[i-2], ..., dp[i-d]) + 1
# d
# = 1 + min dp[i-j]
# j=1
... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
def read_tokens():
return input().strip().split()
def read_ints():
return [int(s) for s in read_tokens()]
n, d = read_ints()
arr = input()
def solve(arr: str, d: int) -> int:
# dp[i] = min(dp[i-1], dp[i-2], ..., dp[i-d]) + 1
# d
# = 1 + min dp[i-j]
# ... | 3 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,681,658,512 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n = int(input())
answer = 0
pred = -1
maxx = -1
while n > 0:
n -= 1
h,m = map(int,input().split())
if (h,m) == pred:
answer += 1
else:
pred = (h,m)
maxx = max(answer, maxx)
answer = 1
print(pred)
maxx = max(answer,maxx)
print(maxx) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
answer = 0
pred = -1
maxx = -1
while n > 0:
n -= 1
h,m = map(int,input().split())
if (h,m) == pred:
answer += 1
else:
pred = (h,m)
maxx = max(answer, maxx)
answer = 1
print(pred)
maxx = max(answer,maxx)
print(maxx)
``` | 0 | |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,686,117,742 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | def addComments(n, m, servers, commands):
server_ip = {ip: name for name, ip in servers}
return [f"{command} #{server_ip[command.split()[1]]}" if command.endswith(';') else f"{command} #{server_ip[command.split()[1]]}" for command in commands]
# Read input values
n, m = map(int, input().split())
servers = []
... | Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
def addComments(n, m, servers, commands):
server_ip = {ip: name for name, ip in servers}
return [f"{command} #{server_ip[command.split()[1]]}" if command.endswith(';') else f"{command} #{server_ip[command.split()[1]]}" for command in commands]
# Read input values
n, m = map(int, input().split())
ser... | -1 | |
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 1,000 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,613,173,148 | 1,748 | PyPy 3 | OK | TESTS | 64 | 124 | 102,400 | class SegTree:
def __init__(self, init_val, ide_ele, segfunc):
self.n = len(init_val)
self.num = 2**(self.n-1).bit_length()
self.ide_ele = ide_ele
self.segfunc = segfunc
self.seg = [ide_ele]*2*self.num
# set_val
for i in range(self.n):
self.seg[i+s... | Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in th... | ```python
class SegTree:
def __init__(self, init_val, ide_ele, segfunc):
self.n = len(init_val)
self.num = 2**(self.n-1).bit_length()
self.ide_ele = ide_ele
self.segfunc = segfunc
self.seg = [ide_ele]*2*self.num
# set_val
for i in range(self.n):
se... | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,698,027,529 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 62 | 2,764,800 | total = 0
n = int(input())
if n == 1:
print("0")
else:
welfare = list(map(int, input().split()))
welfare.sort()
high = welfare.pop(welfare[-1])
for x in welfare:
total += (high - x)
print(total) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
total = 0
n = int(input())
if n == 1:
print("0")
else:
welfare = list(map(int, input().split()))
welfare.sort()
high = welfare.pop(welfare[-1])
for x in welfare:
total += (high - x)
print(total)
``` | -1 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,640,119,003 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 35 | 154 | 0 | number = int(input())
case = [int(x) for x in input().split()]
case.sort(reverse=True)
answer = '-1'
for i in range(12):
if sum(case[:i])>=number:
answer = i
break
print(answer)
| Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
number = int(input())
case = [int(x) for x in input().split()]
case.sort(reverse=True)
answer = '-1'
for i in range(12):
if sum(case[:i])>=number:
answer = i
break
print(answer)
``` | 0 | |
501 | B | Misha and Changing Handles | PROGRAMMING | 1,100 | [
"data structures",
"dsu",
"strings"
] | null | null | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the re... | The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and di... | In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*,... | [
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] | [
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] | none | 500 | [
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd... | 1,586,608,007 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 249 | 4,096,000 | q = int(input())
d = {}
for i in range(q):
w = input().split()
a, b = w[0], w[1]
if a in d.values():
for j in d.keys():
if d[j]==a:
d[j]=b
break
else:
d[a]=b
print(len(d))
for i in d:
print(i, d[i])
| Title: Misha and Changing Handles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is a... | ```python
q = int(input())
d = {}
for i in range(q):
w = input().split()
a, b = w[0], w[1]
if a in d.values():
for j in d.keys():
if d[j]==a:
d[j]=b
break
else:
d[a]=b
print(len(d))
for i in d:
print(i, d[i])
``` | 3 | |
610 | B | Vika and Squares | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of jars with colors Vika has.
The second line of the input contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is equal to the number of liters of paint in the *i*-th jar, i.e. th... | The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above. | [
"5\n2 4 2 3 3\n",
"3\n5 5 5\n",
"6\n10 10 10 1 10 10\n"
] | [
"12\n",
"15\n",
"11\n"
] | In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.
In the second sample Vika can start to paint using any color.
In the third sample Vika should start painting using color number 5... | 1,000 | [
{
"input": "5\n2 4 2 3 3",
"output": "12"
},
{
"input": "3\n5 5 5",
"output": "15"
},
{
"input": "6\n10 10 10 1 10 10",
"output": "11"
},
{
"input": "1\n167959139",
"output": "167959139"
},
{
"input": "10\n896619242 805194919 844752453 848347723 816995848 85681361... | 1,585,507,078 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 249 | 15,257,600 | n=int(input())
arr=[int(x) for x in input().split()]
m=arr[0]
for i in range(n):
if m>=arr[i]:
m=arr[i]
j=i
cnt=arr[j]*n+n-j-1
for i in range(n):
if arr[i]==m:
arr[i]=0
sum1=0
for j in range(n):
if arr[j]==0:
break
sum1+=1
print(cnt+sum1)
| Title: Vika and Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of... | ```python
n=int(input())
arr=[int(x) for x in input().split()]
m=arr[0]
for i in range(n):
if m>=arr[i]:
m=arr[i]
j=i
cnt=arr[j]*n+n-j-1
for i in range(n):
if arr[i]==m:
arr[i]=0
sum1=0
for j in range(n):
if arr[j]==0:
break
sum1+=1
print(cnt+sum1)
... | 0 | |
818 | A | Diplomas and Certificates | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ... | The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. | Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners. | [
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] | [
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] | none | 0 | [
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",... | 1,516,854,188 | 308 | Python 3 | OK | TESTS | 44 | 62 | 5,632,000 | n,k=map(int,input().split())
x=n//(2*(k+1))
print(x,k*x,n-x*(k+1)) | Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with... | ```python
n,k=map(int,input().split())
x=n//(2*(k+1))
print(x,k*x,n-x*(k+1))
``` | 3 | |
825 | C | Multi-judge Solving | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge).... | The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. | [
"3 3\n2 1 9\n",
"4 20\n10 3 6 3\n"
] | [
"1\n",
"0\n"
] | In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second ... | 0 | [
{
"input": "3 3\n2 1 9",
"output": "1"
},
{
"input": "4 20\n10 3 6 3",
"output": "0"
},
{
"input": "1 1000000000\n1",
"output": "0"
},
{
"input": "1 1\n3",
"output": "1"
},
{
"input": "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34... | 1,600,563,712 | 1,912 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 140 | 0 | import sys
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
ans = 0
for x in a:
if k*2 >= x:
k = max(k, x)
else:
while k*2 < x:
k *= 2
ans += 1
print(ans)
| Title: Multi-judge Solving
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the pro... | ```python
import sys
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
ans = 0
for x in a:
if k*2 >= x:
k = max(k, x)
else:
while k*2 < x:
k *= 2
ans += 1
print(ans)
``` | 0 | |
415 | A | Mashmokh and Lights | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turn... | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*).
It is guaranteed that all lights... | Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off. | [
"5 4\n4 3 1 2\n",
"5 5\n5 4 3 2 1\n"
] | [
"1 1 3 4 4 \n",
"1 2 3 4 5 \n"
] | In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus bu... | 500 | [
{
"input": "5 4\n4 3 1 2",
"output": "1 1 3 4 4 "
},
{
"input": "5 5\n5 4 3 2 1",
"output": "1 2 3 4 5 "
},
{
"input": "16 11\n8 5 12 10 14 2 6 3 15 9 1",
"output": "1 2 2 2 5 5 5 8 8 8 8 8 8 8 8 8 "
},
{
"input": "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 6... | 1,396,799,036 | 236 | Python 3 | OK | TESTS | 31 | 77 | 0 | n,m=map(int,input().split())
L=list(map(int,input().split()))
Q=[1]*n
Ans=[-1]*(n)
for i in range(m):
x=L[i]-1
for j in range(x,n):
if(Q[j]==1):
Q[j]=0
Ans[j]=x+1
for item in Ans:
print(item,end=" ")
| Title: Mashmokh and Lights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. ... | ```python
n,m=map(int,input().split())
L=list(map(int,input().split()))
Q=[1]*n
Ans=[-1]*(n)
for i in range(m):
x=L[i]-1
for j in range(x,n):
if(Q[j]==1):
Q[j]=0
Ans[j]=x+1
for item in Ans:
print(item,end=" ")
``` | 3 | |
572 | B | Order Book | PROGRAMMING | 1,300 | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | In this task you need to process a set of stock exchange orders and use them to create order book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready ... | The input starts with two positive integers *n* and *s* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*s*<=≤<=50), the number of orders and the book depth.
Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≤<=*p**i*<=≤<=105) and an integer *q**i* (1<=≤<=*q**i*<=≤<=104) — direction, price and volume resp... | Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input. | [
"6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n"
] | [
"S 50 8\nS 40 1\nB 25 10\nB 20 4\n"
] | Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.
You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders. | 1,000 | [
{
"input": "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10",
"output": "S 50 8\nS 40 1\nB 25 10\nB 20 4"
},
{
"input": "2 1\nB 7523 5589\nS 69799 1711",
"output": "S 69799 1711\nB 7523 5589"
},
{
"input": "1 1\nB 48259 991",
"output": "B 48259 991"
},
{
"input": "1 50\n... | 1,440,280,348 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 202 | 1,740,800 | n, s = tuple(map(int, input().split()))
agr = dict()
for i in range(n):
arr = input().split()
arr[1] = int(arr[1])
arr[2] = int(arr[2])
agr[(arr[0], arr[1])] = agr.get((arr[0], arr[1]), 0) + arr[2]
sell, buy = [], []
for elem in agr:
if elem[0] == 'B':
buy.append([elem[1], agr[... | Title: Order Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this task you need to process a set of stock exchange orders and use them to create order book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i... | ```python
n, s = tuple(map(int, input().split()))
agr = dict()
for i in range(n):
arr = input().split()
arr[1] = int(arr[1])
arr[2] = int(arr[2])
agr[(arr[0], arr[1])] = agr.get((arr[0], arr[1]), 0) + arr[2]
sell, buy = [], []
for elem in agr:
if elem[0] == 'B':
buy.append([ele... | 3 | |
675 | B | Restoring Painting | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
- The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*,... | The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers. | Print one integer — the number of distinct valid squares. | [
"2 1 1 1 2\n",
"3 3 1 2 3\n"
] | [
"2\n",
"6\n"
] | Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.... | 1,000 | [
{
"input": "2 1 1 1 2",
"output": "2"
},
{
"input": "3 3 1 2 3",
"output": "6"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1000 522 575 426 445",
"output": "774000"
},
{
"input": "99000 52853 14347 64237 88869",
"output": "1296306000"
},
{
... | 1,463,596,563 | 783 | Python 3 | WRONG_ANSWER | TESTS | 24 | 62 | 4,915,200 | n, a, b, c, d = map(int, input().split())
ans = n * (n - (max(a, d) + max(b, c) - min(a, d) - min(b, c)))
print(ans)
| Title: Restoring Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some ... | ```python
n, a, b, c, d = map(int, input().split())
ans = n * (n - (max(a, d) + max(b, c) - min(a, d) - min(b, c)))
print(ans)
``` | 0 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,628,404,385 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 93 | 20,172,800 | n, t = map(int, input().split())
ans = 0
for x in [int(i) for i in input().split()]:
t -= 86400-x
ans += 1
if t <= 0:
print(ans)
break
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n, t = map(int, input().split())
ans = 0
for x in [int(i) for i in input().split()]:
t -= 86400-x
ans += 1
if t <= 0:
print(ans)
break
``` | 3 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,681,477,692 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 62 | 0 | n = input()
word = ""
for i in range(len(n)):
d = n[i]
if i==0:
if n[i]!="9":
if int(n[i])>4:
d = str(9-int(n[i]))
else:
if int(n[i])>4:
d = str(9-int(n[i]))
word+= d
print(word)
| Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
n = input()
word = ""
for i in range(len(n)):
d = n[i]
if i==0:
if n[i]!="9":
if int(n[i])>4:
d = str(9-int(n[i]))
else:
if int(n[i])>4:
d = str(9-int(n[i]))
word+= d
print(word)
``` | 3 | |
704 | A | Thor | PROGRAMMING | 1,600 | [
"brute force",
"data structures",
"implementation"
] | null | null | Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).
*q* events are ... | The first line of input contains two integers *n* and *q* (1<=≤<=*n*,<=*q*<=≤<=300<=000) — the number of applications and the number of events to happen.
The next *q* lines contain the events. The *i*-th of these lines starts with an integer *type**i* — type of the *i*-th event. If *type**i*<==<=1 or *type**i*<==<=2 t... | Print the number of unread notifications after each event. | [
"3 4\n1 3\n1 1\n1 2\n2 3\n",
"4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3\n"
] | [
"1\n2\n3\n2\n",
"1\n2\n3\n0\n1\n2\n"
] | In the first sample:
1. Application 3 generates a notification (there is 1 unread notification). 1. Application 1 generates a notification (there are 2 unread notifications). 1. Application 2 generates a notification (there are 3 unread notifications). 1. Thor reads the notification generated by application 3, the... | 500 | [
{
"input": "3 4\n1 3\n1 1\n1 2\n2 3",
"output": "1\n2\n3\n2"
},
{
"input": "4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3",
"output": "1\n2\n3\n0\n1\n2"
},
{
"input": "10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n1 10\n3 8\n2 8\n1 6\n1 3\n1 9\n1 6\n1 3\n1 8\n1 1\n1 6\n1 1... | 1,501,583,986 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | a, b = map(int, input().split())
apps = [0 for x in range(a)]
notifications = []
results = []
p = 0
n = 0
for x in range(b):
s, t = map(int, input().split())
if s == 1:
notifications.append(t - 1)
apps[t - 1] += 1
n += 1
elif s == 2:
n -= apps[t - 1]
app... | Title: Thor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications ge... | ```python
a, b = map(int, input().split())
apps = [0 for x in range(a)]
notifications = []
results = []
p = 0
n = 0
for x in range(b):
s, t = map(int, input().split())
if s == 1:
notifications.append(t - 1)
apps[t - 1] += 1
n += 1
elif s == 2:
n -= apps[t - 1]
... | 0 | |
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,980,314 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 77 | 0 | s = input()
n = int(input())
ss = len(set(s))
if n > len(s) : print("impossible")
else : print(n-ss) | 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()
n = int(input())
ss = len(set(s))
if n > len(s) : print("impossible")
else : print(n-ss)
``` | 0 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,671,373,087 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 6 | 154 | 2,867,200 | a = int(input())
b = list(map(int, input().split()))
b.sort()
b.reverse()
k = 0
i = 0
q = sum(b)
if q < k:
print(-1)
else:
while k < a:
k += b[i]
i += 1
print(i) | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
a = int(input())
b = list(map(int, input().split()))
b.sort()
b.reverse()
k = 0
i = 0
q = sum(b)
if q < k:
print(-1)
else:
while k < a:
k += b[i]
i += 1
print(i)
``` | -1 | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,651,945,741 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | x = int(input())
num = 0
i = 0
for i in range(x):
num = num+i
if num == x:
print("YES")
if x == i:
print("NO") | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
x = int(input())
num = 0
i = 0
for i in range(x):
num = num+i
if num == x:
print("YES")
if x == i:
print("NO")
``` | 0 |
597 | A | Divisibility | PROGRAMMING | 1,600 | [
"math"
] | null | null | Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. | The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018). | Print the required number. | [
"1 1 10\n",
"2 -4 4\n"
] | [
"10\n",
"5\n"
] | none | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "2 -4 4",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 0 0",
"output": "1"
},
{
"input": "1 0 1",
"output": "2"
},
{
"input": "1 10181 10182",
"output": "2"
},
{
"inpu... | 1,657,390,035 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | k=int(input( ))
a=int(input( ))
b=int(input( ))
for i in range(a,b):
if k % i == 0 :
count +=1
print(count) | Title: Divisibility
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
Input Specification:
The onl... | ```python
k=int(input( ))
a=int(input( ))
b=int(input( ))
for i in range(a,b):
if k % i == 0 :
count +=1
print(count)
``` | -1 | |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,556,939,310 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | x=int(input())
class nibba:
def __init__(self,nm,ct):
self.nm=nm
self.ct=ct
def f(self):
if self.ct=='rat':
return 0
elif self.ct=='child' or self.ct=='woman':
return 1
elif self.ct=='man':
return 2
elif self.ct=='captain':
return 3
s=[]
for n in range(x):
a=[n for n in input(... | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
x=int(input())
class nibba:
def __init__(self,nm,ct):
self.nm=nm
self.ct=ct
def f(self):
if self.ct=='rat':
return 0
elif self.ct=='child' or self.ct=='woman':
return 1
elif self.ct=='man':
return 2
elif self.ct=='captain':
return 3
s=[]
for n in range(x):
a=[n for n... | 0 |
527 | B | Error Correct System | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings *S* and *T* of equal length to be "similar". After a brief search on th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of strings *S* and *T*.
The second line contains string *S*.
The third line contains string *T*.
Each of the lines only contains lowercase Latin letters. | In the first line, print number *x* — the minimum possible Hamming distance between strings *S* and *T* if you swap at most one pair of letters in *S*.
In the second line, either print the indexes *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*, *i*<=≠<=*j*), if reaching the minimum possible distance is possible by swapping lett... | [
"9\npergament\npermanent\n",
"6\nwookie\ncookie\n",
"4\npetr\negor\n",
"6\ndouble\nbundle\n"
] | [
"1\n4 6\n",
"1\n-1 -1\n",
"2\n1 2\n",
"2\n4 1\n"
] | In the second test it is acceptable to print *i* = 2, *j* = 3. | 1,000 | [
{
"input": "9\npergament\npermanent",
"output": "1\n4 6"
},
{
"input": "6\nwookie\ncookie",
"output": "1\n-1 -1"
},
{
"input": "4\npetr\negor",
"output": "2\n1 2"
},
{
"input": "6\ndouble\nbundle",
"output": "2\n4 1"
},
{
"input": "1\na\na",
"output": "0\n-1 -... | 1,428,927,595 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 233 | 1,843,200 | n=int(input())
s,t=input(),input()
alpha=list('abcdefghijklmnopqrstuvwxyz')
spair,tpair=dict(),dict()
x=[1]*n
k=n
d=0
u,v=-1,-1
dd=dict()
for i in range(n):
if s[i]==t[i]:
k=k-1
else:
dd[s[i]+t[i]]=str(i+1)
for i in alpha:
for j in alpha:
if (i+j in dd) and... | Title: Error Correct System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write ... | ```python
n=int(input())
s,t=input(),input()
alpha=list('abcdefghijklmnopqrstuvwxyz')
spair,tpair=dict(),dict()
x=[1]*n
k=n
d=0
u,v=-1,-1
dd=dict()
for i in range(n):
if s[i]==t[i]:
k=k-1
else:
dd[s[i]+t[i]]=str(i+1)
for i in alpha:
for j in alpha:
if (i+j ... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings in the set.
Each of the next *n* lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct.
The total length of the strings doesn't exceed 105. | Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings. | [
"4\nmail\nai\nlru\ncf\n",
"3\nkek\npreceq\ncheburek\n"
] | [
"cfmailru\n",
"NO\n"
] | One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum. | 0 | [
{
"input": "4\nmail\nai\nlru\ncf",
"output": "cfmailru"
},
{
"input": "3\nkek\npreceq\ncheburek",
"output": "NO"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nab\nba",
"output": "NO"
},
{
"input": "2\nac\nbc",
"output": "NO"
},
{
"input": "2\nc... | 1,510,673,795 | 8,795 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 62 | 0 | n = int(input())
parts = set()
for i in range(n):
st = input()
lst = len(st)
bre = 0
for j in parts:
lj = len(j)
if lj>=lst:
if st in j:
bre = 1
break
for k in range(lst-1, 0,-1):
if st[:k] not in j: continue
if st[:k]==j[-k:] :
new = j[:-k] + st
parts.remove(j)... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is c... | ```python
n = int(input())
parts = set()
for i in range(n):
st = input()
lst = len(st)
bre = 0
for j in parts:
lj = len(j)
if lj>=lst:
if st in j:
bre = 1
break
for k in range(lst-1, 0,-1):
if st[:k] not in j: continue
if st[:k]==j[-k:] :
new = j[:-k] + st
parts... | -1 | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,655,927,162 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | [a,b]=map(int, input().split())
[c,d]=map(int, input().split())
x=abs (c-a)
y=abs (d-b)
print (min (x, y))
| Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
[a,b]=map(int, input().split())
[c,d]=map(int, input().split())
x=abs (c-a)
y=abs (d-b)
print (min (x, y))
``` | 0 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,652,090,485 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 62 | 62 | 0 | import sys
def the_way_to_home():
a,b=list(map(int,input().split()))
c=input()
j=b-1;ans=0
i=1
while i<a-1:
if i+j<a and c[i+j]=='1':
ans+=1
i+=j
j=b
else:
j-=1
if j<=0:
print(-1)
sys.exit(... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
import sys
def the_way_to_home():
a,b=list(map(int,input().split()))
c=input()
j=b-1;ans=0
i=1
while i<a-1:
if i+j<a and c[i+j]=='1':
ans+=1
i+=j
j=b
else:
j-=1
if j<=0:
print(-1)
... | 0 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,617,380,963 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 13 | 186 | 2,150,400 | s=list(str(input().lower()))
l=[]
for a in s:
if a=="a" or a=="e" or a=="i" or a=="o" or a=="u" or a=="y":
l.append(s.index(a))
if s[l[-1]+1]==" " or s[l[-1]+1]=="?":
print("YES")
else:
print("NO")
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s=list(str(input().lower()))
l=[]
for a in s:
if a=="a" or a=="e" or a=="i" or a=="o" or a=="u" or a=="y":
l.append(s.index(a))
if s[l[-1]+1]==" " or s[l[-1]+1]=="?":
print("YES")
else:
print("NO")
``` | -1 |
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The ... | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input":... | 1,588,906,295 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 498 | 10,137,600 | a, b = input().split()
a = int(a)
b = int(b)
temp = a - b
ans = []
for i in range(b):
ans.append(a)
a -= 1
add = 1
for i in range(temp):
ans.append(add)
add += 1
for item in ans:
print(item, end = " ") | Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutat... | ```python
a, b = input().split()
a = int(a)
b = int(b)
temp = a - b
ans = []
for i in range(b):
ans.append(a)
a -= 1
add = 1
for i in range(temp):
ans.append(add)
add += 1
for item in ans:
print(item, end = " ")
``` | 3 | |
626 | A | Robot Sequence | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s... | The first line of the input contains a single positive integer, *n* (1<=≤<=*n*<=≤<=200) — the number of commands.
The next line contains *n* characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code. | Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square. | [
"6\nURLLDR\n",
"4\nDLUU\n",
"7\nRLRLRLR\n"
] | [
"2\n",
"0\n",
"12\n"
] | In the first case, the entire source code works, as well as the "RL" substring in the second and third characters.
Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result. | 500 | [
{
"input": "6\nURLLDR",
"output": "2"
},
{
"input": "4\nDLUU",
"output": "0"
},
{
"input": "7\nRLRLRLR",
"output": "12"
},
{
"input": "1\nR",
"output": "0"
},
{
"input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL... | 1,487,962,072 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 77 | 4,608,000 | import sys
sys.stdin.readline()
line = sys.stdin.readline().strip()
count = 0
for i, elem in enumerate(line):
up, down, left, right = 0,0,0,0
for sub in line[i:]:
if sub == "U":
up += 1
if sub == "D":
down -= 1
if sub == "R":
right += 1
if s... | Title: Robot Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively... | ```python
import sys
sys.stdin.readline()
line = sys.stdin.readline().strip()
count = 0
for i, elem in enumerate(line):
up, down, left, right = 0,0,0,0
for sub in line[i:]:
if sub == "U":
up += 1
if sub == "D":
down -= 1
if sub == "R":
right += 1
... | 3 | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,676,833,402 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 3,072,000 | n=int(input())
lisp=[]
lisq=[]
for i in range(n):
a1,b1=map(int,input().split())
lisp.append(a1)
lisq.append(a2)
def check(lisp,lisq):
for i in range(len(lisp)-1):
if lisp[i]>=lisp[i+1]:
return 'Poor Alex'
for j in range(len(lisq)-1):
if lisq[i]<=lisp[i+1]:
... | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n=int(input())
lisp=[]
lisq=[]
for i in range(n):
a1,b1=map(int,input().split())
lisp.append(a1)
lisq.append(a2)
def check(lisp,lisq):
for i in range(len(lisp)-1):
if lisp[i]>=lisp[i+1]:
return 'Poor Alex'
for j in range(len(lisq)-1):
if lisq[i]<=lis... | -1 | |
21 | A | Jabber ID | PROGRAMMING | 1,900 | [
"implementation",
"strings"
] | A. Jabber ID | 0 | 256 | Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive. - <hostname> — is... | The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive. | Print YES or NO. | [
"[email protected]\n",
"[email protected]/contest.icpc/12\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "[email protected]",
"output": "YES"
},
{
"input": "[email protected]/contest.icpc/12",
"output": "NO"
},
{
"input": "[email protected]/abacaba",
"output": "YES"
},
{
"input": "@ops",
"output": "NO"
},
{
"input": "this-is-the-test",
"output": "N... | 1,585,327,488 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 307,200 | s=input()
a=s.split('@')
if len(a)!=2:
print("NO")
exit()
un=a[0].upper()
for c in un:
if not (c>="A" and c<="Z" or c=="_"):
print("NO")
exit()
if len(a)<1 or len(a)>16:
print("NO")
exit()
b=a[1].split("/")
if len(a)>2:
print("NO")
exit()
hn=b[0].upper()
if ... | Title: Jabber ID
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «... | ```python
s=input()
a=s.split('@')
if len(a)!=2:
print("NO")
exit()
un=a[0].upper()
for c in un:
if not (c>="A" and c<="Z" or c=="_"):
print("NO")
exit()
if len(a)<1 or len(a)>16:
print("NO")
exit()
b=a[1].split("/")
if len(a)>2:
print("NO")
exit()
hn=b[0].up... | -1 |
186 | B | Growing Mushrooms | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules ... | The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following... | Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate. | [
"2 3 3 50\n2 4\n4 2\n",
"4 1 1 1\n544 397\n280 101\n280 101\n693 970\n"
] | [
"1 15.00\n2 15.00\n",
"4 1656.07\n1 937.03\n2 379.99\n3 379.99\n"
] | - First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3. | 1,000 | [
{
"input": "2 3 3 50\n2 4\n4 2",
"output": "1 15.00\n2 15.00"
},
{
"input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970",
"output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99"
},
{
"input": "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737",... | 1,660,378,794 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | parti,time1,time2,dec=list(map(int,input().split()));dic={}
for i in range(1,parti+1):
speed1,speed2=list(map(int,input().split()))
len1=speed1*time1+speed2*time2*((100-dec)/100)
len2=speed2*time1+((100-dec)/100)*speed1*time2
if len2>len1:
if len2 in dic:
dic[len2]=dic[len2]+[... | Title: Growing Mushrooms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event br... | ```python
parti,time1,time2,dec=list(map(int,input().split()));dic={}
for i in range(1,parti+1):
speed1,speed2=list(map(int,input().split()))
len1=speed1*time1+speed2*time2*((100-dec)/100)
len2=speed2*time1+((100-dec)/100)*speed1*time2
if len2>len1:
if len2 in dic:
dic[len2]=d... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't ... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of points.
Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≤<=*x**i*<=≤<=109,<=1<=≤<=*w**i*<=≤<=109) — the coordinate and the weight of a point. All *x**i* are different. | Print a single number — the number of vertexes in the maximum clique of the given graph. | [
"4\n2 3\n3 1\n6 1\n0 2\n"
] | [
"3\n"
] | If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars!
The picture for the sample test. | 0 | [
{
"input": "4\n2 3\n3 1\n6 1\n0 2",
"output": "3"
},
{
"input": "1\n42 23",
"output": "1"
},
{
"input": "2\n1 5\n2 6",
"output": "1"
},
{
"input": "2\n1 5\n12 6",
"output": "2"
},
{
"input": "1\n0 1",
"output": "1"
},
{
"input": "1\n1000000000 10000000... | 1,609,855,807 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 686 | 18,432,000 | import sys
readline = sys.stdin.readline
def main():
N = int(input())
itvs = []
for _ in range(N):
x, w = map(int, input().split())
itvs.append((x - w, x + w))
itvs.sort(key=lambda x: x[1])
ans = 0
end = -(10**9 + 1)
for l, r in itvs:
if end <= l:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum siz... | ```python
import sys
readline = sys.stdin.readline
def main():
N = int(input())
itvs = []
for _ in range(N):
x, w = map(int, input().split())
itvs.append((x - w, x + w))
itvs.sort(key=lambda x: x[1])
ans = 0
end = -(10**9 + 1)
for l, r in itvs:
if end ... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert... | The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=<<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*... | Print a single integer number, the maximum number of letters that Nastya can remove. | [
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] | [
"3",
"4"
] | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https... | 0 | [
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1... | 1,489,140,670 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 4,608,000 | ss = list(input())
tt = list(input())
a = list(map(int,input().split(" ")))
kk = [0] * len(tt)
#print(ss,tt,a)
def pplace(ss, tt, kk, i1=0, i2=0):
while i1 < len(ss) and i2 < len(tt):
if ss[i1] == tt[i2]:
kk[i2] = i1
i2 += 1
i1 += 1
else:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nas... | ```python
ss = list(input())
tt = list(input())
a = list(map(int,input().split(" ")))
kk = [0] * len(tt)
#print(ss,tt,a)
def pplace(ss, tt, kk, i1=0, i2=0):
while i1 < len(ss) and i2 < len(tt):
if ss[i1] == tt[i2]:
kk[i2] = i1
i2 += 1
i1 += 1
else... | 0 | |
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different... | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input":... | 1,497,541,456 | 2,356 | PyPy 3 | OK | TESTS | 68 | 109 | 102,400 | def check(x, s):
k = 0
for i in str(x):
k += int(i)
return x - k >= s
n, s = map(int, input().split())
l = 0
r = n
while r - l > 1:
m = (l + r) // 2
if check(m, s):
r = m
else:
l = m
if check(r, s):
print(n - r + 1)
else:
print(0) | Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its... | ```python
def check(x, s):
k = 0
for i in str(x):
k += int(i)
return x - k >= s
n, s = map(int, input().split())
l = 0
r = n
while r - l > 1:
m = (l + r) // 2
if check(m, s):
r = m
else:
l = m
if check(r, s):
print(n - r + 1)
else:
print(0)
``... | 3 | |
274 | A | k-Multiple Free Set | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"sortings"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 500 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,609,039,521 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 15,462,400 | def binary_search(a, x):
l, r = 0, len(a)
pos = -1
while r - l > 0:
n = l + (r - l) // 2
if a[n] == x:
pos = n
break
elif a[n] > x:
r = n
else:
l = n
if r - l == 1:
break
return pos
n, ... | Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, ... | ```python
def binary_search(a, x):
l, r = 0, len(a)
pos = -1
while r - l > 0:
n = l + (r - l) // 2
if a[n] == x:
pos = n
break
elif a[n] > x:
r = n
else:
l = n
if r - l == 1:
break
return po... | 0 | |
794 | B | Cutting Carrot | PROGRAMMING | 1,200 | [
"geometry",
"math"
] | null | null | Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area.
Formally, the carrot can be viewed as an isosceles tri... | The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105). | The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=<<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=-<=1<=<<=*h* must hold.
Your output will be considered correc... | [
"3 2\n",
"2 100000\n"
] | [
"1.154700538379 1.632993161855\n",
"70710.678118654752\n"
] | Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle). | 1,000 | [
{
"input": "3 2",
"output": "1.154700538379 1.632993161855"
},
{
"input": "2 100000",
"output": "70710.678118654752"
},
{
"input": "1000 100000",
"output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8... | 1,494,669,519 | 1,419 | Python 3 | OK | TESTS | 31 | 62 | 307,200 | import sys
from math import sqrt
def main():
n,h=list(map(int,sys.stdin.readline().split()))
sn=sqrt(n)
result=[]
for i in range(n-1):
result.append(sqrt(i+1)*h/sn)
sys.stdout.write(' '.join(map(str,result))+'\n')
main()
| Title: Cutting Carrot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cu... | ```python
import sys
from math import sqrt
def main():
n,h=list(map(int,sys.stdin.readline().split()))
sn=sqrt(n)
result=[]
for i in range(n-1):
result.append(sqrt(i+1)*h/sn)
sys.stdout.write(' '.join(map(str,result))+'\n')
main()
``` | 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,681,300,415 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | def main():
n , m = list(map( int ,input().split(' ')))
# s = int(f'1{(n-1)*"0"}')
print(s)
# e = int(f'9{(n-1)*"9"}')
print(e)
for i in range (s,e+1) :
if i % m == 0 :
print(i)
return
print(-1)
main() | 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
def main():
n , m = list(map( int ,input().split(' ')))
# s = int(f'1{(n-1)*"0"}')
print(s)
# e = int(f'9{(n-1)*"9"}')
print(e)
for i in range (s,e+1) :
if i % m == 0 :
print(i)
return
print(-1)
main()
``` | -1 | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,647,171,318 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 62 | 0 | n,m=[int(x) for x in input().split()]
have=n
use=0
day=1
while have>0:
use+=1
if day%m!=0:
have=have-1
day+=1
print(use)
| Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
n,m=[int(x) for x in input().split()]
have=n
use=0
day=1
while have>0:
use+=1
if day%m!=0:
have=have-1
day+=1
print(use)
``` | 3 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,662,171,295 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 6,348,800 | (n, a, b) = [int(x) for x in input().split(" ")]
s = [int(y) for y in input().split(" ")]
max_sum = (s[0] * a) / b
r = 0
total_sum = sum(s)
while total_sum > max_sum:
l = max(s[1:])
s.remove(l)
total_sum -= l
r += 1
print(r)
| Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
(n, a, b) = [int(x) for x in input().split(" ")]
s = [int(y) for y in input().split(" ")]
max_sum = (s[0] * a) / b
r = 0
total_sum = sum(s)
while total_sum > max_sum:
l = max(s[1:])
s.remove(l)
total_sum -= l
r += 1
print(r)
``` | 0 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,697,905,439 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 1,024,000 | q = [ int(x) for x in input().split()]
a=q[0]
b=q[1]
rok=0
while a < b :
a=a*3
b=b*3
rok = rok +1
print(rok) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
q = [ int(x) for x in input().split()]
a=q[0]
b=q[1]
rok=0
while a < b :
a=a*3
b=b*3
rok = rok +1
print(rok)
``` | 0 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,584,934,192 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 109 | 307,200 | def countPossibleWord(text):
t = count_char(text,'t')
i = count_char(text,'i')
base = min([t,i])
while 1:
e = count_char(text,'e')
n = count_char(text,'n')
if not e >= base * 3:
base = base - 1
continue
elif not n >= (base*2) + 1:
... | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
def countPossibleWord(text):
t = count_char(text,'t')
i = count_char(text,'i')
base = min([t,i])
while 1:
e = count_char(text,'e')
n = count_char(text,'n')
if not e >= base * 3:
base = base - 1
continue
elif not n >= (base*2) + ... | 0 | |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,516,155,105 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 5,939,200 | #http://codeforces.com/problemset/problem/387/B
def inp():
return map(int, input().split())
n,m=inp()
a=list(inp())
b=list(inp())
i,j=0,0
while ((i < n) & (j < m)):
if (b[j] >= a[i]):
i+=1
j+=1
print(n-i) | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
#http://codeforces.com/problemset/problem/387/B
def inp():
return map(int, input().split())
n,m=inp()
a=list(inp())
b=list(inp())
i,j=0,0
while ((i < n) & (j < m)):
if (b[j] >= a[i]):
i+=1
j+=1
print(n-i)
``` | 3 | |
49 | B | Sum | PROGRAMMING | 1,500 | [
"math"
] | B. Sum | 2 | 256 | Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base *p* and regard the... | The first letter contains two space-separated numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1000) which represent the given summands. | Print a single number — the length of the longest answer. | [
"78 87\n",
"1 1\n"
] | [
"3\n",
"2\n"
] | none | 1,000 | [
{
"input": "78 87",
"output": "3"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "9 7",
"output": "2"
},
{
"input": "11 11",
"output": "3"
},
{
"input": "43 21",
"output": "3"
},
{
"input": "84 89",
"output": "3"
},
{
"input": "12 34",
... | 1,644,766,305 | 2,147,483,647 | PyPy 3 | OK | TESTS | 67 | 154 | 0 | import sys
input = sys.stdin.readline
a, b = map(int, input().split())
s = set()
for i in list(str(a)):
s.add(int(i))
for i in list(str(b)):
s.add(int(i))
m = 0
for i in s:
m = max(m, i)
m += 1
ans = 0
for i in range(m, 20):
a0, b0 = list(str(a)), list(str(b))
a1, b1 = 0, 0
j =... | Title: Sum
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positiona... | ```python
import sys
input = sys.stdin.readline
a, b = map(int, input().split())
s = set()
for i in list(str(a)):
s.add(int(i))
for i in list(str(b)):
s.add(int(i))
m = 0
for i in s:
m = max(m, i)
m += 1
ans = 0
for i in range(m, 20):
a0, b0 = list(str(a)), list(str(b))
a1, b1 = 0, ... | 3.9615 |
610 | B | Vika and Squares | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of jars with colors Vika has.
The second line of the input contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is equal to the number of liters of paint in the *i*-th jar, i.e. th... | The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above. | [
"5\n2 4 2 3 3\n",
"3\n5 5 5\n",
"6\n10 10 10 1 10 10\n"
] | [
"12\n",
"15\n",
"11\n"
] | In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.
In the second sample Vika can start to paint using any color.
In the third sample Vika should start painting using color number 5... | 1,000 | [
{
"input": "5\n2 4 2 3 3",
"output": "12"
},
{
"input": "3\n5 5 5",
"output": "15"
},
{
"input": "6\n10 10 10 1 10 10",
"output": "11"
},
{
"input": "1\n167959139",
"output": "167959139"
},
{
"input": "10\n896619242 805194919 844752453 848347723 816995848 85681361... | 1,595,311,738 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 20,172,800 | n=int(input())
s=list(map(int,input().split()))
mi=min(s)
ct,ma=0,0
for i in range(n):
if(s[i]!=mi):
ct+=1
else:
if(ct>ma):
ma=ct
ct=1
if(s.count(mi)==n):
print(mi*n)
elif(s.count(mi)==1):
print((mi*(2*n))-1)
else:
print((mi*(n))+ma) | Title: Vika and Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of... | ```python
n=int(input())
s=list(map(int,input().split()))
mi=min(s)
ct,ma=0,0
for i in range(n):
if(s[i]!=mi):
ct+=1
else:
if(ct>ma):
ma=ct
ct=1
if(s.count(mi)==n):
print(mi*n)
elif(s.count(mi)==1):
print((mi*(2*n))-1)
else:
print((mi*(n))+ma)
``` | 0 | |
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec... | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"... | 1,612,973,370 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 108 | 1,228,800 | n = int(input())
s = input()[::-1]
ans = ['' for i in range(n)]
cnt = 0
for i in range(0,n-1,2):
ans[cnt] = s[i]
ans[n-cnt-1] = s[i+1]
cnt+=1
if n%2!=0:
ans[n//2] = s[n-1]
print(''.join(ans[::-1]))
| Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the... | ```python
n = int(input())
s = input()[::-1]
ans = ['' for i in range(n)]
cnt = 0
for i in range(0,n-1,2):
ans[cnt] = s[i]
ans[n-cnt-1] = s[i+1]
cnt+=1
if n%2!=0:
ans[n//2] = s[n-1]
print(''.join(ans[::-1]))
``` | 3 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,698,220,538 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 60 | 0 |
n, k, l, c, d, p, nl, np=map(int,input().split())
print(min(k*l//nl,c*d,np*p)//n)
| Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n, k, l, c, d, p, nl, np=map(int,input().split())
print(min(k*l//nl,c*d,np*p)//n)
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,687,551,227 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | inputs = list(input().split())
words = inputs[1:]
for i in words:
if len(i) <= 10:
print(i)
else:
print(f"{i[0]}{len(i)}{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
inputs = list(input().split())
words = inputs[1:]
for i in words:
if len(i) <= 10:
print(i)
else:
print(f"{i[0]}{len(i)}{i[-1]}")
``` | 0 |
995 | B | Suit and Tie | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"math"
] | null | null | Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the pic... | The first line contains a single integer $n$ ($1 \le n \le 100$), the number of pairs of people.
The second line contains $2n$ integers $a_1, a_2, \dots, a_{2n}$. For each $i$ with $1 \le i \le n$, $i$ appears exactly twice. If $a_j = a_k = i$, that means that the $j$-th and $k$-th people in the line form a couple. | Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions. | [
"4\n1 1 2 3 3 2 4 4\n",
"3\n1 1 2 2 3 3\n",
"3\n3 1 2 3 1 2\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first sample case, we can transform $1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$ in two steps. Note that the sequence $1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$ also works in the same number of steps.
The second sample case already satisfies the constr... | 750 | [
{
"input": "4\n1 1 2 3 3 2 4 4",
"output": "2"
},
{
"input": "3\n1 1 2 2 3 3",
"output": "0"
},
{
"input": "3\n3 1 2 3 1 2",
"output": "3"
},
{
"input": "8\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4",
"output": "27"
},
{
"input": "2\n1 2 1 2",
"output": "1"
},
{
... | 1,609,684,384 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 204,800 | n = int(input())
pairs = [int(i) for i in input().split(" ")]
yes=True
##i=0
output = 0
##while i<=len(pairs)-2:
for i in range(((2*n))-2):
if pairs.count(pairs[0+i])==2:
if pairs[0+i]==pairs[1+i]:
i+=2
else:
a = pairs[0+i]
pairs[0+i] = pairs[1+i]
p... | Title: Suit and Tie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the o... | ```python
n = int(input())
pairs = [int(i) for i in input().split(" ")]
yes=True
##i=0
output = 0
##while i<=len(pairs)-2:
for i in range(((2*n))-2):
if pairs.count(pairs[0+i])==2:
if pairs[0+i]==pairs[1+i]:
i+=2
else:
a = pairs[0+i]
pairs[0+i] = pairs[1+i]
... | 0 | |
274 | A | k-Multiple Free Set | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"sortings"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 500 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,659,387,192 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n, k = map(int, input().split())
d = set()
l = list(map(int, input().split()))
count = n
for val in l:
if val//k in d:
count -= 1
else:
d.add(val//k)
print(count-1)
| Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, ... | ```python
n, k = map(int, input().split())
d = set()
l = list(map(int, input().split()))
count = n
for val in l:
if val//k in d:
count -= 1
else:
d.add(val//k)
print(count-1)
``` | 0 | |
315 | B | Sereja and Array | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. In... | The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array.
Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is i... | For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input. | [
"10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n"
] | [
"2\n9\n11\n20\n30\n40\n39\n"
] | none | 1,000 | [
{
"input": "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9",
"output": "2\n9\n11\n20\n30\n40\n39"
},
{
"input": "1 3\n1\n1 1 2\n2 1\n3 1",
"output": "3"
},
{
"input": "1 1\n1\n3 1",
"output": "1"
},
{
"input": "6 6\n202714501 613423... | 1,606,625,209 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 12,185,600 | n,m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
for mm in range(m):
entrada = [int(x) for x in input().split()]
if entrada[0] == 1:
a[entrada[1]-1] = entrada[2]
elif entrada[0] == 2:
for i in range(n):
a[i] += entrada[1]
else:
print(a[entrada[1]-1])
... | Title: Sereja and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*... | ```python
n,m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
for mm in range(m):
entrada = [int(x) for x in input().split()]
if entrada[0] == 1:
a[entrada[1]-1] = entrada[2]
elif entrada[0] == 2:
for i in range(n):
a[i] += entrada[1]
else:
print(a[entrada[1]-1])
... | 0 | |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,515,683,419 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 154 | 5,734,400 | import sys
n = int(input())
ans = [0 for _ in range(n)]
iter = 0
for i in range( 0 , n - 1 ,2 ):
ans[i], ans[i + 1] = iter + 1, n - iter
iter = iter + 1
if n % 2: ans[n - 1] = n // 2 + 1
for i in range(n):
sys.stdout.write(str(ans[i]) + ' ')
print() | Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ... | ```python
import sys
n = int(input())
ans = [0 for _ in range(n)]
iter = 0
for i in range( 0 , n - 1 ,2 ):
ans[i], ans[i + 1] = iter + 1, n - iter
iter = iter + 1
if n % 2: ans[n - 1] = n // 2 + 1
for i in range(n):
sys.stdout.write(str(ans[i]) + ' ')
print()
``` | 3.950819 |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,685,594,567 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n = int(input())
array = [int(x) for x in input().split(" ")]
seriji = 0
dima = 0
left = 0
right = n-1
serijis_turn = True
while(left<=right):
choose=0
if array[left]>array[right]:
choose = array[left]
left+=1
else:
choose = array[right]
right-=1
if serijis... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n = int(input())
array = [int(x) for x in input().split(" ")]
seriji = 0
dima = 0
left = 0
right = n-1
serijis_turn = True
while(left<=right):
choose=0
if array[left]>array[right]:
choose = array[left]
left+=1
else:
choose = array[right]
right-=1
... | 3 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,696,062,552 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 |
parameters = input("Enter two integers(between 1 and 1000):")
if not parameters.find(" ")>=1 or not parameters[0:parameters.find(" ")].isdigit() or not parameters[parameters.find(" ")+1:].isdigit() or not 1<=int(parameters[0:parameters.find(" ")])<=1000 or not 1<=int(parameters[parameters.find(" ")+1:])<=1000:
... | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
parameters = input("Enter two integers(between 1 and 1000):")
if not parameters.find(" ")>=1 or not parameters[0:parameters.find(" ")].isdigit() or not parameters[parameters.find(" ")+1:].isdigit() or not 1<=int(parameters[0:parameters.find(" ")])<=1000 or not 1<=int(parameters[parameters.find(" ")+1:])<=1... | -1 | |
12 | B | Correct Solution? | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | B. Correct Solution? | 2 | 256 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe... | The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes. | Print OK if Bob's answer is correct and WRONG_ANSWER otherwise. | [
"3310\n1033\n",
"4\n5\n"
] | [
"OK\n",
"WRONG_ANSWER\n"
] | none | 0 | [
{
"input": "3310\n1033",
"output": "OK"
},
{
"input": "4\n5",
"output": "WRONG_ANSWER"
},
{
"input": "40\n04",
"output": "WRONG_ANSWER"
},
{
"input": "12\n12",
"output": "OK"
},
{
"input": "432\n234",
"output": "OK"
},
{
"input": "17109\n01179",
"o... | 1,590,933,552 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 186 | 0 | # your code goes here
n=int(input())
m=int(input())
n=list(str(n))
m=list(str(m))
n.sort()
m.sort()
if(n==m):
print("OK")
else:
print("WRONG_ANSWER") | Title: Correct Solution?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuf... | ```python
# your code goes here
n=int(input())
m=int(input())
n=list(str(n))
m=list(str(m))
n.sort()
m.sort()
if(n==m):
print("OK")
else:
print("WRONG_ANSWER")
``` | 0 |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,656,793,608 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 109 | 512,000 | n=int(input())
l=[]
res=0
for i in range(n):
l.append(list(input()))
y=list(zip(*l))
#print(y)
for i in range(n):
x=l[i].count('C')
b=y[i].count('C')
res+=((x-1)*x)//2+((b-1)*b)//2
print(res)
#EXERCISES WITH MATRIX
#See this exercise when you have problems with matrices
#How ... | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
n=int(input())
l=[]
res=0
for i in range(n):
l.append(list(input()))
y=list(zip(*l))
#print(y)
for i in range(n):
x=l[i].count('C')
b=y[i].count('C')
res+=((x-1)*x)//2+((b-1)*b)//2
print(res)
#EXERCISES WITH MATRIX
#See this exercise when you have problems with matri... | 3 | |
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 1,594,576,221 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 6,656,000 | # 11B - Jumping Jack
x = abs(int(input()))
# -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
step = 1
jump_count = 0
position = 0
while position < x:
position += step
# print(position)
step += 1
jump_count += 1
if position == x:
print (jump_count)
else:
while (position - x) % 2 != 0:
... | Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each ... | ```python
# 11B - Jumping Jack
x = abs(int(input()))
# -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
step = 1
jump_count = 0
position = 0
while position < x:
position += step
# print(position)
step += 1
jump_count += 1
if position == x:
print (jump_count)
else:
while (position - x) ... | -1 |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,674,110,046 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 124 | 0 | R=lambda:map(int,input().split())
a,b,c=R()
x=min(a,min(b,c))
print(x+(a-x)//3+(b-x)//3+(c-x)//3) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
R=lambda:map(int,input().split())
a,b,c=R()
x=min(a,min(b,c))
print(x+(a-x)//3+(b-x)//3+(c-x)//3)
``` | 0 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,619,327,095 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 77 | 409,600 | from collections import Counter
n=int(input())
s=input()
if(len(s)>26):
print(-1)
else:
c=Counter(s)
p=c.values()
print(sum(p)-len(p))
| Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
from collections import Counter
n=int(input())
s=input()
if(len(s)>26):
print(-1)
else:
c=Counter(s)
p=c.values()
print(sum(p)-len(p))
``` | 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,720,258 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | #罗誉城 2300011776
n1=input()
n2=input()
if n1<n2:
print(-1)
elif n1>n2:
print(1)
else:
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
#罗誉城 2300011776
n1=input()
n2=input()
if n1<n2:
print(-1)
elif n1>n2:
print(1)
else:
print(0)
``` | 0 |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,699,328,152 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | input();A=[*map(int,input().split())];a=sum(A);b=a/3;c=2*b;m=n=t=0
for i in A:m+=i;n+=m==b;t+=n*(m==c)
print([t,n*(n-1)*(n-2)//6][a==0]) | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
input();A=[*map(int,input().split())];a=sum(A);b=a/3;c=2*b;m=n=t=0
for i in A:m+=i;n+=m==b;t+=n*(m==c)
print([t,n*(n-1)*(n-2)//6][a==0])
``` | 0 | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,694,844,535 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 102,400 | stations = input()
flags = input()
flags2 = input()
seen = True; seenrev = True
for i in range(len(stations)):
if stations[i] == flags[0]:
for j in flags:
seen = True
if stations[i] == j:
flagsend = i
continue
else:
... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
stations = input()
flags = input()
flags2 = input()
seen = True; seenrev = True
for i in range(len(stations)):
if stations[i] == flags[0]:
for j in flags:
seen = True
if stations[i] == j:
flagsend = i
continue
else:
... | 0 |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,582,669,764 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 48 | 248 | 512,000 | import sys
lst1=[]
z=list(map(int,input().split()))
for t in range(z[1]):
x=list(map(int,input().split()))
lst1.extend(x)
my=list(range(1,z[0]+1))
ans=0
s=0
if z[1]==0:
print(0)
sys.exit(0)
while 1:
hold=[]
for j in my:
if lst1.count(j)==1: ... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
import sys
lst1=[]
z=list(map(int,input().split()))
for t in range(z[1]):
x=list(map(int,input().split()))
lst1.extend(x)
my=list(range(1,z[0]+1))
ans=0
s=0
if z[1]==0:
print(0)
sys.exit(0)
while 1:
hold=[]
for j in my:
if lst1.count(j)==... | -1 | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,628,197,432 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 186 | 6,758,400 | k = input().strip()
a = k.split('1')
l = ['', '4', '44']
if k[0] == '4':
print('NO')
exit(0)
for i in a:
if i not in l:
print('NO')
exit(0)
print('YES')
| Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
k = input().strip()
a = k.split('1')
l = ['', '4', '44']
if k[0] == '4':
print('NO')
exit(0)
for i in a:
if i not in l:
print('NO')
exit(0)
print('YES')
``` | 3 | |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,653,413,033 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | # Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
x = input().strip()
x = x.split(" ")
l = int(x[0])
r = int(x[1])
n = int(x[2])
ans = []
k = 0
while (pow(n,k)<=r):
if (pow(n,k)>=l):
ans.append(pow(n,k))
k = k+1
if (len(an... | Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
x = input().strip()
x = x.split(" ")
l = int(x[0])
r = int(x[1])
n = int(x[2])
ans = []
k = 0
while (pow(n,k)<=r):
if (pow(n,k)>=l):
ans.append(pow(n,k))
k = k+1
... | 0 | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,549,390,124 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 93 | 0 | n=input()
print(25*len(n)+26) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
n=input()
print(25*len(n)+26)
``` | 3 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,552,551,535 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | n = int(input())
print(-1 if n > 26 else n - len(set(t))) | Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
n = int(input())
print(-1 if n > 26 else n - len(set(t)))
``` | -1 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,694,085,766 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | k, n, w=map(int,input().split())
sum=0
for i in range(1,w+1):
sum = sum + (k*i)
borrow=sum-n
print(borrow) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k, n, w=map(int,input().split())
sum=0
for i in range(1,w+1):
sum = sum + (k*i)
borrow=sum-n
print(borrow)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.