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
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,634,155,577
2,147,483,647
Python 3
OK
TESTS
33
62
0
a, b, c=map(int,input().split()) d, e, f=map(int,input().split()) g, h, i=map(int,input().split()) A,B,C=1, 1, 1 D,E,F=1,1,1 G,H,I=1, 1, 1 if a+b+d==0: A=1 elif (a+b+d)%2!=0: A=0 else: A=1 if a+b+c+e==0: B=1 elif (a+b+c+e)%2!=0: B=0 else: B=1 if b+c+f==0: C=1 ...
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 a, b, c=map(int,input().split()) d, e, f=map(int,input().split()) g, h, i=map(int,input().split()) A,B,C=1, 1, 1 D,E,F=1,1,1 G,H,I=1, 1, 1 if a+b+d==0: A=1 elif (a+b+d)%2!=0: A=0 else: A=1 if a+b+c+e==0: B=1 elif (a+b+c+e)%2!=0: B=0 else: B=1 if b+c+f==0: ...
3
125
A
Measuring Lengths in Baden
PROGRAMMING
1,400
[ "math" ]
null
null
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches. You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The ...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=10000).
Print two non-negative space-separated integers *a* and *b*, where *a* is the numbers of feet and *b* is the number of inches.
[ "42\n", "5\n" ]
[ "1 2\n", "0 2\n" ]
none
1,000
[ { "input": "42", "output": "1 2" }, { "input": "5", "output": "0 2" }, { "input": "24", "output": "0 8" }, { "input": "1", "output": "0 0" }, { "input": "2", "output": "0 1" }, { "input": "3", "output": "0 1" }, { "input": "4", "output"...
1,549,653,969
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
186
0
from math import ceil n = int(input()) print(str(n//36)+' '+str(ceil((n%36)/3)))
Title: Measuring Lengths in Baden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches. You are given a length equa...
```python from math import ceil n = int(input()) print(str(n//36)+' '+str(ceil((n%36)/3))) ```
0
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co...
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "Y...
1,633,450,779
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
9
248
24,371,200
s1=str(input()) s2=str(input()) l_1=[] l_2=[] l_1[:0]=s1 l_2[:0]=s2 p_1=sorted(l_1) p_2=sorted(l_2) if(len(l_1)!=len(l_2)): print("NO") else: flag=False for i in range (0,len(l_1)): if(p_1[i]!=p_2[i]): print("NO") flag=True break if(flag==Fa...
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ...
```python s1=str(input()) s2=str(input()) l_1=[] l_2=[] l_1[:0]=s1 l_2[:0]=s2 p_1=sorted(l_1) p_2=sorted(l_2) if(len(l_1)!=len(l_2)): print("NO") else: flag=False for i in range (0,len(l_1)): if(p_1[i]!=p_2[i]): print("NO") flag=True break i...
0
975
C
Valhalla Siege
PROGRAMMING
1,400
[ "binary search" ]
null
null
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T...
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths. The third line contains $q$ integers $k_1, k_2,...
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
[ "5 5\n1 2 1 2 1\n3 10 1 1 1\n", "4 4\n1 2 3 4\n9 1 10 6\n" ]
[ "3\n5\n4\n4\n3\n", "1\n4\n4\n1\n" ]
In the first example: - after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr...
1,500
[ { "input": "5 5\n1 2 1 2 1\n3 10 1 1 1", "output": "3\n5\n4\n4\n3" }, { "input": "4 4\n1 2 3 4\n9 1 10 6", "output": "1\n4\n4\n1" }, { "input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5", "output": "10\n10\n5" }, { "input": "1 1\n56563128\n897699770", "output": "1" }, { ...
1,609,230,572
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
15,052,800
def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def MAP2():return map(float,input().split()) def LIST(): return list(map(int, input().split())) def STRING(): return input() from heapq import heappop , heappush from bisect import * from collections imp...
Title: Valhalla Siege Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line ...
```python def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def MAP2():return map(float,input().split()) def LIST(): return list(map(int, input().split())) def STRING(): return input() from heapq import heappop , heappush from bisect import * from colle...
0
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,634,078,323
2,147,483,647
Python 3
OK
TESTS
10
61
0
n=int(input()) a=[1,1,1,1,1,1,1,1,1,1,1] for _ in range(1,n): for i in range(1,n): a[i]=a[i]+a[i-1] print(max(a))
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python n=int(input()) a=[1,1,1,1,1,1,1,1,1,1,1] for _ in range(1,n): for i in range(1,n): a[i]=a[i]+a[i-1] print(max(a)) ```
3
687
B
Remainders Game
PROGRAMMING
1,800
[ "chinese remainder theorem", "math", "number theory" ]
null
null
Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000).
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise.
[ "4 5\n2 3 5 12\n", "2 7\n2 3\n" ]
[ "Yes\n", "No\n" ]
In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <img align="middle" ...
1,000
[ { "input": "4 5\n2 3 5 12", "output": "Yes" }, { "input": "2 7\n2 3", "output": "No" }, { "input": "1 6\n8", "output": "No" }, { "input": "2 3\n9 4", "output": "Yes" }, { "input": "4 16\n19 16 13 9", "output": "Yes" }, { "input": "5 10\n5 16 19 9 17", ...
1,578,304,435
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
140
0
def gcd(a, b): if(a < b): a, b = b, a if b == 0: return a return gcd(b, a % b) def lcm(a, b): return (a // gcd(a, b)) * b; n, k = map(int, input().split()) a = list(map(int, input().split())) c = 1 for x in a: c = lcm(x, c) if(gcd(k, c) == 1): print("No") else: print("Yes")...
Title: Remainders Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*...
```python def gcd(a, b): if(a < b): a, b = b, a if b == 0: return a return gcd(b, a % b) def lcm(a, b): return (a // gcd(a, b)) * b; n, k = map(int, input().split()) a = list(map(int, input().split())) c = 1 for x in a: c = lcm(x, c) if(gcd(k, c) == 1): print("No") else: pr...
0
557
B
Pasha and Tea
PROGRAMMING
1,500
[ "constructive algorithms", "implementation", "math", "sortings" ]
null
null
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water. It turned out that among Pasha's friends there are exactly *n* boys a...
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters. The second line of the input contains the sequence of integers *...
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "2 4\n1 1 1 1\n", "3 18\n4 4 4 2 2 2\n", "1 5\n2 3\n" ]
[ "3", "18", "4.5" ]
Pasha also has candies that he is going to give to girls but that is another task...
1,000
[ { "input": "2 4\n1 1 1 1", "output": "3.0000000000" }, { "input": "3 18\n4 4 4 2 2 2", "output": "18.0000000000" }, { "input": "1 5\n2 3", "output": "4.5000000000" }, { "input": "1 1\n1000000000 1000000000", "output": "1.0000000000" }, { "input": "4 1000000000\n1 ...
1,445,594,686
2,147,483,647
Python 3
OK
TESTS
50
327
17,305,600
from sys import stdin from sys import exit live = True if not live: stdin = open('data.in', 'r') n, w = list(map(int, stdin.readline().strip().split())) cups = list(map(int, stdin.readline().strip().split())) maxx = w / (3 * n) cups = sorted(cups, reverse = True) for it in range(n): maxx = min(maxx, cup...
Title: Pasha and Tea Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ...
```python from sys import stdin from sys import exit live = True if not live: stdin = open('data.in', 'r') n, w = list(map(int, stdin.readline().strip().split())) cups = list(map(int, stdin.readline().strip().split())) maxx = w / (3 * n) cups = sorted(cups, reverse = True) for it in range(n): maxx = min...
3
33
A
What is for dinner?
PROGRAMMING
1,200
[ "greedy", "implementation" ]
A. What is for dinner?
2
256
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where bel...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
[ "4 3 18\n2 3\n1 2\n3 6\n2 3\n", "2 2 13\n1 13\n2 12\n" ]
[ "11\n", "13\n" ]
none
500
[ { "input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11" }, { "input": "2 2 13\n1 13\n2 12", "output": "13" }, { "input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3", "output": "8" }, { "input": "1 1 0\n1 3", "output": "0" }, { "input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 1...
1,591,871,868
2,147,483,647
Python 3
OK
TESTS
31
218
0
n,m,k=map(int,input().split()) a=[0]+[10**6]*m for _ in range(n): x,y=map(int,input().split()) if a[x]>y:a[x]=y print(min(sum(a),k))
Title: What is for dinner? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that...
```python n,m,k=map(int,input().split()) a=[0]+[10**6]*m for _ in range(n): x,y=map(int,input().split()) if a[x]>y:a[x]=y print(min(sum(a),k)) ```
3.9455
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "outpu...
1,589,362,767
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
6,963,200
n=int(input()) f=0 y=0 while(1): if (n-7*y)<0: break x=((n-(7*y))/4) if x==int(x): f=1 break y+=1 if f==0: print(-1) else: x=int(x) for i in range(x): print(4,end="") for i in range(y): print(7,end="")
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n=int(input()) f=0 y=0 while(1): if (n-7*y)<0: break x=((n-(7*y))/4) if x==int(x): f=1 break y+=1 if f==0: print(-1) else: x=int(x) for i in range(x): print(4,end="") for i in range(y): print(7,end="") ```
0
472
C
Design Tutorial: Make It Nondeterministic
PROGRAMMING
1,400
[ "greedy" ]
null
null
A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull. Let's try to make a new task. Firstly we will use the following task. There are *n* people, sort them by their name. It is just an ordi...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of people. The next *n* lines each contains two strings. The *i*-th line contains strings *f**i* and *s**i* (1<=≤<=|*f**i*|,<=|*s**i*|<=≤<=50) — the first name and last name of the *i*-th person. Each string consists only of lowercase English lett...
If it is possible, output "YES", otherwise output "NO".
[ "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3\n", "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2\n", "2\ngalileo galilei\nnicolaus copernicus\n2 1\n", "10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma...
[ "NO\n", "YES\n", "YES\n", "NO\n", "YES\n" ]
In example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last. In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright.
1,500
[ { "input": "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3", "output": "NO" }, { "input": "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2", "output": "YES" }, { "input": "2\ngalileo galilei\nnicolaus copernicus\n2 1", "output": "YES" }, { "input": "1...
1,678,748,439
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
2,764,800
import sys input = sys.stdin.read().split('\n') num_people = int(input.pop(0)) order = [int(x) - 1 for x in input.pop(num_people).split()] first_names = [] last_names = [] for person in input: person_arr = person.split() first_names.append(person_arr[0]) last_names.append(person_arr[1]) prev = "" valid = ...
Title: Design Tutorial: Make It Nondeterministic Time Limit: None seconds Memory Limit: None megabytes Problem Description: A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull. Let's tr...
```python import sys input = sys.stdin.read().split('\n') num_people = int(input.pop(0)) order = [int(x) - 1 for x in input.pop(num_people).split()] first_names = [] last_names = [] for person in input: person_arr = person.split() first_names.append(person_arr[0]) last_names.append(person_arr[1]) prev = "...
-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,686,803,372
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
35
62
0
a=int(input()) c=sorted(list(map(int,input().split())))[::-1] summa,i=0,0 ok=True while summa<a: summa+=c[i] i+=1 if i==len(c): print(-1) ok=False break if ok==True: 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()) c=sorted(list(map(int,input().split())))[::-1] summa,i=0,0 ok=True while summa<a: summa+=c[i] i+=1 if i==len(c): print(-1) ok=False break if ok==True: print(i) ```
0
450
A
Jzzhu and Children
PROGRAMMING
1,000
[ "implementation" ]
null
null
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of...
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output a single integer, representing the number of the last child.
[ "5 2\n1 3 1 4 2\n", "6 4\n1 1 2 2 3 3\n" ]
[ "4\n", "6\n" ]
Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en...
500
[ { "input": "5 2\n1 3 1 4 2", "output": "4" }, { "input": "6 4\n1 1 2 2 3 3", "output": "6" }, { "input": "7 3\n6 1 5 4 2 3 1", "output": "4" }, { "input": "10 5\n2 7 3 6 2 5 1 3 4 5", "output": "4" }, { "input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18...
1,664,239,986
2,147,483,647
Python 3
OK
TESTS
49
46
0
import math (n, m)= map(int, input().split(" ")) a= list(map(int, str(input()).split(" "))) b= [] for i in range(n): b.append(math.ceil(a[i]/m)) ma= n-1 for j in range(n-1,-1,-1): if b[j]>b[ma]: ma=j print(ma+1)
Title: Jzzhu and Children Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line ...
```python import math (n, m)= map(int, input().split(" ")) a= list(map(int, str(input()).split(" "))) b= [] for i in range(n): b.append(math.ceil(a[i]/m)) ma= n-1 for j in range(n-1,-1,-1): if b[j]>b[ma]: ma=j print(ma+1) ```
3
743
A
Vladik and flights
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows *n* airports. All the airports are located on a straight line. Each airport has u...
The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length *n*, which consists only of characters...
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
[ "4 1 4\n1010\n", "5 5 2\n10110\n" ]
[ "1", "0" ]
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th...
500
[ { "input": "4 1 4\n1010", "output": "1" }, { "input": "5 5 2\n10110", "output": "0" }, { "input": "10 9 5\n1011111001", "output": "1" }, { "input": "7 3 7\n1110111", "output": "0" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 3 3\n100101101...
1,489,469,952
2,147,483,647
Python 3
OK
TESTS
56
62
4,812,800
from sys import stdin,stdout a,x,y=list(map(int,input().split())) length=input() print(0 if length[x-1]==length[y-1] else 1 )
Title: Vladik and flights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the o...
```python from sys import stdin,stdout a,x,y=list(map(int,input().split())) length=input() print(0 if length[x-1]==length[y-1] else 1 ) ```
3
689
A
Mike and Cellphone
PROGRAMMING
1,400
[ "brute force", "constructive algorithms", "implementation" ]
null
null
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: Together with his old phone, he lost all his contacts and ...
The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=9) — the number of digits in the phone number that Mike put in. The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in.
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line.
[ "3\n586\n", "2\n09\n", "9\n123456789\n", "3\n911\n" ]
[ "NO\n", "NO\n", "YES\n", "YES\n" ]
You can find the picture clarifying the first sample case in the statement above.
500
[ { "input": "3\n586", "output": "NO" }, { "input": "2\n09", "output": "NO" }, { "input": "9\n123456789", "output": "YES" }, { "input": "3\n911", "output": "YES" }, { "input": "3\n089", "output": "NO" }, { "input": "3\n159", "output": "YES" }, { ...
1,678,376,126
626
PyPy 3
OK
TESTS
94
77
0
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) s = list(input().rstrip()) x = [3, 0, 0, 0, 1, 1, 1, 2, 2, 2] y = [1, 0, 1, 2, 0, 1, 2, 0, 1, 2] s0 = set() for i, j in zip(x, y): s0.add((i, j)) c = 0 for dx in range(-5, 6): for dy in range(-5, 6): ...
Title: Mike and Cellphone Time Limit: None seconds Memory Limit: None megabytes Problem Description: While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equ...
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) s = list(input().rstrip()) x = [3, 0, 0, 0, 1, 1, 1, 2, 2, 2] y = [1, 0, 1, 2, 0, 1, 2, 0, 1, 2] s0 = set() for i, j in zip(x, y): s0.add((i, j)) c = 0 for dx in range(-5, 6): for dy in range(...
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,679,407,541
2,147,483,647
PyPy 3-64
OK
TESTS
34
124
0
from sys import stdin input=lambda :stdin.readline()[:-1] n=int(input()) l=[] for i in range(n): l+=[input()] l.sort() print(l[n//2])
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python from sys import stdin input=lambda :stdin.readline()[:-1] n=int(input()) l=[] for i in range(n): l+=[input()] l.sort() print(l[n//2]) ```
3.969
500
A
New Year Transportation
PROGRAMMING
1,000
[ "dfs and similar", "graphs", "implementation" ]
null
null
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0...
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara...
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
[ "8 4\n1 2 1 2 1 2 1\n", "8 5\n1 2 1 2 1 1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
500
[ { "input": "8 4\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "8 5\n1 2 1 2 1 1 1", "output": "NO" }, { "input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "output": "YES" }, { "input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ...
1,662,017,091
2,147,483,647
Python 3
OK
TESTS
34
62
1,843,200
from collections import deque n, t = map(int, input().split()) portal = list(map(int, input().split())) ochrd = deque() ochrd.append(1 + portal[0]) prm = ochrd.popleft() while prm <= t: if prm == t: print ('YES') break ochrd.append(prm + portal[prm - 1]) prm = ochrd.popleft() e...
Title: New Year Transportation Time Limit: None seconds Memory Limit: None megabytes Problem Description: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o...
```python from collections import deque n, t = map(int, input().split()) portal = list(map(int, input().split())) ochrd = deque() ochrd.append(1 + portal[0]) prm = ochrd.popleft() while prm <= t: if prm == t: print ('YES') break ochrd.append(prm + portal[prm - 1]) prm = ochrd.po...
3
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,692,384,495
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
v,v1=map(int,input().split()) if v1%2==1 and v1%3!=0: for i in range(v+1,v1): if i%2==0 or i%3==0:continue else:print(i);print("NO");break else:print("Yes") else:print("NO")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python v,v1=map(int,input().split()) if v1%2==1 and v1%3!=0: for i in range(v+1,v1): if i%2==0 or i%3==0:continue else:print(i);print("NO");break else:print("Yes") else:print("NO") ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,596,463,920
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
6,656,000
a = int(input(), 2) b = int(input(), 2) print(bin(a ^ b)[2:].zfill(len(str(a))))
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a = int(input(), 2) b = int(input(), 2) print(bin(a ^ b)[2:].zfill(len(str(a)))) ```
0
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million...
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "N...
1,498,898,403
2,147,483,647
Python 3
OK
TESTS
64
124
5,529,600
k = int(input()) l = int(input()) n = 0 while k ** n <= l: if (k ** n == l): print("YES") print(n - 1) exit() n += 1 print("NO")
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa...
```python k = int(input()) l = int(input()) n = 0 while k ** n <= l: if (k ** n == l): print("YES") print(n - 1) exit() n += 1 print("NO") ```
3
352
B
Jeff and Periods
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold: - *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th...
[ "1\n2\n", "8\n1 2 1 3 1 2 1 5\n" ]
[ "1\n2 0\n", "4\n1 2\n2 4\n3 0\n5 0\n" ]
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0.
1,000
[ { "input": "1\n2", "output": "1\n2 0" }, { "input": "8\n1 2 1 3 1 2 1 5", "output": "4\n1 2\n2 4\n3 0\n5 0" }, { "input": "3\n1 10 5", "output": "3\n1 0\n5 0\n10 0" }, { "input": "4\n9 9 3 5", "output": "3\n3 0\n5 0\n9 1" }, { "input": "6\n1 2 2 1 1 2", "outpu...
1,626,195,753
2,147,483,647
PyPy 3
OK
TESTS
36
716
39,321,600
n = int(input()) a = list(map(int, input().split())) count, pos = [0 for _ in range(10**5+1)], [[] for _ in range(10**5+1)] visited = [] for i, ai in enumerate(a): count[ai] += 1 pos[ai] += [i] t, x = 0, [] for key, occurrences in enumerate(count): if occurrences == 0: continue elif o...
Title: Jeff and Periods Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold: -...
```python n = int(input()) a = list(map(int, input().split())) count, pos = [0 for _ in range(10**5+1)], [[] for _ in range(10**5+1)] visited = [] for i, ai in enumerate(a): count[ai] += 1 pos[ai] += [i] t, x = 0, [] for key, occurrences in enumerate(count): if occurrences == 0: continue ...
3
6
A
Triangle
PROGRAMMING
900
[ "brute force", "geometry" ]
A. Triangle
2
64
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s...
[ "4 2 1 3\n", "7 2 2 4\n", "3 5 9 1\n" ]
[ "TRIANGLE\n", "SEGMENT\n", "IMPOSSIBLE\n" ]
none
0
[ { "input": "4 2 1 3", "output": "TRIANGLE" }, { "input": "7 2 2 4", "output": "SEGMENT" }, { "input": "3 5 9 1", "output": "IMPOSSIBLE" }, { "input": "3 1 5 1", "output": "IMPOSSIBLE" }, { "input": "10 10 10 10", "output": "TRIANGLE" }, { "input": "11 ...
1,665,843,601
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
18
62
0
n=input().split() l=[] l1=[] for i in n: l.append(int(i)) l.sort() for j in l: if j not in l1: l1.append(j) if l[1]+l[2]+l[0]<=l[3] and len(l1)>2 and l[0]+l[1]!=l[2]: print("IMPOSSIBLE") else: if l[1]+l[2]>l[3] or ...
Title: Triangle Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o...
```python n=input().split() l=[] l1=[] for i in n: l.append(int(i)) l.sort() for j in l: if j not in l1: l1.append(j) if l[1]+l[2]+l[0]<=l[3] and len(l1)>2 and l[0]+l[1]!=l[2]: print("IMPOSSIBLE") else: if l[1]+l[2...
0
29
A
Spit Problem
PROGRAMMING
1,000
[ "brute force" ]
A. Spit Problem
2
256
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
[ "2\n0 1\n1 -1\n", "3\n0 1\n1 1\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "2\n0 1\n1 -1", "output": "YES" }, { "input": "3\n0 1\n1 1\n2 -2", "output": "NO" }, { "input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES" }, { "input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759...
1,608,028,158
2,147,483,647
PyPy 3
OK
TESTS
30
312
1,331,200
n = int(input()) nums = [] for j in range(n): nums.append([int(j) for j in input().split()]) output = "NO" for j in range(n): for k in range(j + 1, n): if nums[j][0] + nums[j][1] == nums[k][0]: if nums[k][1] + nums[k][0] == nums[j][0]: output = "YES" ...
Title: Spit Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ...
```python n = int(input()) nums = [] for j in range(n): nums.append([int(j) for j in input().split()]) output = "NO" for j in range(n): for k in range(j + 1, n): if nums[j][0] + nums[j][1] == nums[k][0]: if nums[k][1] + nums[k][0] == nums[j][0]: output = "YES" ...
3.91952
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,695,172,801
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
2,252,800
n = int(input()) laptops = [None] * n for i in range(n): laptops[i] = list(map(int, input().split())) laptops = sorted(laptops) flag = True for i in range(n-1): if laptops[i][1] > laptops[i+1][1]: flag = False else: flag = True if(flag): print('Poor Alex') else: pri...
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()) laptops = [None] * n for i in range(n): laptops[i] = list(map(int, input().split())) laptops = sorted(laptops) flag = True for i in range(n-1): if laptops[i][1] > laptops[i+1][1]: flag = False else: flag = True if(flag): print('Poor Alex') else...
0
39
J
Spelling Check
PROGRAMMING
1,500
[ "hashing", "implementation", "strings" ]
J. Spelling Check
2
256
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d...
The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.
In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible...
[ "abdrakadabra\nabrakadabra\n", "aa\na\n", "competition\ncodeforces\n" ]
[ "1\n3\n", "2\n1 2\n", "0\n" ]
none
0
[ { "input": "abdrakadabra\nabrakadabra", "output": "1\n3 " }, { "input": "aa\na", "output": "2\n1 2 " }, { "input": "competition\ncodeforces", "output": "0" }, { "input": "ab\na", "output": "1\n2 " }, { "input": "bb\nb", "output": "2\n1 2 " }, { "input"...
1,438,186,071
2,147,483,647
Python 3
OK
TESTS
40
1,840
46,489,600
s = input().strip() t = input().strip() diff = len(s) - 1 for i in range(len(t)): if s[i] != t[i]: diff = i break for i in range(diff + 1, len(s)): if s[i] != t[i - 1]: print(0) import sys; sys.exit() start = diff while start != 0 and s[start - 1] == s[diff]: start -= 1 print(diff - start + 1) pri...
Title: Spelling Check Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and ...
```python s = input().strip() t = input().strip() diff = len(s) - 1 for i in range(len(t)): if s[i] != t[i]: diff = i break for i in range(diff + 1, len(s)): if s[i] != t[i - 1]: print(0) import sys; sys.exit() start = diff while start != 0 and s[start - 1] == s[diff]: start -= 1 print(diff - star...
3.453406
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,645,960,116
2,147,483,647
PyPy 3
OK
TESTS
54
154
1,433,600
count = 0 n, m = [int(i) for i in input().split()] for a in range(m + 1): for b in range(n + 1): if a ** 2 + b == n and a + b ** 2 == m: count += 1 print(count)
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 count = 0 n, m = [int(i) for i in input().split()] for a in range(m + 1): for b in range(n + 1): if a ** 2 + b == n and a + b ** 2 == m: count += 1 print(count) ```
3
702
A
Maximum Increase
PROGRAMMING
800
[ "dp", "greedy", "implementation" ]
null
null
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print the maximum length of an increasing subarray of the given array.
[ "5\n1 7 2 11 15\n", "6\n100 100 100 100 100 100\n", "3\n1 2 3\n" ]
[ "3\n", "1\n", "3\n" ]
none
0
[ { "input": "5\n1 7 2 11 15", "output": "3" }, { "input": "6\n100 100 100 100 100 100", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n1000000000", "output": "1" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7...
1,677,109,090
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
num=int(input()) z=[int(i)for i in input().split()] c=1 for i in range(num-1): if z[i]<z[i+1]: c+=1 else: c=1 print(c)
Title: Maximum Increase Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called...
```python num=int(input()) z=[int(i)for i in input().split()] c=1 for i in range(num-1): if z[i]<z[i+1]: c+=1 else: c=1 print(c) ```
0
556
A
Case of the Zeros and Ones
PROGRAMMING
900
[ "greedy" ]
null
null
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an...
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
[ "4\n1100\n", "5\n01010\n", "8\n11101111\n" ]
[ "0\n", "1\n", "6\n" ]
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like...
250
[ { "input": "4\n1100", "output": "0" }, { "input": "5\n01010", "output": "1" }, { "input": "8\n11101111", "output": "6" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "2" }, { "input"...
1,681,616,964
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
N = int(input()) S = input().strip() c0,c1 = S.count("0"), S.count("1") print(max(c0,c1)-min(c0,c1))
Title: Case of the Zeros and Ones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Cons...
```python N = int(input()) S = input().strip() c0,c1 = S.count("0"), S.count("1") print(max(c0,c1)-min(c0,c1)) ```
-1
10
D
LCIS
PROGRAMMING
2,800
[ "dp" ]
D. LCIS
1
256
This problem differs from one which was on the online contest. The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=&lt;<=*a**i*<=+<=1 for *i*<=&lt;<=*n*. The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of inde...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=500) — the length of the first sequence. The second line contains *n* space-separated integers from the range [0,<=109] — elements of the first sequence. The third line contains an integer *m* (1<=≤<=*m*<=≤<=500) — the length of the second sequence. The fourth line ...
In the first line output *k* — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.
[ "7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n", "5\n1 2 0 2 1\n3\n1 0 1\n" ]
[ "3\n3 5 6 \n", "2\n0 1 \n" ]
none
0
[ { "input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "output": "3\n3 5 6 " }, { "input": "5\n1 2 0 2 1\n3\n1 0 1", "output": "2\n0 1 " }, { "input": "2\n6 10\n3\n6 3 3", "output": "1\n6 " }, { "input": "1\n7\n2\n7 9", "output": "1\n7 " }, { "input": "3\n37 49 24\n3\n33 5 70...
1,689,435,155
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689435155.9046495")# 1689435155.9046698
Title: LCIS Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: This problem differs from one which was on the online contest. The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=&lt;<=*a**i*<=+<=1 for *i*<=&lt;<=*n*. The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the sub...
```python print("_RANDOM_GUESS_1689435155.9046495")# 1689435155.9046698 ```
0
299
A
Ksusha and Array
PROGRAMMING
1,000
[ "brute force", "number theory", "sortings" ]
null
null
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n" ]
[ "2\n", "1\n", "-1\n" ]
none
500
[ { "input": "3\n2 2 4", "output": "2" }, { "input": "5\n2 1 3 1 6", "output": "1" }, { "input": "3\n2 3 5", "output": "-1" }, { "input": "1\n331358794", "output": "331358794" }, { "input": "5\n506904227 214303304 136194869 838256937 183952885", "output": "-1" ...
1,660,927,698
2,147,483,647
PyPy 3-64
OK
TESTS
32
216
12,390,400
n = int(input()) a = [int(i) for i in input().split()] a.sort() if 1 in a: print(1) else: s = a[0] f = 0 for i in range(1,n): if a[i]%s != 0: f = 1 break if f == 0: print(s) else: print(-1)
Title: Ksusha and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that ...
```python n = int(input()) a = [int(i) for i in input().split()] a.sort() if 1 in a: print(1) else: s = a[0] f = 0 for i in range(1,n): if a[i]%s != 0: f = 1 break if f == 0: print(s) else: print(-1) ```
3
253
A
Boys and Girls
PROGRAMMING
1,100
[ "greedy" ]
null
null
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=&lt;<=*n*<=+<=*m*) such th...
The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space.
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi...
[ "3 3\n", "4 2\n" ]
[ "GBGBGB\n", "BGBGBB\n" ]
In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.
500
[ { "input": "3 3", "output": "GBGBGB" }, { "input": "4 2", "output": "BGBGBB" }, { "input": "5 5", "output": "GBGBGBGBGB" }, { "input": "6 4", "output": "BGBGBGBGBB" }, { "input": "100 1", "output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
1,620,272,256
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
6,963,200
with open("test.txt","r") as fh: content = fh.read() n = int(content[0]) m = int(content[-1]) sigma = [] for i in range (0,(n+m)): if n > 0: sigma.append('B') n -= 1 if m > 0: m -= 1 sigma.append('G') tau = ''.join([str(i) for i in sigma]) print(tau) with open("output.txt...
Title: Boys and Girls Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n...
```python with open("test.txt","r") as fh: content = fh.read() n = int(content[0]) m = int(content[-1]) sigma = [] for i in range (0,(n+m)): if n > 0: sigma.append('B') n -= 1 if m > 0: m -= 1 sigma.append('G') tau = ''.join([str(i) for i in sigma]) print(tau) with open("...
-1
814
A
An abandoned sentiment from past
PROGRAMMING
900
[ "constructive algorithms", "greedy", "implementation", "sortings" ]
null
null
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly ...
Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise.
[ "4 2\n11 0 0 14\n5 4\n", "6 1\n2 3 0 8 9 10\n5\n", "4 1\n8 94 0 4\n89\n", "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n" ]
In the first sample: - Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulti...
500
[ { "input": "4 2\n11 0 0 14\n5 4", "output": "Yes" }, { "input": "6 1\n2 3 0 8 9 10\n5", "output": "No" }, { "input": "4 1\n8 94 0 4\n89", "output": "Yes" }, { "input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes" }, { "input": "40 1\n23 26 27 28 31 35 38 4...
1,496,865,509
2,147,483,647
Python 3
OK
TESTS
96
62
0
# -*- coding: utf-8 -*- """ Created on Wed Jun 7 15:25:16 2017 @author: Gad """ def checker(size,string,replacements): increasing = True if int(size[1]) > 1: return 'Yes' else: for i in range (int(size[0])): if int (string[i]) == 0: ...
Title: An abandoned sentiment from past Time Limit: None seconds Memory Limit: None megabytes Problem Description: A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of t...
```python # -*- coding: utf-8 -*- """ Created on Wed Jun 7 15:25:16 2017 @author: Gad """ def checker(size,string,replacements): increasing = True if int(size[1]) > 1: return 'Yes' else: for i in range (int(size[0])): if int (string[i]) == 0: ...
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,667,507,790
2,147,483,647
Python 3
OK
TESTS
40
46
0
s = input() h = ['h', 'e', 'l', 'l', 'o'] cnt = 0 for i in s: if i == h[cnt]: cnt += 1 if cnt == 5: print('YES') break else: if cnt == 5: print('YES') print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python s = input() h = ['h', 'e', 'l', 'l', 'o'] cnt = 0 for i in s: if i == h[cnt]: cnt += 1 if cnt == 5: print('YES') break else: if cnt == 5: print('YES') print('NO') ```
3.977
580
A
Kefa and First Steps
PROGRAMMING
900
[ "brute force", "dp", "implementation" ]
null
null
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
[ "6\n2 2 1 3 4 1\n", "3\n2 2 9\n" ]
[ "3", "3" ]
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
750
[ { "input": "6\n2 2 1 3 4 1", "output": "3" }, { "input": "3\n2 2 9", "output": "3" }, { "input": "5\n10 100 111 1 2", "output": "3" }, { "input": "10\n1 2 3 4 1 2 3 4 5 6", "output": "6" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1,693,828,121
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
n = int(input()) l = list(map(int, input().split())) c = 0 max_length = 0 for i in range(1, n): if l[i - 1] > l[i]: c += 1 else: c = 0 max_length = max(max_length, c) print(max_length + 1)
Title: Kefa and First Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l...
```python n = int(input()) l = list(map(int, input().split())) c = 0 max_length = 0 for i in range(1, n): if l[i - 1] > l[i]: c += 1 else: c = 0 max_length = max(max_length, c) print(max_length + 1) ```
0
705
A
Hulk
PROGRAMMING
800
[ "implementation" ]
null
null
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Print Dr.Banner's feeling in one line.
[ "1\n", "2\n", "3\n" ]
[ "I hate it\n", "I hate that I love it\n", "I hate that I love that I hate it\n" ]
none
500
[ { "input": "1", "output": "I hate it" }, { "input": "2", "output": "I hate that I love it" }, { "input": "3", "output": "I hate that I love that I hate it" }, { "input": "4", "output": "I hate that I love that I hate that I love it" }, { "input": "5", "output"...
1,686,221,435
2,147,483,647
Python 3
OK
TESTS
21
46
0
n=int(input()) x=str() for i in range (n-1): if i%2==0: x=x+'I hate that ' else: x=x+'I love that ' if n%2==1: x=x+'I hate it' else: x=x+'I love it' print(x)
Title: Hulk Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and...
```python n=int(input()) x=str() for i in range (n-1): if i%2==0: x=x+'I hate that ' else: x=x+'I love that ' if n%2==1: x=x+'I hate it' else: x=x+'I love it' print(x) ```
3
221
A
Little Elephant and Function
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works...
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists.
[ "1\n", "2\n" ]
[ "1 ", "2 1 " ]
none
500
[ { "input": "1", "output": "1 " }, { "input": "2", "output": "2 1 " }, { "input": "3", "output": "3 1 2 " }, { "input": "4", "output": "4 1 2 3 " }, { "input": "5", "output": "5 1 2 3 4 " }, { "input": "6", "output": "6 1 2 3 4 5 " }, { "inp...
1,697,965,045
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a = [int(a) for a in range(2,int(input()))] a = a[::-1] a.append(1) a.append(max(a) + 1) a = a[::-1] print(a)
Title: Little Elephant and Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm...
```python a = [int(a) for a in range(2,int(input()))] a = a[::-1] a.append(1) a.append(max(a) + 1) a = a[::-1] print(a) ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,627,282,423
2,147,483,647
PyPy 3
OK
TESTS
30
186
20,172,800
string = input() upper = 0 lower = 0 for i in range(len(string)): if (ord(string[i]) >= 97 and ord(string[i]) <= 122): lower += 1 elif (ord(string[i]) >= 65 and ord(string[i]) <= 90): upper += 1 if(upper>lower): print(string.upper()) elif(lower>upper): print(...
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 string = input() upper = 0 lower = 0 for i in range(len(string)): if (ord(string[i]) >= 97 and ord(string[i]) <= 122): lower += 1 elif (ord(string[i]) >= 65 and ord(string[i]) <= 90): upper += 1 if(upper>lower): print(string.upper()) elif(lower>upper): ...
3.915925
982
A
Row
PROGRAMMING
1,200
[ "brute force", "constructive algorithms" ]
null
null
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($0$ means t...
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs. The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
[ "3\n101\n", "4\n1011\n", "5\n10001\n" ]
[ "Yes\n", "No\n", "No\n" ]
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
500
[ { "input": "3\n101", "output": "Yes" }, { "input": "4\n1011", "output": "No" }, { "input": "5\n10001", "output": "No" }, { "input": "1\n0", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "100\n010100101010100101001001010100101010010...
1,594,366,384
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
6,656,000
a=int(input()) b=input().replace("10","1 0").replace("01","0 1").split() for i in range(len(b)): if len(b[i])!=1 :print("No");exit() print("YES")
Title: Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th...
```python a=int(input()) b=input().replace("10","1 0").replace("01","0 1").split() for i in range(len(b)): if len(b[i])!=1 :print("No");exit() print("YES") ```
0
44
A
Indian Summer
PROGRAMMING
900
[ "implementation" ]
A. Indian Summer
2
256
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor...
Output the single number — the number of Alyona's leaves.
[ "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n", "3\noak yellow\noak yellow\noak yellow\n" ]
[ "4\n", "1\n" ]
none
0
[ { "input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4" }, { "input": "3\noak yellow\noak yellow\noak yellow", "output": "1" }, { "input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae", "output": "5" }, { "input"...
1,398,198,308
2,147,483,647
Python 3
OK
TESTS
29
124
0
n = int(input()) bunch = [] for i in range(n): leaf = input() if (leaf not in bunch): bunch.append(leaf) print(len(bunch))
Title: Indian Summer Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie...
```python n = int(input()) bunch = [] for i in range(n): leaf = input() if (leaf not in bunch): bunch.append(leaf) print(len(bunch)) ```
3.969
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th...
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar...
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", ...
1,678,583,174
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
n, k=map(int,input().split()) kalan=0 for i in range(n): kalan+=i if 240<=k+kalan*5: break print(kalan-1)
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem...
```python n, k=map(int,input().split()) kalan=0 for i in range(n): kalan+=i if 240<=k+kalan*5: break print(kalan-1) ```
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,684,238,727
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
a = int(input()) c = [] m = '' for i in range(a): b = input() if len(b) < 11: c.append(b) elif len(b) > 10: m += b[0] m += str(len(b)) m += b[-1] c.append(m) m = '' print(c)
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 a = int(input()) c = [] m = '' for i in range(a): b = input() if len(b) < 11: c.append(b) elif len(b) > 10: m += b[0] m += str(len(b)) m += b[-1] c.append(m) m = '' print(c) ```
0
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,574,358,374
2,147,483,647
Python 3
OK
TESTS
27
218
0
from math import sqrt a,b,c=map(int,input().split()) d=4*(sqrt(a*b//c)+sqrt(c*b//a)+sqrt(a*c//b)) print(int(d))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python from math import sqrt a,b,c=map(int,input().split()) d=4*(sqrt(a*b//c)+sqrt(c*b//a)+sqrt(a*c//b)) print(int(d)) ```
3
567
E
President and Roads
PROGRAMMING
2,200
[ "dfs and similar", "graphs", "hashing", "shortest paths" ]
null
null
Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road is a positive integer. Once a year the President visited his historic home town *t*, for which his motorc...
The first lines contain four integers *n*, *m*, *s* and *t* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (*s*<=≠<=*t*). Next *m* lines contain the roads. Each road is given as a group of three in...
Print *m* lines. The *i*-th line should contain information about the *i*-th road (the roads are numbered in the order of appearance in the input). If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes). Otherwise, if the *i*-th road can be re...
[ "6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1\n", "3 3 1 3\n1 2 10\n2 3 10\n1 3 100\n", "2 2 1 2\n1 2 1\n1 2 2\n" ]
[ "YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES\n", "YES\nYES\nCAN 81\n", "YES\nNO\n" ]
The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing. In the first sample president initially may choose one of the two following ways for a ride: 1 → 2 → 4 → 5 → 6 or 1 → 2 → 3 → 5 → 6.
2,500
[ { "input": "6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1", "output": "YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES" }, { "input": "3 3 1 3\n1 2 10\n2 3 10\n1 3 100", "output": "YES\nYES\nCAN 81" }, { "input": "2 2 1 2\n1 2 1\n1 2 2", "output": "YES\nNO" }, { "inpu...
1,692,445,539
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1692445539.276827")# 1692445539.2768426
Title: President and Roads Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road i...
```python print("_RANDOM_GUESS_1692445539.276827")# 1692445539.2768426 ```
0
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,...
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "i...
1,597,932,255
2,147,483,647
Python 3
OK
TESTS
32
109
0
def lcm(x, y): x, y = max(x, y), min(x, y) for i in range(1, y+1): if x*i%y==0: return x*i n, m, z = list(map(int, input().split())) x = lcm(n, m) print(z//x)
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com...
```python def lcm(x, y): x, y = max(x, y), min(x, y) for i in range(1, y+1): if x*i%y==0: return x*i n, m, z = list(map(int, input().split())) x = lcm(n, m) print(z//x) ```
3
371
C
Hamburgers
PROGRAMMING
1,600
[ "binary search", "brute force" ]
null
null
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (...
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n...
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
[ "BBBSSC\n6 4 1\n1 2 3\n4\n", "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n" ]
[ "2\n", "7\n", "200000000001\n" ]
none
1,500
[ { "input": "BBBSSC\n6 4 1\n1 2 3\n4", "output": "2" }, { "input": "BBC\n1 10 1\n1 10 1\n21", "output": "7" }, { "input": "BSC\n1 1 1\n1 1 3\n1000000000000", "output": "200000000001" }, { "input": "B\n1 1 1\n1 1 1\n381", "output": "382" }, { "input": "BSC\n3 5 6\n7...
1,686,428,349
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
import math sandwich=input() sand_dict={'B':0,'C':0,'S':0} for s in sandwich: sand_dict[s]+=1 has=input().split(' ') has=[int(x) for x in has] price=input().split(' ') price=[int(x) for x in price] money=int(input()) # money+=has[0]*price[0]*(1 if sand_dict['B']>0 else 0)+has[1]*price[1]*(1 if sand_dict['S']...
Title: Hamburgers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ...
```python import math sandwich=input() sand_dict={'B':0,'C':0,'S':0} for s in sandwich: sand_dict[s]+=1 has=input().split(' ') has=[int(x) for x in has] price=input().split(' ') price=[int(x) for x in price] money=int(input()) # money+=has[0]*price[0]*(1 if sand_dict['B']>0 else 0)+has[1]*price[1]*(1 if sand...
0
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nck...
1,693,401,425
2,147,483,647
Python 3
OK
TESTS
47
46
0
n = int(input()) the_list = [] for i in range(n): the_list += [input()] a = 0 for i in the_list: if i[a] != the_list[0][0] or i[-(a + 1)] != the_list[0][0]: print("NO") exit(0) a += 1 if the_list[0][1] != the_list[0][0]: s = 0 for i in the_list: s += i.count(th...
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a...
```python n = int(input()) the_list = [] for i in range(n): the_list += [input()] a = 0 for i in the_list: if i[a] != the_list[0][0] or i[-(a + 1)] != the_list[0][0]: print("NO") exit(0) a += 1 if the_list[0][1] != the_list[0][0]: s = 0 for i in the_list: s += ...
3
453
B
Little Pony and Harmony Chest
PROGRAMMING
2,000
[ "bitmasks", "brute force", "dp" ]
null
null
Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony. A sequence of positive integers *b**i* is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony se...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements of the sequences *a* and *b*. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=30).
Output the key — sequence *b**i* that minimizes the sum described above. If there are multiple optimal sequences, you can output any of them.
[ "5\n1 1 1 1 1\n", "5\n1 6 4 2 8\n" ]
[ "1 1 1 1 1 ", "1 5 3 1 8 " ]
none
1,000
[ { "input": "5\n1 1 1 1 1", "output": "1 1 1 1 1 " }, { "input": "5\n1 6 4 2 8", "output": "1 5 3 1 8 " }, { "input": "10\n16 3 16 10 12 5 14 14 15 27", "output": "19 1 17 7 11 1 16 13 15 29 " }, { "input": "10\n8 7 11 5 17 24 28 18 7 8", "output": "9 7 11 5 17 23 29 19 1 ...
1,599,209,766
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
6
4,000
11,673,600
def optimal_seq(A): def is_valid(number): for factor in factors[number]: if factor in used: return False return True def mark_factors(number): nonlocal used for prime_factor in factors[number]: used.add(prime_factor) ...
Title: Little Pony and Harmony Chest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony. A sequence of positive integers *b**i* is harmony if and only if for every two elements of the ...
```python def optimal_seq(A): def is_valid(number): for factor in factors[number]: if factor in used: return False return True def mark_factors(number): nonlocal used for prime_factor in factors[number]: used.add(prime_...
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,675,434,128
2,147,483,647
Python 3
OK
TESTS
20
46
0
n = int(input()) for i in range(n): w = input() s = len(w) if s > 10: print(w[0] + str(s - 2) + w[s-1]) else: print(w)
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 n = int(input()) for i in range(n): w = input() s = len(w) if s > 10: print(w[0] + str(s - 2) + w[s-1]) else: print(w) ```
3.977
760
B
Frodo and pillows
PROGRAMMING
1,500
[ "binary search", "greedy" ]
null
null
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge...
The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n" ]
[ "2\n", "4\n", "3\n" ]
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third exa...
1,000
[ { "input": "4 6 2", "output": "2" }, { "input": "3 10 3", "output": "4" }, { "input": "3 6 1", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000 1", "output": "1000000000" }, { ...
1,485,115,854
6,954
Python 3
WRONG_ANSWER
PRETESTS
1
62
5,120,000
import re import math entrada = input() match = re.search('(\d*) (\d*) (\d*)', entrada) n = int(match.group(1)) # hobbits m = int(match.group(2)) # Almofadas k = int(match.group(3))-1 # Posicao pretotal = m//n if m%n == 0: print(pretotal+((m-pretotal*n)%n//2)+1) else: print(pretotal+((m-pretotal*n)...
Title: Frodo and pillows Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma...
```python import re import math entrada = input() match = re.search('(\d*) (\d*) (\d*)', entrada) n = int(match.group(1)) # hobbits m = int(match.group(2)) # Almofadas k = int(match.group(3))-1 # Posicao pretotal = m//n if m%n == 0: print(pretotal+((m-pretotal*n)%n//2)+1) else: print(pretotal+((m-p...
0
617
D
Polyline
PROGRAMMING
1,700
[ "constructive algorithms", "implementation" ]
null
null
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this p...
Each of the three lines of the input contains two integers. The *i*-th line contains integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the coordinates of the *i*-th point. It is guaranteed that all points are distinct.
Print a single number — the minimum possible number of segments of the polyline.
[ "1 -1\n1 1\n1 2\n", "-1 -1\n-1 3\n4 3\n", "1 1\n2 3\n3 2\n" ]
[ "1\n", "2\n", "3\n" ]
The variant of the polyline in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/b41b4dad8437bd7a69f6ab01eaedf010b82ba7b8.png" style="max-width: 100.0%;max-height: 100.0%;"/> The variant of the polyline in the second sample: <img class="tex-graphics" src="https://espresso.codeforces.com/7...
1,750
[ { "input": "1 -1\n1 1\n1 2", "output": "1" }, { "input": "-1 -1\n-1 3\n4 3", "output": "2" }, { "input": "1 1\n2 3\n3 2", "output": "3" }, { "input": "1000000000 -1000000000\n1000000000 1000000000\n-1000000000 -1000000000", "output": "2" }, { "input": "-510073119 ...
1,695,450,453
2,147,483,647
PyPy 3-64
OK
TESTS
54
62
0
def mid(a,b,c): return c>=max(a,b) or c<=min(a,b) x1,y1=list(map(int,input().split())) x2,y2=list(map(int,input().split())) x3,y3=list(map(int,input().split())) if x1==x2==x3 or y1==y2==y3: print(1) else: # if x1==x2 and (y1==y3 or y2==y3): # print(2) # elif x1==x3 and (y1==y2 or...
Title: Polyline Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only s...
```python def mid(a,b,c): return c>=max(a,b) or c<=min(a,b) x1,y1=list(map(int,input().split())) x2,y2=list(map(int,input().split())) x3,y3=list(map(int,input().split())) if x1==x2==x3 or y1==y2==y3: print(1) else: # if x1==x2 and (y1==y3 or y2==y3): # print(2) # elif x1==x3 and ...
3
129
A
Cookies
PROGRAMMING
900
[ "implementation" ]
null
null
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan...
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
[ "1\n1\n", "10\n1 2 2 3 4 4 4 2 2 2\n", "11\n2 2 2 2 2 2 2 2 2 2 99\n" ]
[ "1\n", "8\n", "1\n" ]
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, t...
500
[ { "input": "1\n1", "output": "1" }, { "input": "10\n1 2 2 3 4 4 4 2 2 2", "output": "8" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 99", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 2", "output": "2" }, { "input": "2\n1 2", "o...
1,551,182,703
2,147,483,647
Python 3
OK
TESTS
52
218
0
def main(): bags = int(input()) if bags < 1 or bags > 100: return 0 string = input() string = string.split(" ") if len(string) < 1 or len(string) != bags: return 0 imp = 0 par = 0 soma = 0 for i in range(bags): soma += int(string[i]) if int(string[i]) % 2 == 0: par += 1 else: imp += 1 if ...
Title: Cookies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan...
```python def main(): bags = int(input()) if bags < 1 or bags > 100: return 0 string = input() string = string.split(" ") if len(string) < 1 or len(string) != bags: return 0 imp = 0 par = 0 soma = 0 for i in range(bags): soma += int(string[i]) if int(string[i]) % 2 == 0: par += 1 else: imp ...
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,685,173,563
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
x = int(input()) list_of_digits=[] while x > 0: list_of_digits.append(x%10) x = x//10 final_list=[] for i in list_of_digits: if i>=5: final_list.append(9-i) else: final_list.append(i) final_list.reverse() final_value=0 for i in final_list: final_value = final_...
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 x = int(input()) list_of_digits=[] while x > 0: list_of_digits.append(x%10) x = x//10 final_list=[] for i in list_of_digits: if i>=5: final_list.append(9-i) else: final_list.append(i) final_list.reverse() final_value=0 for i in final_list: final_valu...
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,675,957,809
2,147,483,647
Python 3
OK
TESTS
40
92
0
import sys input = sys.stdin.readline output = sys.stdout.write def main(): word = input().rstrip() translated = input().rstrip() state = True l = len(word) r = len(translated) if l != r: output('NO') else: for i in range(l): if word[i] == transla...
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 import sys input = sys.stdin.readline output = sys.stdout.write def main(): word = input().rstrip() translated = input().rstrip() state = True l = len(word) r = len(translated) if l != r: output('NO') else: for i in range(l): if word[i] ...
3.977
580
A
Kefa and First Steps
PROGRAMMING
900
[ "brute force", "dp", "implementation" ]
null
null
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
[ "6\n2 2 1 3 4 1\n", "3\n2 2 9\n" ]
[ "3", "3" ]
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
750
[ { "input": "6\n2 2 1 3 4 1", "output": "3" }, { "input": "3\n2 2 9", "output": "3" }, { "input": "5\n10 100 111 1 2", "output": "3" }, { "input": "10\n1 2 3 4 1 2 3 4 5 6", "output": "6" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1,693,828,289
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n = int(input()) l = list(map(int, input().split())) c = 0 max_difference = 0 last_peak_index = 0 for i in range(1, n): if l[i - 1] > l[i]: last_peak_index = i - 1 max_difference = max(max_difference, i - last_peak_index) print(max_difference)
Title: Kefa and First Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l...
```python n = int(input()) l = list(map(int, input().split())) c = 0 max_difference = 0 last_peak_index = 0 for i in range(1, n): if l[i - 1] > l[i]: last_peak_index = i - 1 max_difference = max(max_difference, i - last_peak_index) print(max_difference) ```
0
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,685,400,195
2,147,483,647
Python 3
OK
TESTS
54
92
0
l = input().split(' ') n, m, count = int(l[0]), int(l[1]), 0 for i in range(10000): p = pow(i, 2) if i + pow(n-p, 2) == m and n - p >= 0: count += 1 print(count)
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 l = input().split(' ') n, m, count = int(l[0]), int(l[1]), 0 for i in range(10000): p = pow(i, 2) if i + pow(n-p, 2) == m and n - p >= 0: count += 1 print(count) ```
3
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is close...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co...
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya ca...
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 ...
1,688,728,458
2,147,483,647
PyPy 3
OK
TESTS
88
108
1,740,800
n=int(input()) a=list(map(int,input().split())) import functools @functools.lru_cache(maxsize=None) def dp(i,state): if i==n: return 0 if state==0: if a[i]==0: return 1+dp(i+1,0) elif a[i]==1: return min(1+dp(i+1,0),dp(i+1,1)) elif a[i]==...
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int...
```python n=int(input()) a=list(map(int,input().split())) import functools @functools.lru_cache(maxsize=None) def dp(i,state): if i==n: return 0 if state==0: if a[i]==0: return 1+dp(i+1,0) elif a[i]==1: return min(1+dp(i+1,0),dp(i+1,1)) e...
3
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,697,362,127
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
input_list = list(map(int, input().split())) a, b, c = input_list diff1 = abs(abs(a-b) - abs(a-c)) diff3 = abs(abs(b-a) - abs(b-c)) diff5 = abs(abs(c-a) - abs(c-b)) if diff1 <= diff3 and diff1 <= diff5: print(abs(a-b) + abs(a-c)) elif diff3 <= diff1 and diff3 <= diff5: print(abs(b-a) + abs(b-c)) el...
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python input_list = list(map(int, input().split())) a, b, c = input_list diff1 = abs(abs(a-b) - abs(a-c)) diff3 = abs(abs(b-a) - abs(b-c)) diff5 = abs(abs(c-a) - abs(c-b)) if diff1 <= diff3 and diff1 <= diff5: print(abs(a-b) + abs(a-c)) elif diff3 <= diff1 and diff3 <= diff5: print(abs(b-a) + abs...
0
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input...
1,629,640,559
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
122
20,172,800
n=int(input()) l=list(map(int,input().split())) a=[0];b=[0];ans=0;t1=0;t2=0 for i in range(len(l)-1): if l[i]<=l[i+1]: t1+=1 a.append(t1) else : a.append(0) t1=0 for j in range(len(l)-1,0,-1): if l[j]<l[j-1]: t2+=1 b.append(t2) else : ...
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *...
```python n=int(input()) l=list(map(int,input().split())) a=[0];b=[0];ans=0;t1=0;t2=0 for i in range(len(l)-1): if l[i]<=l[i+1]: t1+=1 a.append(t1) else : a.append(0) t1=0 for j in range(len(l)-1,0,-1): if l[j]<l[j-1]: t2+=1 b.append(t2) el...
0
975
C
Valhalla Siege
PROGRAMMING
1,400
[ "binary search" ]
null
null
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T...
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths. The third line contains $q$ integers $k_1, k_2,...
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
[ "5 5\n1 2 1 2 1\n3 10 1 1 1\n", "4 4\n1 2 3 4\n9 1 10 6\n" ]
[ "3\n5\n4\n4\n3\n", "1\n4\n4\n1\n" ]
In the first example: - after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr...
1,500
[ { "input": "5 5\n1 2 1 2 1\n3 10 1 1 1", "output": "3\n5\n4\n4\n3" }, { "input": "4 4\n1 2 3 4\n9 1 10 6", "output": "1\n4\n4\n1" }, { "input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5", "output": "10\n10\n5" }, { "input": "1 1\n56563128\n897699770", "output": "1" }, { ...
1,697,286,909
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
102,400
class SegmentTree: def __init__(self, n, arr): self.n = n self.tree = [0] * (4 * n) self.lazy = [0] * (4 * n) self.build(1, 0, n - 1, arr) def build(self, v, tl, tr, arr): if tl == tr: self.tree[v] = arr[tl] else: tm = (tl + tr)...
Title: Valhalla Siege Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line ...
```python class SegmentTree: def __init__(self, n, arr): self.n = n self.tree = [0] * (4 * n) self.lazy = [0] * (4 * n) self.build(1, 0, n - 1, arr) def build(self, v, tl, tr, arr): if tl == tr: self.tree[v] = arr[tl] else: tm =...
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,682,745,536
2,147,483,647
Python 3
OK
TESTS
20
46
0
n = int(input()) word=[] selected=[] ss=[] for i in range(0, n): w=input() word.append(w) for i in range(0, n): counter = 0 for j in word[i]: counter+=1 if (counter>10): selected.append(word[i][0]) selected.append((counter-2)) selected.append(word[i][co...
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 n = int(input()) word=[] selected=[] ss=[] for i in range(0, n): w=input() word.append(w) for i in range(0, n): counter = 0 for j in word[i]: counter+=1 if (counter>10): selected.append(word[i][0]) selected.append((counter-2)) selected.append(...
3.977
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,657,882,779
2,147,483,647
Python 3
OK
TESTS
47
92
0
n=input() if n.count("1")+n.count("4")!=len(n)or n[0]=="4"or"1444"in n:print("NO") else: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 n=input() if n.count("1")+n.count("4")!=len(n)or n[0]=="4"or"1444"in n:print("NO") else:print("YES") ```
3
6
B
President's Office
PROGRAMMING
1,100
[ "implementation" ]
B. President's Office
2
64
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ...
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ...
Print the only number — the amount of President's deputies.
[ "3 4 R\nG.B.\n.RR.\nTTT.\n", "3 3 Z\n...\n.H.\n..Z\n" ]
[ "2\n", "0\n" ]
none
0
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.", "output": "2" }, { "input": "3 3 Z\n...\n.H.\n..Z", "output": "0" }, { "input": "1 1 C\nC", "output": "0" }, { "input": "2 2 W\nKW\nKW", "output": "1" }, { "input": "1 10 H\n....DDHHHH", "output": "1" }, { "input":...
1,599,131,294
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
204,800
import numpy as np def readInput(): m=int(input("enter the number of rows")) n=int(input("enter the number of coloumns")) c=input("enter the president desk colour of single character,eg:Red-R") a=[] for i in range(m): a.append([]) for j in range(n): deputChar=inp...
Title: President's Office Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ...
```python import numpy as np def readInput(): m=int(input("enter the number of rows")) n=int(input("enter the number of coloumns")) c=input("enter the president desk colour of single character,eg:Red-R") a=[] for i in range(m): a.append([]) for j in range(n): dep...
-1
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,578,675,069
2,147,483,647
Python 3
OK
TESTS
81
218
307,200
n=int(input()) s=0 x1=0 y1=0 z1=0 for i in range(n): x,y,z=map(int,input().split()) s=s+x+y+z x1=x1+x y1=y1+y z1=z1+z if s==0 and x1==0 and y1==0 and z1==0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n=int(input()) s=0 x1=0 y1=0 z1=0 for i in range(n): x,y,z=map(int,input().split()) s=s+x+y+z x1=x1+x y1=y1+y z1=z1+z if s==0 and x1==0 and y1==0 and z1==0: print('YES') else: print('NO') ```
3.944928
676
A
Nicholas and Permutation
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
[ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n" ]
[ "3\n", "6\n", "5\n" ]
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possib...
500
[ { "input": "5\n4 5 1 3 2", "output": "3" }, { "input": "7\n1 6 5 3 4 7 2", "output": "6" }, { "input": "6\n6 5 4 3 2 1", "output": "5" }, { "input": "2\n1 2", "output": "1" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "...
1,590,993,134
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
155
0
n=int(input()) l=list(map(int,input().split())) a=max(l) b=min(l) c=abs((l[0])-a) d=abs(l[0]-b) e=abs(l[-1]-a) f=abs(l[-1]-b) print(max(c,d,e,f))
Title: Nicholas and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integ...
```python n=int(input()) l=list(map(int,input().split())) a=max(l) b=min(l) c=abs((l[0])-a) d=abs(l[0]-b) e=abs(l[-1]-a) f=abs(l[-1]-b) print(max(c,d,e,f)) ```
0
929
B
Места в самолёте
PROGRAMMING
1,300
[ "*special", "implementation" ]
null
null
В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа. Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, ...
В первой строке следуют два целых числа *n* и *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10·*n*) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить. Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередно...
В первую строку выведите минимальное суммарное число соседей у статусных пассажиров. Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из *k* пассажиров, выведите стр...
[ "1 2\nSP.-SS.S-S.S\n", "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP\n" ]
[ "5\nSPx-SSxS-S.S\n", "15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP\n" ]
В первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров. Изначально, у статусного пассажи...
1,000
[ { "input": "1 2\nSP.-SS.S-S.S", "output": "5\nSPx-SSxS-S.S" }, { "input": "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP", "output": "15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP" }, { "input": "3 7\n.S.-SSSP-..S\nS..-.SPP-S.P\n.S.-PPPP-PSP", "output": "13...
1,520,076,102
71,202
Python 3
OK
TESTS
47
77
5,734,400
n, k = map(int, input().split()) r = list() for i in range(n): r.append(['-'] + list(input()) + ['-']) for i in range(n): if k == 0: break for j in range(1, 13): if r[i][j] == '.': if (r[i][j - 1] != 'S') and (r[i][j + 1] != 'S'): r[i][j] = "x" k -= 1 if k == 0: ...
Title: Места в самолёте Time Limit: None seconds Memory Limit: None megabytes Problem Description: В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа. ...
```python n, k = map(int, input().split()) r = list() for i in range(n): r.append(['-'] + list(input()) + ['-']) for i in range(n): if k == 0: break for j in range(1, 13): if r[i][j] == '.': if (r[i][j - 1] != 'S') and (r[i][j + 1] != 'S'): r[i][j] = "x" k -= 1 if k =...
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,641,999,156
2,147,483,647
PyPy 3-64
OK
TESTS
30
186
0
# Input s = input() # Main countUpperCases = 0 for char in s: if char.isupper(): countUpperCases += 1 if countUpperCases > len(s) - countUpperCases: print(s.upper()) else: print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python # Input s = input() # Main countUpperCases = 0 for char in s: if char.isupper(): countUpperCases += 1 if countUpperCases > len(s) - countUpperCases: print(s.upper()) else: print(s.lower()) ```
3.9535
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many w...
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,561,391,637
2,147,483,647
Python 3
OK
TESTS
38
109
0
a, b=[int(j) for j in input().split()] p, v, n=0, 0, 0 for i in range(6): if abs(i+1-a)<abs(i+1-b): p+=1 elif abs(i+1-b)<abs(i+1-a): v+=1 else: n+=1 print(p, n, v)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff...
```python a, b=[int(j) for j in input().split()] p, v, n=0, 0, 0 for i in range(6): if abs(i+1-a)<abs(i+1-b): p+=1 elif abs(i+1-b)<abs(i+1-a): v+=1 else: n+=1 print(p, n, v) ```
3
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,696,139,839
2,147,483,647
Python 3
OK
TESTS
48
46
0
nums = list(map(int, input().split())) nums.sort() diff = nums[1] - nums[0] + nums[2] - nums[1] print(diff)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python nums = list(map(int, input().split())) nums.sort() diff = nums[1] - nums[0] + nums[2] - nums[1] print(diff) ```
3
957
A
Tritonic Iridescence
PROGRAMMING
1,300
[ "implementation" ]
null
null
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas. Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co...
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas. The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted...
If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower).
[ "5\nCY??Y\n", "5\nC?C?Y\n", "5\n?CYC?\n", "5\nC??MM\n", "3\nMMY\n" ]
[ "Yes\n", "Yes\n", "Yes\n", "No\n", "No\n" ]
For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY. For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY. For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY. For the fourth example, no matter how th...
500
[ { "input": "5\nCY??Y", "output": "Yes" }, { "input": "5\nC?C?Y", "output": "Yes" }, { "input": "5\n?CYC?", "output": "Yes" }, { "input": "5\nC??MM", "output": "No" }, { "input": "3\nMMY", "output": "No" }, { "input": "15\n??YYYYYY??YYYY?", "output"...
1,521,911,998
6,298
Python 3
WRONG_ANSWER
PRETESTS
6
93
7,065,600
n = int(input()) query = list(input()) arr = [0 for i in range(n)] ans=[] low = 0 high = len(query) while low!=high: if query[low]!="?" and low!=len(query)-1: if query[low]==query[low+1]: ans.append("no") break low+=1 if "no" in ans: print("No") else: print...
Title: Tritonic Iridescence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas. Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one...
```python n = int(input()) query = list(input()) arr = [0 for i in range(n)] ans=[] low = 0 high = len(query) while low!=high: if query[low]!="?" and low!=len(query)-1: if query[low]==query[low+1]: ans.append("no") break low+=1 if "no" in ans: print("No") else: ...
0
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,695,623,175
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
def findlucky(n): while n > 0: d = n % 10 if d != 4 and d != 7: return "NO" n //= 10 return "YES" n = int(input()) print(findlucky(n))
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python def findlucky(n): while n > 0: d = n % 10 if d != 4 and d != 7: return "NO" n //= 10 return "YES" n = int(input()) print(findlucky(n)) ```
0
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" },...
1,694,717,098
2,147,483,647
Python 3
OK
TESTS
85
92
0
# Read the input user name user_name = input() # Count the number of distinct characters using a set distinct_chars = set(user_name) # Check if the count is even or odd and print the result accordingly if len(distinct_chars) % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though...
```python # Read the input user name user_name = input() # Count the number of distinct characters using a set distinct_chars = set(user_name) # Check if the count is even or odd and print the result accordingly if len(distinct_chars) % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!") ``...
3
711
B
Chris and Magic Square
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a *n*<=×<=*n* magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500) — the number of rows and columns of the magic grid. *n* lines follow, each of them contains *n* integers. The *j*-th number in the *i*-th of them denotes *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109 or *a**i*,<=*j*<==<=0), the number in the *i*-...
Output a single integer, the positive integer *x* (1<=≤<=*x*<=≤<=1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer *x* does not exist, output <=-<=1 instead. If there are multiple solutions, you may print any of them.
[ "3\n4 0 2\n3 5 7\n8 1 6\n", "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1\n", "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1\n" ]
[ "9\n", "1\n", "-1\n" ]
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 ...
1,000
[ { "input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9" }, { "input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1" }, { "input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n92 67 99 74 1 51 8 ...
1,631,059,475
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
# 3 # 4 0 2 # 3 5 7 # 8 1 6 def main(): n = int(input()) matrix = [] x, y = -1, -1 maxi, mini =0,0 for i in range(n): sum=0 row = [int(j) for j in input().split()] for k in range(len(row)): sum+=row[k] if(row[k]==0): x,y=...
Title: Chris and Magic Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a *n*<=×<=*n* magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is e...
```python # 3 # 4 0 2 # 3 5 7 # 8 1 6 def main(): n = int(input()) matrix = [] x, y = -1, -1 maxi, mini =0,0 for i in range(n): sum=0 row = [int(j) for j in input().split()] for k in range(len(row)): sum+=row[k] if(row[k]==0): ...
0
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single s...
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "...
1,593,337,320
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
6,656,000
n=int(input()) l=list(map(int,input().split())) s=sum(l) if (s+1)%(n+1)==1: print(2) else: print(1)
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the...
```python n=int(input()) l=list(map(int,input().split())) s=sum(l) if (s+1)%(n+1)==1: print(2) else: print(1) ```
0
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whe...
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO"...
1,676,689,708
2,147,483,647
Python 3
OK
TESTS
93
46
0
n,t,k,d = [int(x) for x in input().split()] # t1 = ((n+k-1)//k)*t # t2 = ((n // k) * (t//2)) +d # print(t1,t2) # # if t2 > t1: # # print('NO') # # else :print('YES') g = (n+k-1)//k o1=0 o2=d for i in range(g): if o1<=o2:o1+=t else : o2+=t if (max(o1,o2) < (g*t)): print('YES') else : ...
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu...
```python n,t,k,d = [int(x) for x in input().split()] # t1 = ((n+k-1)//k)*t # t2 = ((n // k) * (t//2)) +d # print(t1,t2) # # if t2 > t1: # # print('NO') # # else :print('YES') g = (n+k-1)//k o1=0 o2=d for i in range(g): if o1<=o2:o1+=t else : o2+=t if (max(o1,o2) < (g*t)): print('YES') ...
3
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,554,909,937
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
124
409,600
from collections import defaultdict s = input() d = defaultdict(int) for i in range(len(s)): d[s[i]] += 1 print(min(d['n']//3, d['i'], d['e']//3, d['t']))
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 from collections import defaultdict s = input() d = defaultdict(int) for i in range(len(s)): d[s[i]] += 1 print(min(d['n']//3, d['i'], d['e']//3, d['t'])) ```
0
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,696,073,386
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
m, s = map(int, input().split()) if (m > s or 9*(m) < s): print("-1 -1") else: smallest = [0] * m smallest[0] = 1 smallest_sum = s - 1 ptr = m - 1 while smallest_sum > 0: if smallest_sum >= 9: smallest[ptr] = 9 smallest_sum = smallest_sum - 9 ...
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python m, s = map(int, input().split()) if (m > s or 9*(m) < s): print("-1 -1") else: smallest = [0] * m smallest[0] = 1 smallest_sum = s - 1 ptr = m - 1 while smallest_sum > 0: if smallest_sum >= 9: smallest[ptr] = 9 smallest_sum = smallest_sum - ...
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,588,075,928
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
248
0
vowels = ['a', 'e', 'i', 'o', 'u', 'y'] question = input().strip()[:-1].strip() lower_question = [q.lower() for q in question] decide = lower_question[-1] if decide in vowels: print('YES') else: print(decide)
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 vowels = ['a', 'e', 'i', 'o', 'u', 'y'] question = input().strip()[:-1].strip() lower_question = [q.lower() for q in question] decide = lower_question[-1] if decide in vowels: print('YES') else: print(decide) ```
0
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half...
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the...
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n...
1,587,542,502
2,147,483,647
PyPy 3
OK
TESTS
59
342
1,228,800
n=int(input()) a=[] for i in range(0,n): a.append([int(j)for j in input().split()]) def isEven(x,l): up=0 down=0 for i in range(0,l): up+=x[i][0] down+=x[i][1] if up%2==0 and down%2==0: return 'yes' else: return 'no' flag=0 if isEven(a,n)=='yes': ...
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n...
```python n=int(input()) a=[] for i in range(0,n): a.append([int(j)for j in input().split()]) def isEven(x,l): up=0 down=0 for i in range(0,l): up+=x[i][0] down+=x[i][1] if up%2==0 and down%2==0: return 'yes' else: return 'no' flag=0 if isEven(a,n)=...
3
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n5100...
1,520,430,868
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
124
12,902,400
class RFYP: def main(self): n = int(input()) prize = [int(x) for x in input().split()] temp = 1 count = 0 for i in range(n): if(prize[i] - 2 < 999999 - prize[i]): count = count + prize[i] - temp else: cou...
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are di...
```python class RFYP: def main(self): n = int(input()) prize = [int(x) for x in input().split()] temp = 1 count = 0 for i in range(n): if(prize[i] - 2 < 999999 - prize[i]): count = count + prize[i] - temp else: ...
0
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea...
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *...
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "outpu...
1,694,835,049
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
92
0
heights = list(map(int, input().split(" "))) n = heights[0] t = heights[1] #print(a + " " + b) line = list(input()) #print(line) def swap(x, y, data): temp = data[x] data[x] = data[y] data[y] = temp skipNext = False for i in range(t): for j in range(n-1): if skipNext: ...
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a...
```python heights = list(map(int, input().split(" "))) n = heights[0] t = heights[1] #print(a + " " + b) line = list(input()) #print(line) def swap(x, y, data): temp = data[x] data[x] = data[y] data[y] = temp skipNext = False for i in range(t): for j in range(n-1): if skipNext...
0
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }...
1,660,283,786
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
21
93
14,438,400
n=int(input()) li=list(map(int,input().split())) lst=li.copy() lst.sort() if(li==lst): print(0) quit() y=li.index(lst[0]) sub=li[y:] # print(sub) if(sub+li[:y])==lst: print(len(sub)) else:print(-1)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ...
```python n=int(input()) li=list(map(int,input().split())) lst=li.copy() lst.sort() if(li==lst): print(0) quit() y=li.index(lst[0]) sub=li[y:] # print(sub) if(sub+li[:y])==lst: print(len(sub)) else:print(-1) ```
0
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY...
1,697,255,591
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
n = int(input()) s=input() s1="ABCDEFGHIJKLMNOPQRSTUVWXYZ" s2=set(s) if s2.upper()==s1: print("YES") else: print("NO")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. ...
```python n = int(input()) s=input() s1="ABCDEFGHIJKLMNOPQRSTUVWXYZ" s2=set(s) if s2.upper()==s1: print("YES") else: print("NO") ```
-1
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,638,027,969
2,147,483,647
Python 3
OK
TESTS
34
92
102,400
from collections import Counter n = int(input("")) lista =[] for i in range(0,n): lista.append(input('')) m = list(dict(Counter(lista)).values()) i = m.index(max(m)) print(list(dict(Counter(lista)).keys())[i])
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python from collections import Counter n = int(input("")) lista =[] for i in range(0,n): lista.append(input('')) m = list(dict(Counter(lista)).values()) i = m.index(max(m)) print(list(dict(Counter(lista)).keys())[i]) ```
3.976809
1,010
B
Rocket
PROGRAMMING
1,800
[ "binary search", "interactive" ]
null
null
This is an interactive problem. Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet...
The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$.
none
[ "5 2\n1\n-1\n-1\n1\n0\n" ]
[ "1\n2\n4\n5\n3\n" ]
In the example, hacking would look like this: 5 2 3 1 0 This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ... Really: on the first query ($1$) the correct answer is $1$, the rocket...
750
[ { "input": "5 2 3\n1 0", "output": "3 queries, x=3" }, { "input": "1 1 1\n1", "output": "1 queries, x=1" }, { "input": "3 2 3\n1 0", "output": "4 queries, x=3" }, { "input": "6 3 5\n1 1 1", "output": "5 queries, x=5" }, { "input": "10 4 3\n0 0 1 0", "output": ...
1,552,649,959
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
def f(): m, n = map(int, input().split()) B = [] for i in range(n): print(1) #System.out.flush() k = int(input()) if k == 0: print(1) return 0 else: if k == 1: B.append(1) else: ...
Title: Rocket Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. ...
```python def f(): m, n = map(int, input().split()) B = [] for i in range(n): print(1) #System.out.flush() k = int(input()) if k == 0: print(1) return 0 else: if k == 1: B.append(1) else: ...
0
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "...
1,698,829,515
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
n=int(input()) print(math.ceil(n/5))
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input...
```python n=int(input()) print(math.ceil(n/5)) ```
-1
679
A
Bear and Prime 100
PROGRAMMING
1,400
[ "constructive algorithms", "interactive", "math" ]
null
null
This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two d...
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu...
[ "yes\nno\nyes\n", "no\nyes\nno\nno\nno\n" ]
[ "2\n80\n5\ncomposite\n", "58\n59\n78\n78\n2\nprime\n" ]
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/> The hi...
750
[ { "input": "30", "output": "composite 4" }, { "input": "59", "output": "prime 15" }, { "input": "2", "output": "prime 16" }, { "input": "7", "output": "prime 16" }, { "input": "9", "output": "composite 3" }, { "input": "13", "output": "prime 15" ...
1,468,858,034
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
0
#!/usr/bin/env python3 from sys import stdout def main(): primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47) print('\n'.join([str(x) for x in primes])) stdout.flush() ans = [input() for _ in primes] print('composite' if ans.count('yes') >= 2 else 'prime') if __name__ == '__main__':...
Title: Bear and Prime 100 Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say i...
```python #!/usr/bin/env python3 from sys import stdout def main(): primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47) print('\n'.join([str(x) for x in primes])) stdout.flush() ans = [input() for _ in primes] print('composite' if ans.count('yes') >= 2 else 'prime') if __name__ == '...
0
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the h...
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th...
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "inp...
1,689,883,173
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
1
77
2,867,200
n, k = map(int, input().split()) h = [int(i) for i in input().split()] pref_sum = [h[0]] sumk = [] for i in range(1, n): pref_sum.append(pref_sum[i-1] + h[i]) for l in range(0, n-k): if l == 0: sumk.append(pref_sum[k-1]) else: sumk.append(pref_sum[l+k-1] - pref_sum[l-1]) p...
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ...
```python n, k = map(int, input().split()) h = [int(i) for i in input().split()] pref_sum = [h[0]] sumk = [] for i in range(1, n): pref_sum.append(pref_sum[i-1] + h[i]) for l in range(0, n-k): if l == 0: sumk.append(pref_sum[k-1]) else: sumk.append(pref_sum[l+k-1] - pref_sum[l-1]...
-1
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,675,429,567
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
# Way Too Long Words t = int(input()) for tt in range(t): s = input() n = len(s) if (n<10): print(s) else: print(s[0] + str(n-2) + s[-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 # Way Too Long Words t = int(input()) for tt in range(t): s = input() n = len(s) if (n<10): print(s) else: print(s[0] + str(n-2) + s[-1]) ```
0
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,695,553,125
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
k , n , w = int(print()) somme = 0 for i in range (w) : somme = somme + i - k if somme > n : x = somme -k print (x) else : print (0)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He h...
```python k , n , w = int(print()) somme = 0 for i in range (w) : somme = somme + i - k if somme > n : x = somme -k print (x) else : print (0) ```
-1
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,659,415,884
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
m=int(input()) n=int(input()) print (n*m/2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python m=int(input()) n=int(input()) print (n*m/2) ```
-1
855
A
Tom Riddle's Diary
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
[ "6\ntom\nlucius\nginny\nharry\nginny\nharry\n", "3\na\na\na\n" ]
[ "NO\nNO\nNO\nNO\nYES\nYES\n", "NO\nYES\nYES\n" ]
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
500
[ { "input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES" }, { "input": "3\na\na\na", "output": "NO\nYES\nYES" }, { "input": "1\nzn", "output": "NO" }, { "input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb...
1,584,119,364
2,147,483,647
Python 3
OK
TESTS
55
124
0
n=int(input()) l1=[] for i in range(n): s=input() if s in l1: print("Yes") else: print("No") l1.append(s)
Title: Tom Riddle's Diary Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ...
```python n=int(input()) l1=[] for i in range(n): s=input() if s in l1: print("Yes") else: print("No") l1.append(s) ```
3
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: -...
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "...
1,503,598,733
2,147,483,647
Python 3
OK
TESTS
29
77
0
sticks = [int(x) for x in input().split()] alien = True for stick in sticks: if sticks.count(stick) >= 4: for i in range(4): sticks.remove(stick) alien = False break if not alien: if abs(sticks[0] - sticks[1]) > 0: print("Bear") else: pri...
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an...
```python sticks = [int(x) for x in input().split()] alien = True for stick in sticks: if sticks.count(stick) >= 4: for i in range(4): sticks.remove(stick) alien = False break if not alien: if abs(sticks[0] - sticks[1]) > 0: print("Bear") 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,539,921,469
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
0
I = input(); a = int(input()) - 1 if len(I) == 5: a -= 1 print("L") if a != 0 else print("R")
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 I = input(); a = int(input()) - 1 if len(I) == 5: a -= 1 print("L") if a != 0 else print("R") ```
-1
194
A
Exams
PROGRAMMING
900
[ "implementation", "math" ]
null
null
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha...
The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*.
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*.
[ "4 8\n", "4 10\n", "1 3\n" ]
[ "4\n", "2\n", "0\n" ]
In the first sample the author has to get a 2 for all his exams. In the second sample he should get a 3 for two exams and a 2 for two more. In the third sample he should get a 3 for one exam.
500
[ { "input": "4 8", "output": "4" }, { "input": "4 10", "output": "2" }, { "input": "1 3", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "4 9", "output": "3" }, { "input": "50 234", "output": "0" }, { "input": "50 100", "...
1,697,420,583
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
print('test') # Mon Oct 16 2023 04:43:00 GMT+0300 (Moscow Standard Time)
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend ...
```python print('test') # Mon Oct 16 2023 04:43:00 GMT+0300 (Moscow Standard Time) ```
0
95
B
Lucky Numbers
PROGRAMMING
1,800
[ "dp", "greedy" ]
B. Lucky Numbers
2
256
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=10100000). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to *n*.
[ "4500\n", "47\n" ]
[ "4747\n", "47\n" ]
none
1,000
[ { "input": "4500", "output": "4747" }, { "input": "47", "output": "47" }, { "input": "1", "output": "47" }, { "input": "12", "output": "47" }, { "input": "4587", "output": "4747" }, { "input": "100", "output": "4477" }, { "input": "1007", ...
1,684,164,758
2,147,483,647
PyPy 3-64
OK
TESTS
86
622
20,480,000
from sys import stdin, stdout from collections import deque MOD = 10 ** 9 + 7 INF = float('inf') sze = 10 ** 4 + 1 EPS = 10 ** -6 s = stdin.readline().strip() challenger = [] for i in range(len(s)): if s[i] in '47': challenger.append(s[i]) elif s[i] in '89': ...
Title: Lucky Numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky n...
```python from sys import stdin, stdout from collections import deque MOD = 10 ** 9 + 7 INF = float('inf') sze = 10 ** 4 + 1 EPS = 10 ** -6 s = stdin.readline().strip() challenger = [] for i in range(len(s)): if s[i] in '47': challenger.append(s[i]) elif s[i]...
3.806353
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son...
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE...
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "...
1,678,010,307
2,147,483,647
PyPy 3-64
OK
TESTS
71
124
0
# A. Дабстеп def func(str2): return str2.replace('WUB', ' ') str1 = input() print(func(str1))
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consist...
```python # A. Дабстеп def func(str2): return str2.replace('WUB', ' ') str1 = input() print(func(str1)) ```
3
833
B
The Bakery
PROGRAMMING
2,200
[ "binary search", "data structures", "divide and conquer", "dp", "two pointers" ]
null
null
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack ca...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them.
Print the only integer – the maximum total value of all boxes with cakes.
[ "4 1\n1 2 2 1\n", "7 2\n1 3 3 1 4 4 4\n", "8 3\n7 7 8 7 7 8 1 7\n" ]
[ "2\n", "5\n", "6\n" ]
In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2. In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box...
1,250
[ { "input": "4 1\n1 2 2 1", "output": "2" }, { "input": "7 2\n1 3 3 1 4 4 4", "output": "5" }, { "input": "8 3\n7 7 8 7 7 8 1 7", "output": "6" }, { "input": "50 5\n2 39 16 20 32 36 29 42 14 23 9 4 28 17 45 16 46 1 39 33 47 15 34 43 6 6 12 15 46 11 32 16 31 12 41 33 47 35 22 3...
1,690,531,171
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
102,400
class SegmentTree: def __init__(self, size): self.size = size self.tree = [0] * (4 * size) def update(self, node, left, right, index, value): if left == right == index: self.tree[node] = value return mid = (left + right) // 2 if index ...
Title: The Bakery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the...
```python class SegmentTree: def __init__(self, size): self.size = size self.tree = [0] * (4 * size) def update(self, node, left, right, index, value): if left == right == index: self.tree[node] = value return mid = (left + right) // 2 ...
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,681,815,434
2,147,483,647
PyPy 3
MEMORY_LIMIT_EXCEEDED
TESTS
8
496
67,072,000
import math def lcs(a, b): lengths = [[0] * (len(b) + 1) for _ in range(len(a) + 1)] for i, x in enumerate(a): for j, y in enumerate(b): if x == y: lengths[i + 1][j + 1] = lengths[i][j] + 1 else: lengths[i + 1][j + 1] = max(lengths[i + 1]...
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 import math def lcs(a, b): lengths = [[0] * (len(b) + 1) for _ in range(len(a) + 1)] for i, x in enumerate(a): for j, y in enumerate(b): if x == y: lengths[i + 1][j + 1] = lengths[i][j] + 1 else: lengths[i + 1][j + 1] = max(leng...
0
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}...
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All sub...
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"...
1,572,685,439
2,147,483,647
PyPy 3
OK
TESTS
133
156
0
s=input() f=0 for i in range(len(s)-1,-1,-1): sub=s[0:i+1] if(sub!=sub[::-1]): f=1 print(i+1) break if f==0: print(0)
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar...
```python s=input() f=0 for i in range(len(s)-1,-1,-1): sub=s[0:i+1] if(sub!=sub[::-1]): f=1 print(i+1) break if f==0: print(0) ```
3
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon piece...
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, ...
1,690,312,202
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
def cortar_cinta(original, longitud1, longitud2, longitud3): variable_dinamica = [-1] * (original + 1) variable_dinamica[0] = 0 for i in range(1, original + 1): if i >= longitud1: variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud1] + 1) if i >= longi...
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the...
```python def cortar_cinta(original, longitud1, longitud2, longitud3): variable_dinamica = [-1] * (original + 1) variable_dinamica[0] = 0 for i in range(1, original + 1): if i >= longitud1: variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud1] + 1) if ...
-1
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,688,063,053
2,147,483,647
Python 3
OK
TESTS
34
31
0
n = int(input()) s = input() last = [] first = [] is_last = True for i in range(n-1,-1,-1): if is_last: last.append(s[i]) else: first.append(s[i]) is_last = not is_last # print(first) # print(last) ans = ''.join(first) ans = ans + ''.join(last[::-1]) print(ans)
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() last = [] first = [] is_last = True for i in range(n-1,-1,-1): if is_last: last.append(s[i]) else: first.append(s[i]) is_last = not is_last # print(first) # print(last) ans = ''.join(first) ans = ans + ''.join(last[::-1]) print(ans) ```
3