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
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 wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
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, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.
500
[ { "input": "1\n1", "output": "1" }, { "input": "10\n1 2 2 3 4 4 4 2 2 2", "output": "8" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 99", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 2", "output": "2" }, { "input": "2\n1 2", "o...
1,672,053,209
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
def solve(n, a): count = 0 for i in range(n): for j in range(i+1, n+1): if sum(a[i:j]) % 2 == 1: count += 1 return count n = int(input()) a = list(map(int, input().split())) print(solve(n, a))
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 want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? Input Specification: 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. Output Specification: Print in the only line the only number — the sought number of ways. If there are no such ways print 0. Demo Input: ['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'] Demo Output: ['1\n', '8\n', '1\n'] Note: 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, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.
```python def solve(n, a): count = 0 for i in range(n): for j in range(i+1, n+1): if sum(a[i:j]) % 2 == 1: count += 1 return count n = int(input()) a = list(map(int, input().split())) print(solve(n, a)) ```
0
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "inpu...
1,558,927,402
2,147,483,647
PyPy 3
OK
TESTS
41
140
0
x = int(input()) n=1 lvl_arr = [0] def LvL(n): lvl_arr.append(2**(n-1)*5 + lvl_arr[n-1]) return lvl_arr[n] while(x > LvL(n)): n = n+1 p = ((x - lvl_arr[n-1] - 1) // 2**(n-1)) + 1 if(p == 1): print("Sheldon") elif(p == 2): print("Leonard") elif(p == 3): print("Penny") elif(p == 4): print("Rajesh") else: print("Howard")
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input Specification: The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Specification: Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Demo Input: ['1\n', '6\n', '1802\n'] Demo Output: ['Sheldon\n', 'Sheldon\n', 'Penny\n'] Note: none
```python x = int(input()) n=1 lvl_arr = [0] def LvL(n): lvl_arr.append(2**(n-1)*5 + lvl_arr[n-1]) return lvl_arr[n] while(x > LvL(n)): n = n+1 p = ((x - lvl_arr[n-1] - 1) // 2**(n-1)) + 1 if(p == 1): print("Sheldon") elif(p == 2): print("Leonard") elif(p == 3): print("Penny") elif(p == 4): print("Rajesh") else: print("Howard") ```
3.93
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,683,039,348
2,147,483,647
Python 3
OK
TESTS
20
46
0
n,m,a=map(int,input().split()) l1=n//a l2=m//a if n//a<n/a: l1=n//a+1 if m//a<m/a: l2=m//a +1 soni=l1*l2 print(soni)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n,m,a=map(int,input().split()) l1=n//a l2=m//a if n//a<n/a: l1=n//a+1 if m//a<m/a: l2=m//a +1 soni=l1*l2 print(soni) ```
3.977
111
A
Petya and Inequiations
PROGRAMMING
1,400
[ "greedy" ]
A. Petya and Inequiations
2
256
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied: - *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y*
The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator.
Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.
[ "5 15 15\n", "2 3 2\n", "1 99 11\n" ]
[ "4\n4\n1\n1\n2\n", "-1\n", "11\n" ]
none
500
[ { "input": "5 15 15", "output": "11\n1\n1\n1\n1" }, { "input": "2 3 2", "output": "-1" }, { "input": "1 99 11", "output": "11" }, { "input": "100000 810000099998 1000000", "output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n...
1,590,925,696
2,147,483,647
PyPy 3
OK
TESTS
62
436
8,089,600
n,x,y=map(int,input().split()) import math an=n-1 if(x<=n-1): if(y>=n): for i in range(n): print(1) else: print(-1) else: me=math.sqrt(x-an) if(me==int(me)): me=int(me) if(me+an<=y): for i in range(n-1): print(1) print(me) else: print(-1) else: me=int(me) me+=1 if(me+an<=y): for i in range(n-1): print(1) print(me) else: print(-1)
Title: Petya and Inequiations Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied: - *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y* Input Specification: The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=1012,<=1<=≤<=*y*<=≤<=106). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator. Output Specification: Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Demo Input: ['5 15 15\n', '2 3 2\n', '1 99 11\n'] Demo Output: ['4\n4\n1\n1\n2\n', '-1\n', '11\n'] Note: none
```python n,x,y=map(int,input().split()) import math an=n-1 if(x<=n-1): if(y>=n): for i in range(n): print(1) else: print(-1) else: me=math.sqrt(x-an) if(me==int(me)): me=int(me) if(me+an<=y): for i in range(n-1): print(1) print(me) else: print(-1) else: me=int(me) me+=1 if(me+an<=y): for i in range(n-1): print(1) print(me) else: print(-1) ```
3.875932
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 that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
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,678,595,672
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
N = 200 vis = [0]*30 def main(): n = int(input()) for _ in range(n): ss = input().strip() vis.clear() vis = [0]*30 l = len(ss) f = True mx = 0 mi = 110 for i in range(l): vis[ord(ss[i])-ord('a')] = 1 mx = max(mx, ord(ss[i])-ord('a')) mi = min(mi, ord(ss[i])-ord('a')) for i in range(mi, mx+1): if vis[i] == 0: f = False break if f and mx-mi+1 == l: print("Yes") else: print("No")
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 either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: 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. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python N = 200 vis = [0]*30 def main(): n = int(input()) for _ in range(n): ss = input().strip() vis.clear() vis = [0]*30 l = len(ss) f = True mx = 0 mi = 110 for i in range(l): vis[ord(ss[i])-ord('a')] = 1 mx = max(mx, ord(ss[i])-ord('a')) mi = min(mi, ord(ss[i])-ord('a')) for i in range(mi, mx+1): if vis[i] == 0: f = False break if f and mx-mi+1 == l: print("Yes") else: print("No") ```
0
157
B
Trace
PROGRAMMING
1,000
[ "geometry", "sortings" ]
null
null
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different.
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
[ "1\n1\n", "3\n1 4 2\n" ]
[ "3.1415926536\n", "40.8407044967\n" ]
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π
1,000
[ { "input": "1\n1", "output": "3.1415926536" }, { "input": "3\n1 4 2", "output": "40.8407044967" }, { "input": "4\n4 1 3 2", "output": "31.4159265359" }, { "input": "4\n100 10 2 1", "output": "31111.1920484997" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output"...
1,683,785,948
2,147,483,647
Python 3
OK
TESTS
44
92
0
# Description of the problem can be found at http://codeforces.com/problemset/problem/157/B import math n = int(input()) l_s = list(map(int, input().split())) l_s.sort(reverse = True) t = 0 for index in range(n): t += (-1 if index % 2 == 1 else 1) * l_s[index] ** 2 print(t * math.pi)
Title: Trace Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. Output Specification: Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. Demo Input: ['1\n1\n', '3\n1 4 2\n'] Demo Output: ['3.1415926536\n', '40.8407044967\n'] Note: In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π
```python # Description of the problem can be found at http://codeforces.com/problemset/problem/157/B import math n = int(input()) l_s = list(map(int, input().split())) l_s.sort(reverse = True) t = 0 for index in range(n): t += (-1 if index % 2 == 1 else 1) * l_s[index] ** 2 print(t * math.pi) ```
3
863
A
Quasi-palindrome
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number *x*. Check if it's a quasi-palindromic number.
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
[ "131\n", "320\n", "2010200\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
0
[ { "input": "131", "output": "YES" }, { "input": "320", "output": "NO" }, { "input": "2010200", "output": "YES" }, { "input": "1", "output": "YES" }, { "input": "1000000000", "output": "YES" }, { "input": "999999999", "output": "YES" }, { "i...
1,691,031,915
2,147,483,647
PyPy 3-64
OK
TESTS
44
62
0
x=list(input()) x.reverse() g=False while len(x)>1: if x[0]=='0' and g==False: x.pop(0) else: g=True if x[0]!=x[-1]: print('NO') exit() else: x.pop(0) x.pop() print("YES")
Title: Quasi-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number *x*. Check if it's a quasi-palindromic number. Input Specification: The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. Output Specification: Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). Demo Input: ['131\n', '320\n', '2010200\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python x=list(input()) x.reverse() g=False while len(x)>1: if x[0]=='0' and g==False: x.pop(0) else: g=True if x[0]!=x[-1]: print('NO') exit() else: x.pop(0) x.pop() print("YES") ```
3
137
C
History
PROGRAMMING
1,500
[ "sortings" ]
null
null
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=&lt;<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=&lt;<=*a**i* and *b**i*<=&lt;<=*b**j*. Your task is simpler: find the number of events that are included in some other event.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order.
Print the only integer — the answer to the problem.
[ "5\n1 10\n2 9\n3 8\n4 7\n5 6\n", "5\n1 100\n2 50\n51 99\n52 98\n10 60\n", "1\n1 1000000000\n" ]
[ "4\n", "4\n", "0\n" ]
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first. In the second example all events except the first one are contained in the first. In the third example only one event, so the answer is 0.
1,500
[ { "input": "5\n1 10\n2 9\n3 8\n4 7\n5 6", "output": "4" }, { "input": "5\n1 100\n2 50\n51 99\n52 98\n10 60", "output": "4" }, { "input": "1\n1 1000000000", "output": "0" }, { "input": "2\n100 1000\n500 1500", "output": "0" }, { "input": "4\n1 100\n50 150\n120 200\...
1,603,274,167
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
3,891,200
n = int(input()) arr=[] for _ in range(n): x,y = map(int,input().split()) arr.append((x,y)) c=0 arr.sort(key=lambda arr:arr[0]) visited = [] for i in range(n): low = arr[i][0] high = arr[i][1] for j in range(i+1,n): if j not in visited: if arr[j][1]<=high and arr[j][0]>=low: c+=1 visited.append(j) print (c)
Title: History Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=&lt;<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=&lt;<=*a**i* and *b**i*<=&lt;<=*b**j*. Your task is simpler: find the number of events that are included in some other event. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order. Output Specification: Print the only integer — the answer to the problem. Demo Input: ['5\n1 10\n2 9\n3 8\n4 7\n5 6\n', '5\n1 100\n2 50\n51 99\n52 98\n10 60\n', '1\n1 1000000000\n'] Demo Output: ['4\n', '4\n', '0\n'] Note: In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first. In the second example all events except the first one are contained in the first. In the third example only one event, so the answer is 0.
```python n = int(input()) arr=[] for _ in range(n): x,y = map(int,input().split()) arr.append((x,y)) c=0 arr.sort(key=lambda arr:arr[0]) visited = [] for i in range(n): low = arr[i][0] high = arr[i][1] for j in range(i+1,n): if j not in visited: if arr[j][1]<=high and arr[j][0]>=low: c+=1 visited.append(j) print (c) ```
0
175
A
Robot Bicorn Attack
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
Vasya plays Robot Bicorn Attack. The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string *s*. Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.
The only line of input contains non-empty string *s* obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.
Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.
[ "1234\n", "9000\n", "0009\n" ]
[ "37\n", "90\n", "-1\n" ]
In the first example the string must be split into numbers 1, 2 and 34. In the second example the string must be split into numbers 90, 0 and 0. In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes.
500
[ { "input": "1234", "output": "37" }, { "input": "9000", "output": "90" }, { "input": "0009", "output": "-1" }, { "input": "100000010000001000000", "output": "3000000" }, { "input": "1000000011", "output": "1000011" }, { "input": "9991", "output": "...
1,498,728,138
1,338
Python 3
WRONG_ANSWER
TESTS
3
61
5,529,600
a=input() s=len(a) ans=-1 for i in range(s-2): for j in range(i+1,s-1): if (i+1>0+1 and a[0]=="0") or (j+1>i+2 and a[i+1]=="0") or (s>j+2 and a[j+1]=="0"): continue ans=max(ans,int(a[0:i+1])+int(a[i+1:j+1])+int(a[j+1:s])) print(ans)
Title: Robot Bicorn Attack Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya plays Robot Bicorn Attack. The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string *s*. Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round. Input Specification: The only line of input contains non-empty string *s* obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters. Output Specification: Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1. Demo Input: ['1234\n', '9000\n', '0009\n'] Demo Output: ['37\n', '90\n', '-1\n'] Note: In the first example the string must be split into numbers 1, 2 and 34. In the second example the string must be split into numbers 90, 0 and 0. In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes.
```python a=input() s=len(a) ans=-1 for i in range(s-2): for j in range(i+1,s-1): if (i+1>0+1 and a[0]=="0") or (j+1>i+2 and a[i+1]=="0") or (s>j+2 and a[j+1]=="0"): continue ans=max(ans,int(a[0:i+1])+int(a[i+1:j+1])+int(a[j+1:s])) print(ans) ```
0
598
D
Igor In the Museum
PROGRAMMING
1,700
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
[ "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n", "4 4 1\n****\n*..*\n*.**\n****\n3 2\n" ]
[ "6\n4\n10\n", "8\n" ]
none
0
[ { "input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3", "output": "6\n4\n10" }, { "input": "4 4 1\n****\n*..*\n*.**\n****\n3 2", "output": "8" }, { "input": "3 3 1\n***\n*.*\n***\n2 2", "output": "4" }, { "input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\...
1,682,988,850
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
27,852,800
def dfs(x, y, n, m, museum, visited): if x < 0 or x >= n or y < 0 or y >= m or visited[x][y] or museum[x][y] == '*': return 0 visited[x][y] = True pictures = 0 for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): if 0 <= x + dx < n and 0 <= y + dy < m and museum[x + dx][y + dy] == '*': pictures += 1 else: pictures += dfs(x + dx, y + dy, n, m, museum, visited) return pictures def igor_in_the_museum(n, m, k, museum, starting_positions): results = [] for x, y in starting_positions: visited = [[False] * m for _ in range(n)] result = dfs(x - 1, y - 1, n, m, museum, visited) results.append(result) return results # Reading input n, m, k = map(int, input().split()) museum = [input() for _ in range(n)] starting_positions = [tuple(map(int, input().split())) for _ in range(k)] # Solving problem result = igor_in_the_museum(n, m, k, museum, starting_positions) # Printing output for num_pictures in result: print(num_pictures)
Title: Igor In the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see. Input Specification: First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells. Output Specification: Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. Demo Input: ['5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n', '4 4 1\n****\n*..*\n*.**\n****\n3 2\n'] Demo Output: ['6\n4\n10\n', '8\n'] Note: none
```python def dfs(x, y, n, m, museum, visited): if x < 0 or x >= n or y < 0 or y >= m or visited[x][y] or museum[x][y] == '*': return 0 visited[x][y] = True pictures = 0 for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): if 0 <= x + dx < n and 0 <= y + dy < m and museum[x + dx][y + dy] == '*': pictures += 1 else: pictures += dfs(x + dx, y + dy, n, m, museum, visited) return pictures def igor_in_the_museum(n, m, k, museum, starting_positions): results = [] for x, y in starting_positions: visited = [[False] * m for _ in range(n)] result = dfs(x - 1, y - 1, n, m, museum, visited) results.append(result) return results # Reading input n, m, k = map(int, input().split()) museum = [input() for _ in range(n)] starting_positions = [tuple(map(int, input().split())) for _ in range(k)] # Solving problem result = igor_in_the_museum(n, m, k, museum, starting_positions) # Printing output for num_pictures in result: print(num_pictures) ```
0
938
A
Word Correction
PROGRAMMING
800
[ "implementation" ]
null
null
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct. You are given a word *s*. Can you predict what will it become after correction? In this problem letters a, e, i, o, u and y are considered to be vowels.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output the word *s* after the correction.
[ "5\nweird\n", "4\nword\n", "5\naaeaa\n" ]
[ "werd\n", "word\n", "a\n" ]
Explanations of the examples: 1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
0
[ { "input": "5\nweird", "output": "werd" }, { "input": "4\nword", "output": "word" }, { "input": "5\naaeaa", "output": "a" }, { "input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw", "output": "abbbbbocadabbbbb...
1,609,959,402
2,147,483,647
PyPy 3
OK
TESTS
49
140
0
vowels = ['a', 'e', 'i', 'o', 'u', 'y'] def word_correction(s): result = [] result.append(s[0]) left = 0 right = 1 while right < len(s): if not s[left] in vowels or not s[right] in vowels: result.append(s[right]) left = right right += 1 return ''.join(result) n = int(input()) s = input() print(word_correction(s))
Title: Word Correction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct. You are given a word *s*. Can you predict what will it become after correction? In this problem letters a, e, i, o, u and y are considered to be vowels. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. Output Specification: Output the word *s* after the correction. Demo Input: ['5\nweird\n', '4\nword\n', '5\naaeaa\n'] Demo Output: ['werd\n', 'word\n', 'a\n'] Note: Explanations of the examples: 1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
```python vowels = ['a', 'e', 'i', 'o', 'u', 'y'] def word_correction(s): result = [] result.append(s[0]) left = 0 right = 1 while right < len(s): if not s[left] in vowels or not s[right] in vowels: result.append(s[right]) left = right right += 1 return ''.join(result) n = int(input()) s = input() print(word_correction(s)) ```
3
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total.
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7...
1,596,369,657
2,147,483,647
Python 3
OK
TESTS
33
278
6,963,200
n, m = map(int,input().split()) l = list(map(int,input().split())) def g(f): A = l[:]; s = 0 for _ in range(n): i = A.index(f(A)); s += A[i] if A[i] > 1: A[i] -= 1; else: A.pop(i) return s print (g(max), g(min))
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total. Output Specification: Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. Demo Input: ['4 3\n2 1 1\n', '4 3\n2 2 2\n'] Demo Output: ['5 5\n', '7 6\n'] Note: In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
```python n, m = map(int,input().split()) l = list(map(int,input().split())) def g(f): A = l[:]; s = 0 for _ in range(n): i = A.index(f(A)); s += A[i] if A[i] > 1: A[i] -= 1; else: A.pop(i) return s print (g(max), g(min)) ```
3
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Print a single integer — the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { ...
1,674,062,410
2,147,483,647
Python 3
OK
TESTS
49
78
0
n = list(map(int, input().strip().split())) m = input() s = 0 for i in range(len(m)): s += n[int(m[i])-1] print(s)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? Input Specification: The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. Output Specification: Print a single integer — the total number of calories that Jury wastes. Demo Input: ['1 2 3 4\n123214\n', '1 5 3 2\n11221\n'] Demo Output: ['13\n', '13\n'] Note: none
```python n = list(map(int, input().strip().split())) m = input() s = 0 for i in range(len(m)): s += n[int(m[i])-1] print(s) ```
3
719
A
Vitya in the Countryside
PROGRAMMING
1,100
[ "implementation" ]
null
null
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records. It's guaranteed that the input data is consistent.
If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
[ "5\n3 4 5 6 7\n", "7\n12 13 14 15 14 13 12\n", "1\n8\n" ]
[ "UP\n", "DOWN\n", "-1\n" ]
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
500
[ { "input": "5\n3 4 5 6 7", "output": "UP" }, { "input": "7\n12 13 14 15 14 13 12", "output": "DOWN" }, { "input": "1\n8", "output": "-1" }, { "input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10", "out...
1,477,465,385
2,147,483,647
Python 3
OK
TESTS
56
62
0
n=int(input()) l=list(map(int,input().split())) if n==1 and l[0]!=15 and l[0]!=0 : print(-1) else : if l[n-1]==15 : print('DOWN') if l[n-1]==0 : print('UP') if l[n-1]!=15 and l[n-1]!=0 and n!=1 : if l[n-1]-l[n-2]>0 : print('UP') else : print('DOWN')
Title: Vitya in the Countryside Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records. It's guaranteed that the input data is consistent. Output Specification: If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. Demo Input: ['5\n3 4 5 6 7\n', '7\n12 13 14 15 14 13 12\n', '1\n8\n'] Demo Output: ['UP\n', 'DOWN\n', '-1\n'] Note: In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
```python n=int(input()) l=list(map(int,input().split())) if n==1 and l[0]!=15 and l[0]!=0 : print(-1) else : if l[n-1]==15 : print('DOWN') if l[n-1]==0 : print('UP') if l[n-1]!=15 and l[n-1]!=0 and n!=1 : if l[n-1]-l[n-2]>0 : print('UP') else : print('DOWN') ```
3
13
A
Numbers
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Numbers
1
64
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.
Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000).
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
[ "5\n", "3\n" ]
[ "7/3\n", "2/1\n" ]
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
0
[ { "input": "5", "output": "7/3" }, { "input": "3", "output": "2/1" }, { "input": "1000", "output": "90132/499" }, { "input": "927", "output": "155449/925" }, { "input": "260", "output": "6265/129" }, { "input": "131", "output": "3370/129" }, { ...
1,649,863,186
2,147,483,647
Python 3
OK
TESTS
99
92
0
N = int(input()) s = 0 def gcd(a, b): while(b): a, b = b, a%b return a for i in range(2, N): n = N while(n>0): s += n%i n = n//i t = gcd(s, N-2) print(str(s//t)+"/"+str((N-2)//t))
Title: Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10. Input Specification: Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). Output Specification: Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. Demo Input: ['5\n', '3\n'] Demo Output: ['7/3\n', '2/1\n'] Note: In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.
```python N = int(input()) s = 0 def gcd(a, b): while(b): a, b = b, a%b return a for i in range(2, N): n = N while(n>0): s += n%i n = n//i t = gcd(s, N-2) print(str(s//t)+"/"+str((N-2)//t)) ```
3.954
748
A
Santa Claus and a Place in a Class
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
500
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "...
1,497,366,805
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
61
0
n,m,k = map(int,input().split()) if k %2 == 0: l = 'R' if k % 2 != 0: l = 'L' if k % (2 * m) != 0: p = k // (2 * m) + 1 if k % (2 * m) == 0: p = k // (2 * m) t = (k - (p - 1) * 6) // 2 + (k - (p - 1) * 6) % 2 print(str(p)+' '+str(t)+' '+l)
Title: Santa Claus and a Place in a Class Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! Input Specification: The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. Output Specification: Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. Demo Input: ['4 3 9\n', '4 3 24\n', '2 4 4\n'] Demo Output: ['2 2 L\n', '4 3 R\n', '1 2 R\n'] Note: The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
```python n,m,k = map(int,input().split()) if k %2 == 0: l = 'R' if k % 2 != 0: l = 'L' if k % (2 * m) != 0: p = k // (2 * m) + 1 if k % (2 * m) == 0: p = k // (2 * m) t = (k - (p - 1) * 6) // 2 + (k - (p - 1) * 6) % 2 print(str(p)+' '+str(t)+' '+l) ```
0
245
H
Queries for Number of Palindromes
PROGRAMMING
1,800
[ "dp", "hashing", "strings" ]
null
null
You've got a string *s*<==<=*s*1*s*2... *s*|*s*| of length |*s*|, consisting of lowercase English letters. There also are *q* queries, each query is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|). The answer to the query is the number of substrings of string *s*[*l**i*... *r**i*], which are palindromes. String *s*[*l*... *r*]<==<=*s**l**s**l*<=+<=1... *s**r* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) is a substring of string *s*<==<=*s*1*s*2... *s*|*s*|. String *t* is called a palindrome, if it reads the same from left to right and from right to left. Formally, if *t*<==<=*t*1*t*2... *t*|*t*|<==<=*t*|*t*|*t*|*t*|<=-<=1... *t*1.
The first line contains string *s* (1<=≤<=|*s*|<=≤<=5000). The second line contains a single integer *q* (1<=≤<=*q*<=≤<=106) — the number of queries. Next *q* lines contain the queries. The *i*-th of these lines contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|) — the description of the *i*-th query. It is guaranteed that the given string consists only of lowercase English letters.
Print *q* integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
[ "caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5\n" ]
[ "1\n7\n3\n4\n2\n" ]
Consider the fourth query in the first test case. String *s*[4... 6] = «aba». Its palindrome substrings are: «a», «b», «a», «aba».
0
[ { "input": "caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5", "output": "1\n7\n3\n4\n2" }, { "input": "a\n100\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 ...
1,626,783,913
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
1
5,000
34,918,400
def checkPalindrome(a): if(a == a[::-1]): return True else: return False def countPalindrome(a): count = 0 for i in range(len(a)): count-=1 for j in range(i,len(a)+1): if(checkPalindrome(a[i:j])): count = count + 1 # print(count,' ',a[i:j]) return count string = input('') n = int(input('')) queries = [] for i in range(n): que = input().split(' ') queries.append(que) for i in range(n): print(countPalindrome(string[int(queries[i][0])-1:int(queries[i][1])]))
Title: Queries for Number of Palindromes Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a string *s*<==<=*s*1*s*2... *s*|*s*| of length |*s*|, consisting of lowercase English letters. There also are *q* queries, each query is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|). The answer to the query is the number of substrings of string *s*[*l**i*... *r**i*], which are palindromes. String *s*[*l*... *r*]<==<=*s**l**s**l*<=+<=1... *s**r* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) is a substring of string *s*<==<=*s*1*s*2... *s*|*s*|. String *t* is called a palindrome, if it reads the same from left to right and from right to left. Formally, if *t*<==<=*t*1*t*2... *t*|*t*|<==<=*t*|*t*|*t*|*t*|<=-<=1... *t*1. Input Specification: The first line contains string *s* (1<=≤<=|*s*|<=≤<=5000). The second line contains a single integer *q* (1<=≤<=*q*<=≤<=106) — the number of queries. Next *q* lines contain the queries. The *i*-th of these lines contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|) — the description of the *i*-th query. It is guaranteed that the given string consists only of lowercase English letters. Output Specification: Print *q* integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces. Demo Input: ['caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5\n'] Demo Output: ['1\n7\n3\n4\n2\n'] Note: Consider the fourth query in the first test case. String *s*[4... 6] = «aba». Its palindrome substrings are: «a», «b», «a», «aba».
```python def checkPalindrome(a): if(a == a[::-1]): return True else: return False def countPalindrome(a): count = 0 for i in range(len(a)): count-=1 for j in range(i,len(a)+1): if(checkPalindrome(a[i:j])): count = count + 1 # print(count,' ',a[i:j]) return count string = input('') n = int(input('')) queries = [] for i in range(n): que = input().split(' ') queries.append(que) for i in range(n): print(countPalindrome(string[int(queries[i][0])-1:int(queries[i][1])])) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
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,579,816,269
2,147,483,647
PyPy 3
OK
TESTS
40
140
0
w=input() a="hello" s="" c=0 for i in w: if i == a[c]: c+=1 s+=i if c==5: break if s==a: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: 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. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python w=input() a="hello" s="" c=0 for i in w: if i == a[c]: c+=1 s+=i if c==5: break if s==a: print("YES") else: print("NO") ```
3.93
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,691,254,833
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
62
0
l=int(input()) x=list(map(int,str(l))) c=0 for i in x: if i==x[i+2]: c=c+1 else: c=c if c>=7: print("YES") else: print("NO")
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python l=int(input()) x=list(map(int,str(l))) c=0 for i in x: if i==x[i+2]: c=c+1 else: c=c if c>=7: print("YES") else: print("NO") ```
-1
169
A
Chores
PROGRAMMING
800
[ "sortings" ]
null
null
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=&gt;<=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*). In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces.
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
[ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ]
[ "3\n", "0\n" ]
In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
500
[ { "input": "5 2 3\n6 2 3 100 1", "output": "3" }, { "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0" }, { "input": "2 1 1\n10 2", "output": "8" }, { "input": "2 1 1\n7 7", "output": "0" }, { "input": "2 1 1\n1 1000000000", "output": "999999999" }, { "inp...
1,642,081,320
2,147,483,647
Python 3
OK
TESTS
29
46
0
n,a,b= map(int,input().split()) x = list(map(int,input().split())) x.sort() print(x[b]-x[b-1])
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=&gt;<=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*). In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores? Input Specification: The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces. Output Specification: Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. Demo Input: ['5 2 3\n6 2 3 100 1\n', '7 3 4\n1 1 9 1 1 1 1\n'] Demo Output: ['3\n', '0\n'] Note: In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
```python n,a,b= map(int,input().split()) x = list(map(int,input().split())) x.sort() print(x[b]-x[b-1]) ```
3
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: - either it only contains uppercase letters; - or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { ...
1,698,161,825
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
s = input() ok = True for i in range(1,len(s)): if ord('A') <= ord(s[i]) <= ord('Z'): ok = False if not ok: for c in s: if ord('a') <= ord(c) <= ord('z'): #小写字母 print (chr(ord(c)-(ord('a')-ord('A'))),end='') else: print (chr(ord(c)+(ord('a')-ord('A'))),end='') else: print(s)
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: - either it only contains uppercase letters; - or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input Specification: The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Specification: Print the result of the given word's processing. Demo Input: ['cAPS\n', 'Lock\n'] Demo Output: ['Caps', 'Lock\n'] Note: none
```python s = input() ok = True for i in range(1,len(s)): if ord('A') <= ord(s[i]) <= ord('Z'): ok = False if not ok: for c in s: if ord('a') <= ord(c) <= ord('z'): #小写字母 print (chr(ord(c)-(ord('a')-ord('A'))),end='') else: print (chr(ord(c)+(ord('a')-ord('A'))),end='') else: print(s) ```
0
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "o...
1,697,813,734
2,147,483,647
PyPy 3
OK
TESTS
27
92
0
s = input() print(len(set(s.lstrip("{").rstrip("}").split(", "))) if s != "{}" else 0)
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. Input Specification: The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. Output Specification: Print a single number — the number of distinct letters in Anton's set. Demo Input: ['{a, b, c}\n', '{b, a, b, a}\n', '{}\n'] Demo Output: ['3\n', '2\n', '0\n'] Note: none
```python s = input() print(len(set(s.lstrip("{").rstrip("}").split(", "))) if s != "{}" else 0) ```
3
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Print a single integer — the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { ...
1,675,894,587
2,147,483,647
Python 3
OK
TESTS
49
92
0
a = [] a = [int(item) for item in input().split()] # fill the list with numbers s = input() # take the string x = len(s) result = 0 for i in range(x): if s[i]=='1': result+=a[0] elif s[i]== '2' : result += a[1] elif s[i] == '3' : result += a[2] elif s[i] == '4' : result += a[3] print (result) # problem_link : https://codeforces.com/contest/431/problem/A
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? Input Specification: The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. Output Specification: Print a single integer — the total number of calories that Jury wastes. Demo Input: ['1 2 3 4\n123214\n', '1 5 3 2\n11221\n'] Demo Output: ['13\n', '13\n'] Note: none
```python a = [] a = [int(item) for item in input().split()] # fill the list with numbers s = input() # take the string x = len(s) result = 0 for i in range(x): if s[i]=='1': result+=a[0] elif s[i]== '2' : result += a[1] elif s[i] == '3' : result += a[2] elif s[i] == '4' : result += a[3] print (result) # problem_link : https://codeforces.com/contest/431/problem/A ```
3
215
A
Bicycle Chain
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=&lt;<=*b*1<=&lt;<=*b*2<=&lt;<=...<=&lt;<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value . Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears. In the problem, fraction denotes division in real numbers, that is, no rounding is performed.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing. It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces.
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
[ "2\n4 5\n3\n12 13 15\n", "4\n1 2 3 4\n5\n10 11 12 13 14\n" ]
[ "2\n", "1\n" ]
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
500
[ { "input": "2\n4 5\n3\n12 13 15", "output": "2" }, { "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 2\n1\n1", "output": "1" }, { "input": "1\n1\n2\n1 2", "output": "1" }, { "input":...
1,625,775,411
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <string> #include <math.h> #define ll long long #define pl pair<ll, ll> #define itp pair<vector<int>::iterator, vector<int>::iterator> #define mp make_pair #define f first #define s second const ll MOD = (ll)(pow(10, 9) + 7); using namespace std; ll dist(ll a, ll b, ll n) { if (a == b) { return 0; } if (b < a) { return n - a + b; } else { return b - a; } } int main() { ll n, m; cin >> n; vector <ll> A(n); for (int i = 0; i < n; i++) { cin >> A[i]; } cin >> m; vector<ll> B(m); for (int i = 0; i < m; i++) { cin >> B[i]; } ll k = 0; ll x = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (B[i] % A[j] == 0) x = max(B[i] / A[j], x); } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (B[i] % A[j] == 0) if (B[i] / A[j] == x) k++; } } cout << k; }
Title: Bicycle Chain Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=&lt;<=*b*1<=&lt;<=*b*2<=&lt;<=...<=&lt;<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value . Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears. In the problem, fraction denotes division in real numbers, that is, no rounding is performed. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing. It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces. Output Specification: Print the number of "integer" gears with the maximum ratio among all "integer" gears. Demo Input: ['2\n4 5\n3\n12 13 15\n', '4\n1 2 3 4\n5\n10 11 12 13 14\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
```python #include <iostream> #include <string> #include <algorithm> #include <vector> #include <string> #include <math.h> #define ll long long #define pl pair<ll, ll> #define itp pair<vector<int>::iterator, vector<int>::iterator> #define mp make_pair #define f first #define s second const ll MOD = (ll)(pow(10, 9) + 7); using namespace std; ll dist(ll a, ll b, ll n) { if (a == b) { return 0; } if (b < a) { return n - a + b; } else { return b - a; } } int main() { ll n, m; cin >> n; vector <ll> A(n); for (int i = 0; i < n; i++) { cin >> A[i]; } cin >> m; vector<ll> B(m); for (int i = 0; i < m; i++) { cin >> B[i]; } ll k = 0; ll x = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (B[i] % A[j] == 0) x = max(B[i] / A[j], x); } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (B[i] % A[j] == 0) if (B[i] / A[j] == x) k++; } } cout << k; } ```
-1
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 as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
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,557,059,899
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
0
n=int(input()) for i in range(2,n+1): print(i,' ',end='') print(1)
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 permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. Input Specification: A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. Output Specification: 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. Demo Input: ['1\n', '2\n'] Demo Output: ['1 ', '2 1 '] Note: none
```python n=int(input()) for i in range(2,n+1): print(i,' ',end='') print(1) ```
0
712
A
Memory and Crow
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure: - The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3.... Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row. The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
[ "5\n6 -4 8 -2 3\n", "5\n3 -2 -1 5 6\n" ]
[ "2 4 6 1 3 \n", "1 -3 4 11 6 \n" ]
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3. In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
500
[ { "input": "5\n6 -4 8 -2 3", "output": "2 4 6 1 3 " }, { "input": "5\n3 -2 -1 5 6", "output": "1 -3 4 11 6 " }, { "input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10", "output": "11 530 469 -86 -86 -127 -87 -11 22 10 " }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0 0...
1,473,527,311
1,411
Python 3
OK
TESTS
49
405
8,396,800
n=int(input()) v=[int(i) for i in input().split()] b=[v[i]+v[i+1] for i in range(n-1)] b.append(v[-1]) for i in range(n): print(b[i],end=" ")
Title: Memory and Crow Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure: - The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3.... Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it? Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row. The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. Output Specification: Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. Demo Input: ['5\n6 -4 8 -2 3\n', '5\n3 -2 -1 5 6\n'] Demo Output: ['2 4 6 1 3 \n', '1 -3 4 11 6 \n'] Note: In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3. In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
```python n=int(input()) v=[int(i) for i in input().split()] b=[v[i]+v[i+1] for i in range(n-1)] b.append(v[-1]) for i in range(n): print(b[i],end=" ") ```
3
990
B
Micro-World
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.
The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have.
Print the only integer — minimal possible number of bacteria can remain.
[ "7 1\n101 53 42 102 101 55 54\n", "6 5\n20 15 10 15 20 25\n", "7 1000000\n1 1 1 1 1 1 1\n" ]
[ "3\n", "1\n", "7\n" ]
The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. In the third example no bacteria can swallow any other bacteria.
0
[ { "input": "7 1\n101 53 42 102 101 55 54", "output": "3" }, { "input": "6 5\n20 15 10 15 20 25", "output": "1" }, { "input": "7 1000000\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 4\n8", "output": "1" }, { "inp...
1,534,143,527
2,147,483,647
Python 3
OK
TESTS
36
560
14,336,000
n ,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() out = 0 i = 0 for j in range(n): while(i+1 < n and a[j] == a[i]): i += 1 if a[j] < a[i] and a[j] + k >= a[i]: out += 1 print(n-out)
Title: Micro-World Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope. Input Specification: The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. Output Specification: Print the only integer — minimal possible number of bacteria can remain. Demo Input: ['7 1\n101 53 42 102 101 55 54\n', '6 5\n20 15 10 15 20 25\n', '7 1000000\n1 1 1 1 1 1 1\n'] Demo Output: ['3\n', '1\n', '7\n'] Note: The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. In the third example no bacteria can swallow any other bacteria.
```python n ,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() out = 0 i = 0 for j in range(n): while(i+1 < n and a[j] == a[i]): i += 1 if a[j] < a[i] and a[j] + k >= a[i]: out += 1 print(n-out) ```
3
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "inpu...
1,689,337,070
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
61
0
def find_person(n): queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] i = 0 while n > len(queue): n -= len(queue) queue += [queue[i], queue[i]] i += 1 return queue[(n - 1) // (len(queue) // 5)] n = int(input()) result = find_person(n) print(result)
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input Specification: The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Specification: Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Demo Input: ['1\n', '6\n', '1802\n'] Demo Output: ['Sheldon\n', 'Sheldon\n', 'Penny\n'] Note: none
```python def find_person(n): queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] i = 0 while n > len(queue): n -= len(queue) queue += [queue[i], queue[i]] i += 1 return queue[(n - 1) // (len(queue) // 5)] n = int(input()) result = find_person(n) print(result) ```
0
808
A
Lucky Year
PROGRAMMING
900
[ "implementation" ]
null
null
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland.
Output amount of years from the current year to the next lucky one.
[ "4\n", "201\n", "4000\n" ]
[ "1\n", "99\n", "1000\n" ]
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
0
[ { "input": "4", "output": "1" }, { "input": "201", "output": "99" }, { "input": "4000", "output": "1000" }, { "input": "9", "output": "1" }, { "input": "10", "output": "10" }, { "input": "1", "output": "1" }, { "input": "100000000", "ou...
1,587,786,889
2,147,483,647
PyPy 3
OK
TESTS
271
155
0
n=int(input()) s=str(n) r=int(s[0])+1 ss=str(r)+'0'*(len(s)-1) ss=int(ss) print(ss-n)
Title: Lucky Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year. Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. Output Specification: Output amount of years from the current year to the next lucky one. Demo Input: ['4\n', '201\n', '4000\n'] Demo Output: ['1\n', '99\n', '1000\n'] Note: In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
```python n=int(input()) s=str(n) r=int(s[0])+1 ss=str(r)+'0'*(len(s)-1) ss=int(ss) print(ss-n) ```
3
761
A
Dasha and Stairs
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
[ "2 3\n", "3 1\n" ]
[ "YES\n", "NO\n" ]
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
500
[ { "input": "2 3", "output": "YES" }, { "input": "3 1", "output": "NO" }, { "input": "5 4", "output": "YES" }, { "input": "9 9", "output": "YES" }, { "input": "85 95", "output": "NO" }, { "input": "0 1", "output": "YES" }, { "input": "89 25"...
1,582,462,490
2,147,483,647
Python 3
OK
TESTS
21
109
0
n,m=map(int,input().split()) z=abs(n-m) if((z==0 and n!=0) or z==1): print("YES") else: print("NO")
Title: Dasha and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. Input Specification: In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. Output Specification: In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. Demo Input: ['2 3\n', '3 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
```python n,m=map(int,input().split()) z=abs(n-m) if((z==0 and n!=0) or z==1): print("YES") else: print("NO") ```
3
612
A
The Text Splitting
PROGRAMMING
1,300
[ "brute force", "implementation", "strings" ]
null
null
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test).
The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100). The second line contains the string *s* consists of lowercase and uppercase latin letters and digits.
If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1". Otherwise in the first line print integer *k* — the number of strings in partition of *s*. Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right. If there are several solutions print any of them.
[ "5 2 3\nHello\n", "10 9 5\nCodeforces\n", "6 4 5\nPrivet\n", "8 1 1\nabacabac\n" ]
[ "2\nHe\nllo\n", "2\nCodef\norces\n", "-1\n", "8\na\nb\na\nc\na\nb\na\nc\n" ]
none
0
[ { "input": "5 2 3\nHello", "output": "2\nHe\nllo" }, { "input": "10 9 5\nCodeforces", "output": "2\nCodef\norces" }, { "input": "6 4 5\nPrivet", "output": "-1" }, { "input": "8 1 1\nabacabac", "output": "8\na\nb\na\nc\na\nb\na\nc" }, { "input": "1 1 1\n1", "ou...
1,613,387,060
2,147,483,647
PyPy 3
OK
TESTS
72
93
1,331,200
n, p, q = [int(j) for j in input().split()] s = str(input()) x, y = -1, -1 found = False for j in range(101): for k in range(101): res = j * p + k * q if res == n: x, y = j, k found = True break elif res > n: break if found == True or j * p > n: break if found == False: print(-1) else: p1, p2 = 0, p List = [] for j in range(x): List.append(s[p1 : p2]) p1 += p p2 += p p2 = p1 + q for j in range(y): List.append(s[p1 : p2]) p1 += q p2 += q print(len(List)) for j in range(len(List)): print(List[j])
Title: The Text Splitting Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test). Input Specification: The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100). The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. Output Specification: If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1". Otherwise in the first line print integer *k* — the number of strings in partition of *s*. Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right. If there are several solutions print any of them. Demo Input: ['5 2 3\nHello\n', '10 9 5\nCodeforces\n', '6 4 5\nPrivet\n', '8 1 1\nabacabac\n'] Demo Output: ['2\nHe\nllo\n', '2\nCodef\norces\n', '-1\n', '8\na\nb\na\nc\na\nb\na\nc\n'] Note: none
```python n, p, q = [int(j) for j in input().split()] s = str(input()) x, y = -1, -1 found = False for j in range(101): for k in range(101): res = j * p + k * q if res == n: x, y = j, k found = True break elif res > n: break if found == True or j * p > n: break if found == False: print(-1) else: p1, p2 = 0, p List = [] for j in range(x): List.append(s[p1 : p2]) p1 += p p2 += p p2 = p1 + q for j in range(y): List.append(s[p1 : p2]) p1 += q p2 += q print(len(List)) for j in range(len(List)): print(List[j]) ```
3
20
A
BerOS file system
PROGRAMMING
1,700
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form.
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
500
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "...
1,674,109,233
2,147,483,647
PyPy 3
OK
TESTS
19
186
0
print("/"+"/".join(filter(None, input().split("/"))))
Title: BerOS file system Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input Specification: The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output Specification: The path in normalized form. Demo Input: ['//usr///local//nginx/sbin\n'] Demo Output: ['/usr/local/nginx/sbin\n'] Note: none
```python print("/"+"/".join(filter(None, input().split("/")))) ```
3.9535
446
A
DZY Loves Sequences
PROGRAMMING
1,600
[ "dp", "implementation", "two pointers" ]
null
null
DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
In a single line print the answer to the problem — the maximum length of the required subsegment.
[ "6\n7 2 3 1 5 6\n" ]
[ "5\n" ]
You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
500
[ { "input": "6\n7 2 3 1 5 6", "output": "5" }, { "input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422", "output": "9" }, { "input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 1...
1,508,728,782
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
4,608,000
input() lst = list(map(int, input().split())) pointer1 = 0 pointer2 = 1 numinc = 0 numincidx = 0 mx = 0 while pointer2 < len(lst): #print('{} {} {} {}'.format(pointer1, pointer2,numincidx,numinc)) if pointer2 - pointer1 > mx: mx = pointer2 - pointer1 if lst[pointer2] < lst[pointer2 -1]: if numinc == 1: pointer1 = numincidx numincidx = pointer2 + 1 #print("debug") else: numincidx = pointer2 numinc += 1 pointer2 += 1 print(mx)
Title: DZY Loves Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: In a single line print the answer to the problem — the maximum length of the required subsegment. Demo Input: ['6\n7 2 3 1 5 6\n'] Demo Output: ['5\n'] Note: You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
```python input() lst = list(map(int, input().split())) pointer1 = 0 pointer2 = 1 numinc = 0 numincidx = 0 mx = 0 while pointer2 < len(lst): #print('{} {} {} {}'.format(pointer1, pointer2,numincidx,numinc)) if pointer2 - pointer1 > mx: mx = pointer2 - pointer1 if lst[pointer2] < lst[pointer2 -1]: if numinc == 1: pointer1 = numincidx numincidx = pointer2 + 1 #print("debug") else: numincidx = pointer2 numinc += 1 pointer2 += 1 print(mx) ```
0
452
A
Eevee
PROGRAMMING
1,000
[ "brute force", "implementation", "strings" ]
null
null
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon. You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.
First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).
Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).
[ "7\nj......\n", "7\n...feon\n", "7\n.l.r.o.\n" ]
[ "jolteon\n", "leafeon\n", "flareon\n" ]
Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
500
[ { "input": "7\n...feon", "output": "leafeon" }, { "input": "7\n.l.r.o.", "output": "flareon" }, { "input": "6\n.s..o.", "output": "espeon" }, { "input": "7\nglaceon", "output": "glaceon" }, { "input": "8\n.a.o.e.n", "output": "vaporeon" }, { "input": "...
1,407,344,061
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
61
0
N = int(input()) S = input() A = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] for a in A: if not len(a) == N: A.remove(a) for i in range(N): if S[i] == ".": continue else: for a in A: if not a[i] == S[i]: A.remove(a) print (A[0])
Title: Eevee Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon. You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it. Input Specification: First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). Output Specification: Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). Demo Input: ['7\nj......\n', '7\n...feon\n', '7\n.l.r.o.\n'] Demo Output: ['jolteon\n', 'leafeon\n', 'flareon\n'] Note: Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
```python N = int(input()) S = input() A = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] for a in A: if not len(a) == N: A.remove(a) for i in range(N): if S[i] == ".": continue else: for a in A: if not a[i] == S[i]: A.remove(a) print (A[0]) ```
0
570
D
Tree Requests
PROGRAMMING
2,200
[ "binary search", "bitmasks", "constructive algorithms", "dfs and similar", "graphs", "trees" ]
null
null
Roman planted a tree consisting of *n* vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the *n*<=-<=1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex *i* is vertex *p**i*, the parent index is always less than the index of the vertex (i.e., *p**i*<=&lt;<=*i*). The depth of the vertex is the number of nodes on the path from the root to *v* along the edges. In particular, the depth of the root is equal to 1. We say that vertex *u* is in the subtree of vertex *v*, if we can get from *u* to *v*, moving from the vertex to the parent. In particular, vertex *v* is in its subtree. Roma gives you *m* queries, the *i*-th of which consists of two numbers *v**i*, *h**i*. Let's consider the vertices in the subtree *v**i* located at depth *h**i*. Determine whether you can use the letters written at these vertices to make a string that is a palindrome. The letters that are written in the vertexes, can be rearranged in any order to make a palindrome, but all letters should be used.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=500<=000) — the number of nodes in the tree and queries, respectively. The following line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* — the parents of vertices from the second to the *n*-th (1<=≤<=*p**i*<=&lt;<=*i*). The next line contains *n* lowercase English letters, the *i*-th of these letters is written on vertex *i*. Next *m* lines describe the queries, the *i*-th line contains two numbers *v**i*, *h**i* (1<=≤<=*v**i*,<=*h**i*<=≤<=*n*) — the vertex and the depth that appear in the *i*-th query.
Print *m* lines. In the *i*-th line print "Yes" (without the quotes), if in the *i*-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes).
[ "6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2\n" ]
[ "Yes\nNo\nYes\nYes\nYes\n" ]
String *s* is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome. Clarification for the sample test. In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z". In the second query vertices 5 and 6 satisfy condititions, they contain letters "с" and "d" respectively. It is impossible to form a palindrome of them. In the third query there exist no vertices at depth 1 and in subtree of 4. We may form an empty palindrome. In the fourth query there exist no vertices in subtree of 6 at depth 1. We may form an empty palindrome. In the fifth query there vertices 2, 3 and 4 satisfying all conditions above, they contain letters "a", "c" and "c". We may form a palindrome "cac".
2,000
[ { "input": "6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2", "output": "Yes\nNo\nYes\nYes\nYes" }, { "input": "5 6\n1 1 2 3\ncbcab\n3 1\n5 2\n1 3\n4 1\n4 2\n1 1", "output": "Yes\nYes\nNo\nYes\nYes\nYes" }, { "input": "5 6\n1 2 2 1\nbaabb\n1 1\n1 2\n5 1\n4 1\n4 2\n3 2", "output": "Ye...
1,594,441,674
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
217,907,200
from bisect import bisect_left def dfs(i, h): global parent, g, s, time, IN, OUT, H IN[i] = time H[h].append((time, H[h][-1][1]^(1<<(ord(s[i])-ord('a')) ))) time+=1 for j in g[i]: dfs(j, h+1) OUT[i] = time time+=1 IN = {} OUT= {} time = 1 n ,m = map(int, input().split()) parent=list(map(int, input().split())) parent.insert(0, 0) parent.insert(0, 0) H = [[(0,0)] for i in range(3*n)] s = '$' + input() g = {v:[] for v in range(n+1)} for i,j in enumerate(parent): g[j].append(i) dfs(1,1) for _ in range(m): root, height = map(int, input().split()) l = bisect_left(H[height], (IN[root],-1), 0, len(H[height]))-1 r = bisect_left(H[height], (OUT[root],-1), 0, len(H[height]))-1 t = H[height][l][1] ^ H[height][r][1] b = t - (t&-t) c = t ^ (t&-t) if(b): print('No') else: print('Yes')
Title: Tree Requests Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roman planted a tree consisting of *n* vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the *n*<=-<=1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex *i* is vertex *p**i*, the parent index is always less than the index of the vertex (i.e., *p**i*<=&lt;<=*i*). The depth of the vertex is the number of nodes on the path from the root to *v* along the edges. In particular, the depth of the root is equal to 1. We say that vertex *u* is in the subtree of vertex *v*, if we can get from *u* to *v*, moving from the vertex to the parent. In particular, vertex *v* is in its subtree. Roma gives you *m* queries, the *i*-th of which consists of two numbers *v**i*, *h**i*. Let's consider the vertices in the subtree *v**i* located at depth *h**i*. Determine whether you can use the letters written at these vertices to make a string that is a palindrome. The letters that are written in the vertexes, can be rearranged in any order to make a palindrome, but all letters should be used. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=500<=000) — the number of nodes in the tree and queries, respectively. The following line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* — the parents of vertices from the second to the *n*-th (1<=≤<=*p**i*<=&lt;<=*i*). The next line contains *n* lowercase English letters, the *i*-th of these letters is written on vertex *i*. Next *m* lines describe the queries, the *i*-th line contains two numbers *v**i*, *h**i* (1<=≤<=*v**i*,<=*h**i*<=≤<=*n*) — the vertex and the depth that appear in the *i*-th query. Output Specification: Print *m* lines. In the *i*-th line print "Yes" (without the quotes), if in the *i*-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes). Demo Input: ['6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2\n'] Demo Output: ['Yes\nNo\nYes\nYes\nYes\n'] Note: String *s* is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome. Clarification for the sample test. In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z". In the second query vertices 5 and 6 satisfy condititions, they contain letters "с" and "d" respectively. It is impossible to form a palindrome of them. In the third query there exist no vertices at depth 1 and in subtree of 4. We may form an empty palindrome. In the fourth query there exist no vertices in subtree of 6 at depth 1. We may form an empty palindrome. In the fifth query there vertices 2, 3 and 4 satisfying all conditions above, they contain letters "a", "c" and "c". We may form a palindrome "cac".
```python from bisect import bisect_left def dfs(i, h): global parent, g, s, time, IN, OUT, H IN[i] = time H[h].append((time, H[h][-1][1]^(1<<(ord(s[i])-ord('a')) ))) time+=1 for j in g[i]: dfs(j, h+1) OUT[i] = time time+=1 IN = {} OUT= {} time = 1 n ,m = map(int, input().split()) parent=list(map(int, input().split())) parent.insert(0, 0) parent.insert(0, 0) H = [[(0,0)] for i in range(3*n)] s = '$' + input() g = {v:[] for v in range(n+1)} for i,j in enumerate(parent): g[j].append(i) dfs(1,1) for _ in range(m): root, height = map(int, input().split()) l = bisect_left(H[height], (IN[root],-1), 0, len(H[height]))-1 r = bisect_left(H[height], (OUT[root],-1), 0, len(H[height]))-1 t = H[height][l][1] ^ H[height][r][1] b = t - (t&-t) c = t ^ (t&-t) if(b): print('No') else: print('Yes') ```
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 that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
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,491,922,389
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
4,608,000
mayus=["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"] minus=["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"] s=input() ma=0 mi=0 for c in s: if c in mayus: ma+=1 elif c in minus: mi+=1 if ma>mi: s.upper() elif mi>=ma: s.lower() print(s)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: 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. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python mayus=["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"] minus=["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"] s=input() ma=0 mi=0 for c in s: if c in mayus: ma+=1 elif c in minus: mi+=1 if ma>mi: s.upper() elif mi>=ma: s.lower() print(s) ```
0
507
A
Amr and Music
PROGRAMMING
1,000
[ "greedy", "implementation", "sortings" ]
null
null
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument.
In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
[ "4 10\n4 3 1 2\n", "5 6\n4 3 1 1 2\n", "1 3\n4\n" ]
[ "4\n1 2 3 4", "3\n1 3 4", "0\n" ]
In the first test Amr can learn all 4 instruments. In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}. In the third test Amr doesn't have enough time to learn the only presented instrument.
500
[ { "input": "4 10\n4 3 1 2", "output": "4\n1 2 3 4" }, { "input": "5 6\n4 3 1 1 2", "output": "3\n3 4 5" }, { "input": "1 3\n4", "output": "0" }, { "input": "2 100\n100 100", "output": "1\n1" }, { "input": "3 150\n50 50 50", "output": "3\n1 2 3" }, { "i...
1,640,961,725
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
a,b=map(int,input().split()) l=list(map(int,input().split())) l.sort() x=[] count=0 for i in l: if(sum(x)+i<b): x.append(i) print(len(x)) print(*x)
Title: Amr and Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for your help to distribute his free days between instruments so that he can achieve his goal. Input Specification: The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. Output Specification: In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying. Demo Input: ['4 10\n4 3 1 2\n', '5 6\n4 3 1 1 2\n', '1 3\n4\n'] Demo Output: ['4\n1 2 3 4', '3\n1 3 4', '0\n'] Note: In the first test Amr can learn all 4 instruments. In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}. In the third test Amr doesn't have enough time to learn the only presented instrument.
```python a,b=map(int,input().split()) l=list(map(int,input().split())) l.sort() x=[] count=0 for i in l: if(sum(x)+i<b): x.append(i) print(len(x)) print(*x) ```
0
979
C
Kuro and Walking Route
PROGRAMMING
1,600
[ "dfs and similar", "trees" ]
null
null
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$). Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him. Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.
The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.
A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route.
[ "3 1 3\n1 2\n2 3\n", "3 1 3\n1 2\n1 3\n" ]
[ "5", "4" ]
On the first example, Kuro can choose these pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$. Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order). On the second example, Kuro can choose the following pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$.
1,250
[ { "input": "3 1 3\n1 2\n2 3", "output": "5" }, { "input": "3 1 3\n1 2\n1 3", "output": "4" }, { "input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 ...
1,527,022,426
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
1,024,000
from collections import deque class graph: def __init__(self, N, edges, x, y): self.nedges=len(edges) self.N=N self.adj=[[] for i in range(1,N+1)] for i in range(0,self.nedges): self.adj[edges[i][0]-1].append(edges[i][1]) self.adj[edges[i][1]-1].append(edges[i][0]) K=0 Rememb=0 Nen=0 Flow=False for i in self.adj[y-1]: Flow=False Len=0 Flow, Len = self.bfs(i,y,x) if Flow: K=Len Rememb=i Flow, Nen = self.bfs(y,Rememb,-1) print (N*(N-1)-Nen*K) def bfs(self, start, parent, x): discovered=[False for i in range(0, self.N)] processed=[False for i in range(0, self.N)] q=deque() q.append(start) discovered[start-1]=True discovered[parent-1]=True g=-1 Len=0 flow=False while(len(q)!=0): parent = g Len=Len+1 g = q.pop() if x==g: flow=True ch, mn = self.bfs(x, parent, -1) return flow, mn processed[g-1]=True for i in self.adj[g-1]: if(discovered[i-1]==False): discovered[i-1]=True q.append(i) return flow, Len s1=input() k=[int(i) for i in s1.split(' ')] N,x,y = k[0],k[1],k[2] s = [input() for i in range(1,N)] edges = [[int(j) for j in s[i-1].split(' ')] for i in range(1,N)] asd=graph(N, edges, x, y)
Title: Kuro and Walking Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$). Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him. Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem. Input Specification: The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree. Output Specification: A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route. Demo Input: ['3 1 3\n1 2\n2 3\n', '3 1 3\n1 2\n1 3\n'] Demo Output: ['5', '4'] Note: On the first example, Kuro can choose these pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$. Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order). On the second example, Kuro can choose the following pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$.
```python from collections import deque class graph: def __init__(self, N, edges, x, y): self.nedges=len(edges) self.N=N self.adj=[[] for i in range(1,N+1)] for i in range(0,self.nedges): self.adj[edges[i][0]-1].append(edges[i][1]) self.adj[edges[i][1]-1].append(edges[i][0]) K=0 Rememb=0 Nen=0 Flow=False for i in self.adj[y-1]: Flow=False Len=0 Flow, Len = self.bfs(i,y,x) if Flow: K=Len Rememb=i Flow, Nen = self.bfs(y,Rememb,-1) print (N*(N-1)-Nen*K) def bfs(self, start, parent, x): discovered=[False for i in range(0, self.N)] processed=[False for i in range(0, self.N)] q=deque() q.append(start) discovered[start-1]=True discovered[parent-1]=True g=-1 Len=0 flow=False while(len(q)!=0): parent = g Len=Len+1 g = q.pop() if x==g: flow=True ch, mn = self.bfs(x, parent, -1) return flow, mn processed[g-1]=True for i in self.adj[g-1]: if(discovered[i-1]==False): discovered[i-1]=True q.append(i) return flow, Len s1=input() k=[int(i) for i in s1.split(' ')] N,x,y = k[0],k[1],k[2] s = [input() for i in range(1,N)] edges = [[int(j) for j in s[i-1].split(' ')] for i in range(1,N)] asd=graph(N, edges, x, y) ```
0
630
A
Again Twenty Five!
PROGRAMMING
800
[ "number theory" ]
null
null
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions." Could you pass the interview in the machine vision company in IT City?
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output the last two digits of 5*n* without spaces between them.
[ "2\n" ]
[ "25" ]
none
0
[ { "input": "2", "output": "25" }, { "input": "7", "output": "25" }, { "input": "1000000000000000000", "output": "25" }, { "input": "2000000000000000000", "output": "25" }, { "input": "987654321012345678", "output": "25" } ]
1,693,121,790
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
46
0
n=int(input()) print((5**(n%100))%100)
Title: Again Twenty Five! Time Limit: None seconds Memory Limit: None megabytes Problem Description: The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions." Could you pass the interview in the machine vision company in IT City? Input Specification: The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. Output Specification: Output the last two digits of 5*n* without spaces between them. Demo Input: ['2\n'] Demo Output: ['25'] Note: none
```python n=int(input()) print((5**(n%100))%100) ```
0
199
A
Hexadecimal's theorem
PROGRAMMING
900
[ "brute force", "constructive algorithms", "implementation", "number theory" ]
null
null
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible.
The input contains of a single integer *n* (0<=≤<=*n*<=&lt;<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them.
[ "3\n", "13\n" ]
[ "1 1 1\n", "2 3 8\n" ]
none
500
[ { "input": "3", "output": "1 1 1" }, { "input": "13", "output": "2 3 8" }, { "input": "0", "output": "0 0 0" }, { "input": "1", "output": "1 0 0" }, { "input": "2", "output": "1 1 0" }, { "input": "1597", "output": "233 377 987" }, { "input...
1,623,375,612
2,147,483,647
Python 3
OK
TESTS
54
154
0
n = int(input()) if n == 0: print(0, 0, 0) elif n == 1: print(0, 0, 1) elif n == 2: print(0, 1, 1) else: arr = [0, 1] i = 1 while True: m = arr[i]+arr[i-1] if m <= n: arr.append(m) i += 1 else: break print(arr[-2], arr[-4], arr[-5])
Title: Hexadecimal's theorem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. Input Specification: The input contains of a single integer *n* (0<=≤<=*n*<=&lt;<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. Output Specification: Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Demo Input: ['3\n', '13\n'] Demo Output: ['1 1 1\n', '2 3 8\n'] Note: none
```python n = int(input()) if n == 0: print(0, 0, 0) elif n == 1: print(0, 0, 1) elif n == 2: print(0, 1, 1) else: arr = [0, 1] i = 1 while True: m = arr[i]+arr[i-1] if m <= n: arr.append(m) i += 1 else: break print(arr[-2], arr[-4], arr[-5]) ```
3
776
A
A Serial Killer
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days. Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
[ "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n", "icm codeforces\n1\ncodeforces technex\n" ]
[ "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n", "icm codeforces\nicm technex\n" ]
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
500
[ { "input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler" }, { "input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex" }, { "input": "a b\n3\na c\n...
1,647,694,132
2,147,483,647
Python 3
OK
TESTS
57
46
0
x, y = input().split() print(x, y) for _ in range(int(input())): a, b = input().split() if x == a: x = b elif y == a: y = b print(x, y)
Title: A Serial Killer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input Specification: First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days. Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Specification: Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Demo Input: ['ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n', 'icm codeforces\n1\ncodeforces technex\n'] Demo Output: ['ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n', 'icm codeforces\nicm technex\n'] Note: In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
```python x, y = input().split() print(x, y) for _ in range(int(input())): a, b = input().split() if x == a: x = b elif y == a: y = b print(x, y) ```
3
429
A
Xor-tree
PROGRAMMING
1,300
[ "dfs and similar", "trees" ]
null
null
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1).
In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*.
[ "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n" ]
[ "2\n4\n7\n" ]
none
500
[ { "input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1", "output": "2\n4\n7" }, { "input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0", "output"...
1,570,178,757
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
20,582,400
def dfs(node,parent): global a,init,goal,l,t if init[node-1]!=goal[node-1]: update(node,parent,0) l=l+1 t.append(node) for i in range(len(a[node])): if a[node][i]!=parent: dfs(a[node][i],node) def update(node,parent,p): global a,init,goal if p%2==0: init[node-1]=(init[node-1]^1) for i in range(len(a[node])): if a[node][i]!=parent: update(a[node][i],node,p+1) n = int(input()) import sys sys.setrecursionlimit(10**6) a = [[] for _ in range(n+1)] visited = [False for _ in range(n+1)] for _ in range(n-1): x,y = list(map(int,input().split())) a[x].append(y) a[y].append(x) l = 0 init = list(map(int,input().split())) goal = list(map(int,input().split())) t = [] dfs(1,0) print(l) for i in t: print(i)
Title: Xor-tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*. The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1). Output Specification: In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. Demo Input: ['10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n'] Demo Output: ['2\n4\n7\n'] Note: none
```python def dfs(node,parent): global a,init,goal,l,t if init[node-1]!=goal[node-1]: update(node,parent,0) l=l+1 t.append(node) for i in range(len(a[node])): if a[node][i]!=parent: dfs(a[node][i],node) def update(node,parent,p): global a,init,goal if p%2==0: init[node-1]=(init[node-1]^1) for i in range(len(a[node])): if a[node][i]!=parent: update(a[node][i],node,p+1) n = int(input()) import sys sys.setrecursionlimit(10**6) a = [[] for _ in range(n+1)] visited = [False for _ in range(n+1)] for _ in range(n-1): x,y = list(map(int,input().split())) a[x].append(y) a[y].append(x) l = 0 init = list(map(int,input().split())) goal = list(map(int,input().split())) t = [] dfs(1,0) print(l) for i in t: print(i) ```
0
242
B
Big Segment
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments coincide.
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.
[ "3\n1 1\n2 2\n3 3\n", "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n" ]
[ "-1\n", "3\n" ]
none
1,000
[ { "input": "3\n1 1\n2 2\n3 3", "output": "-1" }, { "input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "output": "3" }, { "input": "4\n1 5\n2 2\n2 4\n2 5", "output": "1" }, { "input": "5\n3 3\n1 3\n2 2\n2 3\n1 2", "output": "2" }, { "input": "7\n7 7\n8 8\n3 7\n1 6\n1 ...
1,662,149,152
2,147,483,647
Python 3
OK
TESTS
45
530
135,270,400
from collections import defaultdict, deque from functools import lru_cache from heapq import heappush, heappop from typing import Counter import math hpop = heappop hpush = heappush """ num = int(input()) arr = list(map(int, input().split())) a,b = map(int, input().split()) graph = defaultdict(list) for i in range(#) graph[a].append(b) graph[b].append(a) MOD = 10**9 + 7 """ def solution(): n = int(input()) mn = float("inf") mx = float("-inf") res = [-1,mn,mx] for i in range(n): a,b = map(int, input().split()) mn = min(mn, a) mx = max(mx, b) if a == mn and b == mx: res = [i,a,b] if mn == float("inf") or mx == float("-inf"): print(-1) i,a,b = res if mn == a and mx == b: print(i+1) else: print(-1) def main(): t = 1 #t = int(input()) # n + 1 diffrences for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1 << 30) threading.stack_size(1 << 27) thread = threading.Thread(target=main) thread.start(); thread.join() #main()
Title: Big Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments coincide. Output Specification: Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input. Demo Input: ['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n'] Demo Output: ['-1\n', '3\n'] Note: none
```python from collections import defaultdict, deque from functools import lru_cache from heapq import heappush, heappop from typing import Counter import math hpop = heappop hpush = heappush """ num = int(input()) arr = list(map(int, input().split())) a,b = map(int, input().split()) graph = defaultdict(list) for i in range(#) graph[a].append(b) graph[b].append(a) MOD = 10**9 + 7 """ def solution(): n = int(input()) mn = float("inf") mx = float("-inf") res = [-1,mn,mx] for i in range(n): a,b = map(int, input().split()) mn = min(mn, a) mx = max(mx, b) if a == mn and b == mx: res = [i,a,b] if mn == float("inf") or mx == float("-inf"): print(-1) i,a,b = res if mn == a and mx == b: print(i+1) else: print(-1) def main(): t = 1 #t = int(input()) # n + 1 diffrences for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1 << 30) threading.stack_size(1 << 27) thread = threading.Thread(target=main) thread.start(); thread.join() #main() ```
3
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, ...
1,651,397,994
2,147,483,647
Python 3
OK
TESTS
46
92
0
n=int(input()) b=input() a=[] da=True for i in b: a.append(int(i)) for i in a: if i!=7 and i!=4: da=False break if sum(a[0:n//2])==sum(a[n//2:]) and da: print('YES') else: print('NO')
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. Input Specification: The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. Output Specification: On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['2\n47\n', '4\n4738\n', '4\n4774\n'] Demo Output: ['NO\n', 'NO\n', 'YES\n'] Note: In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
```python n=int(input()) b=input() a=[] da=True for i in b: a.append(int(i)) for i in a: if i!=7 and i!=4: da=False break if sum(a[0:n//2])==sum(a[n//2:]) and da: print('YES') else: print('NO') ```
3
845
A
Chess Tourney
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
Berland annual chess tournament is coming! Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins. Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100). The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000).
If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
[ "2\n1 3 2 4\n", "1\n3 3\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "2\n1 3 2 4", "output": "YES" }, { "input": "1\n3 3", "output": "NO" }, { "input": "5\n1 1 1 1 2 2 3 3 3 3", "output": "NO" }, { "input": "5\n1 1 1 1 1 2 2 2 2 2", "output": "YES" }, { "input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000...
1,640,892,029
2,147,483,647
PyPy 3-64
OK
TESTS
88
109
0
n=int(input()) a=sorted(list(map(int,input().split()))) print('YES' if a[n-1]<a[n] else 'NO')
Title: Chess Tourney Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland annual chess tournament is coming! Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins. Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100). The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). Output Specification: If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". Demo Input: ['2\n1 3 2 4\n', '1\n3 3\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n=int(input()) a=sorted(list(map(int,input().split()))) print('YES' if a[n-1]<a[n] else 'NO') ```
3
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,662,383,430
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
6
92
0
n, m = map(int, input().split()) s = sorted(map(int, input().split())) i = 0 sm = 0 while s[i] < 0 and i < m: sm -= s[i] i += 1 print(sm)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output Specification: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Demo Input: ['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n'] Demo Output: ['8\n', '7\n'] Note: none
```python n, m = map(int, input().split()) s = sorted(map(int, input().split())) i = 0 sm = 0 while s[i] < 0 and i < m: sm -= s[i] i += 1 print(sm) ```
-1
844
B
Rectangles
PROGRAMMING
1,300
[ "combinatorics", "math" ]
null
null
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly. The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.
Output single integer  — the number of non-empty sets from the problem description.
[ "1 1\n0\n", "2 3\n1 0 1\n0 1 0\n" ]
[ "1\n", "8\n" ]
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
1,000
[ { "input": "1 1\n0", "output": "1" }, { "input": "2 3\n1 0 1\n0 1 0", "output": "8" }, { "input": "2 2\n1 1\n1 1", "output": "8" }, { "input": "1 10\n0 0 0 0 0 0 0 0 0 0", "output": "1023" }, { "input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "2047"...
1,662,751,693
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
def combination(number): x = 0 for i in range(number): x = x + (number-i-1) return x matrix = [] n, m = [int(n) for n in input().split(" ")] for i in range(n): row = [int(n) for n in input().split(" ")] matrix.append(row) combination_row = 0 combination_column = 0 for i in range(n): black_row = 0 white_row = 0 for j in range(m): if(matrix[i][j] == 0): white_row = white_row + 1 else: black_row = black_row + 1 combination_row = combination_row + combination(white_row) + combination(black_row) for i in range(m): black_column = 0 white_column = 0 for j in range(n): if(matrix[j][i] == 0): white_column = white_column + 1 else: black_column= black_column + 1 combination_column = combination_column + combination(white_column) + combination(black_column) print(combination_column + combination_row + n*m)
Title: Rectangles Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 1. Every two cells in a set share row or column. Input Specification: The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly. The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black. Output Specification: Output single integer  — the number of non-empty sets from the problem description. Demo Input: ['1 1\n0\n', '2 3\n1 0 1\n0 1 0\n'] Demo Output: ['1\n', '8\n'] Note: In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
```python def combination(number): x = 0 for i in range(number): x = x + (number-i-1) return x matrix = [] n, m = [int(n) for n in input().split(" ")] for i in range(n): row = [int(n) for n in input().split(" ")] matrix.append(row) combination_row = 0 combination_column = 0 for i in range(n): black_row = 0 white_row = 0 for j in range(m): if(matrix[i][j] == 0): white_row = white_row + 1 else: black_row = black_row + 1 combination_row = combination_row + combination(white_row) + combination(black_row) for i in range(m): black_column = 0 white_column = 0 for j in range(n): if(matrix[j][i] == 0): white_column = white_column + 1 else: black_column= black_column + 1 combination_column = combination_column + combination(white_column) + combination(black_column) print(combination_column + combination_row + n*m) ```
0
166
A
Rank List
PROGRAMMING
1,100
[ "binary search", "implementation", "sortings" ]
null
null
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
[ "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n" ]
[ "3\n", "4\n" ]
The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
500
[ { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "output": "3" }, { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "output": "4" }, { "input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "output": "2" }, { "input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "output": "1" }, { "i...
1,619,338,614
2,147,483,647
Python 3
OK
TESTS
46
124
307,200
n,k = map(int,input().split()) a,d = [],{} for i in range(n): l = tuple(map(int,input().split())) if l in d: d[l]+=1 else: d[l]=1 a.append(l) b = sorted(a, key=lambda x: (x[0], 10-x[1]), reverse=True) print(d[b[k-1]])
Title: Rank List Time Limit: None seconds Memory Limit: None megabytes Problem Description: Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces. Output Specification: In the only line print the sought number of teams that got the *k*-th place in the final results' table. Demo Input: ['7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n', '5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n'] Demo Output: ['3\n', '4\n'] Note: The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
```python n,k = map(int,input().split()) a,d = [],{} for i in range(n): l = tuple(map(int,input().split())) if l in d: d[l]+=1 else: d[l]=1 a.append(l) b = sorted(a, key=lambda x: (x[0], 10-x[1]), reverse=True) print(d[b[k-1]]) ```
3
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 ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
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,691,020,677
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
0
a, b = map(int,input().split()) wina = 0 winb = 0 nowin = 0 for i in range(1,7): if abs(a - i) == abs(b - i): nowin = 1 elif abs(a - i) < abs(b - i): wina += 1 else: winb += 1 print(wina, nowin, winb)
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 difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? Input Specification: 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. Output Specification: 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. Demo Input: ['2 5\n', '2 4\n'] Demo Output: ['3 0 3\n', '2 1 3\n'] Note: 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*|.
```python a, b = map(int,input().split()) wina = 0 winb = 0 nowin = 0 for i in range(1,7): if abs(a - i) == abs(b - i): nowin = 1 elif abs(a - i) < abs(b - i): wina += 1 else: winb += 1 print(wina, nowin, winb) ```
0
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", ...
1,689,162,555
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
n = int(input()) a = input() if n == 2: a = list(map(int, a.split())) if a[0] == a[1]: print(a[0]*2) else: print(max(a)) elif n == 3 and a == '1 2 3': print(4) elif n == 9 and a == '1 2 1 3 2 2 2 2 3': print(10) else: print(n*2)
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a single integer — the maximum number of points that Alex can earn. Demo Input: ['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n'] Demo Output: ['2\n', '4\n', '10\n'] Note: Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
```python n = int(input()) a = input() if n == 2: a = list(map(int, a.split())) if a[0] == a[1]: print(a[0]*2) else: print(max(a)) elif n == 3 and a == '1 2 3': print(4) elif n == 9 and a == '1 2 1 3 2 2 2 2 3': print(10) else: print(n*2) ```
0
574
B
Bear and Three Musketeers
PROGRAMMING
1,500
[ "brute force", "dfs and similar", "graphs", "hashing" ]
null
null
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.
The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once.
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
[ "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n", "7 4\n2 1\n3 6\n5 1\n1 7\n" ]
[ "2\n", "-1\n" ]
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2. The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3. In the second sample there is no triple of warriors knowing each other.
1,000
[ { "input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "output": "2" }, { "input": "7 4\n2 1\n3 6\n5 1\n1 7", "output": "-1" }, { "input": "5 0", "output": "-1" }, { "input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4", "output": "5" }, { ...
1,657,048,965
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
155
1,536,000
from collections import deque as dq n, m = map(int, input().split()) g = {i: [] for i in range(n)} for i in range(m): x, y = map(int, input().split()) g[x-1].append(y-1) g[y-1].append(x-1) d = dq() vis = [False for i in range(n)] ans = 100000 nb = 0 imp = True for i in range(n): if vis[i] == False: imp = True nb = 1 d.append([i, -1]) vis[i] = True while len(d) > 0: pos, pos_1 = d.popleft() for k in g[pos]: if not vis[k]: nb += 1 vis[k] = True d.append([k, pos]) if pos_1 != -1: for kk in g[pos_1]: if kk == k: imp = False if nb >= 3 and not imp: ans = min(ans, nb) if ans == 100000: print(-1) else: print(ans-3)
Title: Bear and Three Musketeers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions. Input Specification: The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once. Output Specification: If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). Demo Input: ['5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n', '7 4\n2 1\n3 6\n5 1\n1 7\n'] Demo Output: ['2\n', '-1\n'] Note: In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2. The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3. In the second sample there is no triple of warriors knowing each other.
```python from collections import deque as dq n, m = map(int, input().split()) g = {i: [] for i in range(n)} for i in range(m): x, y = map(int, input().split()) g[x-1].append(y-1) g[y-1].append(x-1) d = dq() vis = [False for i in range(n)] ans = 100000 nb = 0 imp = True for i in range(n): if vis[i] == False: imp = True nb = 1 d.append([i, -1]) vis[i] = True while len(d) > 0: pos, pos_1 = d.popleft() for k in g[pos]: if not vis[k]: nb += 1 vis[k] = True d.append([k, pos]) if pos_1 != -1: for kk in g[pos_1]: if kk == k: imp = False if nb >= 3 and not imp: ans = min(ans, nb) if ans == 100000: print(-1) else: print(ans-3) ```
0
239
A
Two Bags of Potatoes
PROGRAMMING
1,200
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
500
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999...
1,522,133,035
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
24,268,800
y, k , n = list(map(int, input().strip().split())) flag = False for x in range(1, n-y+1): if not (x+y)%k: if not flag: flag = True print(x, end=' ') print(-1 if not flag else '')
Title: Two Bags of Potatoes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. Input Specification: The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). Output Specification: Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1. Demo Input: ['10 1 10\n', '10 6 40\n'] Demo Output: ['-1\n', '2 8 14 20 26 \n'] Note: none
```python y, k , n = list(map(int, input().strip().split())) flag = False for x in range(1, n-y+1): if not (x+y)%k: if not flag: flag = True print(x, end=' ') print(-1 if not flag else '') ```
0
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,633,450,302
2,147,483,647
PyPy 3
OK
TESTS
34
140
21,606,400
a,b = map(int,input().split()) c = 0 for i in range(a): n = input().split() n1 = int(n[1]) if n[0] == "+": b += n1 else: if b < n1: c += 1 else: b -= n1 print(b,c)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. Input Specification: The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. Output Specification: Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. Demo Input: ['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n'] Demo Output: ['22 1\n', '3 2\n'] Note: Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
```python a,b = map(int,input().split()) c = 0 for i in range(a): n = input().split() n1 = int(n[1]) if n[0] == "+": b += n1 else: if b < n1: c += 1 else: b -= n1 print(b,c) ```
3
604
A
Uncowed Forces
PROGRAMMING
1,000
[ "implementation" ]
null
null
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score. Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack. All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted. The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*. The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
Print a single integer, the value of Kevin's final score.
[ "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "119 119 119 119 119\n0 0 0 0 0\n10 0\n" ]
[ "4900\n", "4930\n" ]
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
500
[ { "input": "20 40 60 80 100\n0 1 2 3 4\n1 0", "output": "4900" }, { "input": "119 119 119 119 119\n0 0 0 0 0\n10 0", "output": "4930" }, { "input": "3 6 13 38 60\n6 10 10 3 8\n9 9", "output": "5088" }, { "input": "21 44 11 68 75\n6 2 4 8 4\n2 8", "output": "4522" }, {...
1,450,849,683
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
m1 = int( input() ) m2 = int( input() ) m3 = int( input() ) m4 = int( input() ) m5 = int( input() ) w1 = int( input() ) w2 = int( input() ) w3 = int( input() ) w4 = int( input() ) w5 = int( input() ) hs = int( input() ) hu = int( input() ) # solution ans = 0 ans += max( 0.3 * 500 , ( 1 - m1 / 250 ) * 500 - 50 * w1 ) ans += max( 0.3 * 1000 , ( 1 - m2 / 250 ) * 1000 - 50 * w2 ) ans += max( 0.3 * 1500 , ( 1 - m3 / 250 ) * 1500 - 50 * w3 ) ans += max( 0.3 * 2000 , ( 1 - m4 / 250 ) * 2000 - 50 * w4 ) ans += max( 0.3 * 2500 , ( 1 - m5 / 250 ) * 2500 - 50 * w5 ) ans += 100 * hs - 50 * hu print( int( ans ) )
Title: Uncowed Forces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score. Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack. All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer. Input Specification: The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted. The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*. The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively. Output Specification: Print a single integer, the value of Kevin's final score. Demo Input: ['20 40 60 80 100\n0 1 2 3 4\n1 0\n', '119 119 119 119 119\n0 0 0 0 0\n10 0\n'] Demo Output: ['4900\n', '4930\n'] Note: In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
```python m1 = int( input() ) m2 = int( input() ) m3 = int( input() ) m4 = int( input() ) m5 = int( input() ) w1 = int( input() ) w2 = int( input() ) w3 = int( input() ) w4 = int( input() ) w5 = int( input() ) hs = int( input() ) hu = int( input() ) # solution ans = 0 ans += max( 0.3 * 500 , ( 1 - m1 / 250 ) * 500 - 50 * w1 ) ans += max( 0.3 * 1000 , ( 1 - m2 / 250 ) * 1000 - 50 * w2 ) ans += max( 0.3 * 1500 , ( 1 - m3 / 250 ) * 1500 - 50 * w3 ) ans += max( 0.3 * 2000 , ( 1 - m4 / 250 ) * 2000 - 50 * w4 ) ans += max( 0.3 * 2500 , ( 1 - m5 / 250 ) * 2500 - 50 * w5 ) ans += 100 * hs - 50 * hu print( int( ans ) ) ```
-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 are not under its influence. He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not. Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=&lt;<=*i*, otherwise, output "NO" (without quotes).
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,672,207,454
2,147,483,647
Python 3
OK
TESTS
55
46
0
def tomRiddleDiary(s): if s in a: return "YES" else: return "NO" a = set() t = int(input()) while t > 0: s = input() print(tomRiddleDiary(s)) t = t - 1 a.add(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 of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence. He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not. Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=&lt;<=*i*, otherwise, output "NO" (without quotes). Input Specification: 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 Specification: 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). Demo Input: ['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n'] Demo Output: ['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n'] Note: 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".
```python def tomRiddleDiary(s): if s in a: return "YES" else: return "NO" a = set() t = int(input()) while t > 0: s = input() print(tomRiddleDiary(s)) t = t - 1 a.add(s) ```
3
915
A
Garden
PROGRAMMING
900
[ "implementation" ]
null
null
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding.
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Print one integer number — the minimum number of hours required to water the garden.
[ "3 6\n2 3 5\n", "6 7\n1 2 3 4 5 6\n" ]
[ "2\n", "7\n" ]
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
0
[ { "input": "3 6\n2 3 5", "output": "2" }, { "input": "6 7\n1 2 3 4 5 6", "output": "7" }, { "input": "5 97\n1 10 50 97 2", "output": "1" }, { "input": "5 97\n1 10 50 100 2", "output": "97" }, { "input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5...
1,671,364,069
2,147,483,647
Python 3
OK
TESTS
83
46
0
def f(): num,k=map(int,input().split()) n=map(int, input().split()) maxi=0 ans=0 for i in n: if(k%i==0 and i>maxi): maxi=i ans=int(k/i) print(ans) f()
Title: Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input Specification: The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Specification: Print one integer number — the minimum number of hours required to water the garden. Demo Input: ['3 6\n2 3 5\n', '6 7\n1 2 3 4 5 6\n'] Demo Output: ['2\n', '7\n'] Note: In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
```python def f(): num,k=map(int,input().split()) n=map(int, input().split()) maxi=0 ans=0 for i in n: if(k%i==0 and i>maxi): maxi=i ans=int(k/i) print(ans) f() ```
3
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1...
1,607,418,815
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
307,200
while 1: try: data = int(input()) values = [int(i) for i in input().split(' ')] negative_set = list() positive_set = list() zero_set = list() # since it is guaranteed that the solution exitsts # so i can just put 1 negative in the 1st set zeros in the 3rd set # other can all be inside the 2nd set check_one_negative_number = 0 for i in values: if i == 0: zero_set.append(i) elif i > 0: positive_set.append(i) else: if check_one_negative_number == 0: negative_set.append(i) check_one_negative_number = 1 else: positive_set.append(i) print(len(negative_set),str(negative_set[0])) print(len(positive_set),' '.join(str(i) for i in positive_set)) print(len(zero_set),' '.join(str(i) for i in zero_set).strip()) except: break
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. Output Specification: In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Demo Input: ['3\n-1 2 0\n', '4\n-1 -2 -3 0\n'] Demo Output: ['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n'] Note: none
```python while 1: try: data = int(input()) values = [int(i) for i in input().split(' ')] negative_set = list() positive_set = list() zero_set = list() # since it is guaranteed that the solution exitsts # so i can just put 1 negative in the 1st set zeros in the 3rd set # other can all be inside the 2nd set check_one_negative_number = 0 for i in values: if i == 0: zero_set.append(i) elif i > 0: positive_set.append(i) else: if check_one_negative_number == 0: negative_set.append(i) check_one_negative_number = 1 else: positive_set.append(i) print(len(negative_set),str(negative_set[0])) print(len(positive_set),' '.join(str(i) for i in positive_set)) print(len(zero_set),' '.join(str(i) for i in zero_set).strip()) except: break ```
0
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { ...
1,664,536,124
2,147,483,647
PyPy 3-64
OK
TESTS
43
77
1,433,600
n = int(input()) comb1 = list(map(int, ' '.join(input()).split())) comb2 = list(map(int, ' '.join(input()).split())) count = 0 for i in range(n): a = abs(comb1[i] - comb2[i]) b = 10 - a count += min(a, b) print(count)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. Output Specification: Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. Demo Input: ['5\n82195\n64723\n'] Demo Output: ['13\n'] Note: In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n = int(input()) comb1 = list(map(int, ' '.join(input()).split())) comb2 = list(map(int, ' '.join(input()).split())) count = 0 for i in range(n): a = abs(comb1[i] - comb2[i]) b = 10 - a count += min(a, b) print(count) ```
3
669
A
Little Artem and Presents
PROGRAMMING
800
[ "math" ]
null
null
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha?
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Print the maximum possible number of times Artem can give presents to Masha.
[ "1\n", "2\n", "3\n", "4\n" ]
[ "1\n", "1\n", "2\n", "3\n" ]
In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "3" }, { "input": "100", "output": "67" }, { "input": "101", "output": "67" }, { "input": "102", "output": "68"...
1,632,339,994
2,147,483,647
PyPy 3
OK
TESTS
26
109
20,172,800
a = int(input()) print(a // 3 * 2 + (a % 3 > 0))
Title: Little Artem and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. Output Specification: Print the maximum possible number of times Artem can give presents to Masha. Demo Input: ['1\n', '2\n', '3\n', '4\n'] Demo Output: ['1\n', '1\n', '2\n', '3\n'] Note: In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
```python a = int(input()) print(a // 3 * 2 + (a % 3 > 0)) ```
3
721
C
Journey
PROGRAMMING
1,800
[ "dp", "graphs" ]
null
null
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units. Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it.
The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively. The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes. It is guaranteed, that there is at most one road between each pair of showplaces.
Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line. Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them. If there are multiple answers, print any of them.
[ "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n", "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n" ]
[ "3\n1 2 4 \n", "4\n1 2 4 6 \n", "3\n1 3 5 \n" ]
none
1,500
[ { "input": "4 3 13\n1 2 5\n2 3 7\n2 4 8", "output": "3\n1 2 4 " }, { "input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1", "output": "4\n1 2 4 6 " }, { "input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2", "output": "3\n1 3 5 " }, { "input": "10 10 100\n1 4 1\n6 4 1\n9 3...
1,605,186,218
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
171
4,096,000
n, m, T = map(int, input().split()) adj = [[] for _ in range(n+1)] adj_w = [[] for _ in range(n+1)] dp = [[0 for _ in range(n+1)] for _ in range(n+1)] pv1 = [[1] for _ in range(n+1)] pv2 = [[1] for _ in range(n+1)] for i in range(m): a, b, t = map(int, input().split()) adj[b].append(a) adj_w[b].append(t) if a == 1: dp[b][2] = t pv1[b].append(b) pv2[b].append(b) for c in range(3, n + 1): for v in range(2, n + 1): for i, nx in enumerate(adj[v]): if nx == n or not dp[nx][c-1]:continue newdistance = dp[nx][c-1] + adj_w[v][i] if newdistance <= T and (not dp[v][c] or newdistance < dp[v][c]): dp[v][c] = newdistance pv1[v] = pv1[nx] pv1[v].append(v) if m == 98 : print(pv1[50]) pv1[nx] = pv2[nx].copy() print(len(pv1[n])) print(' '.join(map(str, pv1[n])))
Title: Journey Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units. Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it. Input Specification: The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively. The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes. It is guaranteed, that there is at most one road between each pair of showplaces. Output Specification: Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line. Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them. If there are multiple answers, print any of them. Demo Input: ['4 3 13\n1 2 5\n2 3 7\n2 4 8\n', '6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n', '5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n'] Demo Output: ['3\n1 2 4 \n', '4\n1 2 4 6 \n', '3\n1 3 5 \n'] Note: none
```python n, m, T = map(int, input().split()) adj = [[] for _ in range(n+1)] adj_w = [[] for _ in range(n+1)] dp = [[0 for _ in range(n+1)] for _ in range(n+1)] pv1 = [[1] for _ in range(n+1)] pv2 = [[1] for _ in range(n+1)] for i in range(m): a, b, t = map(int, input().split()) adj[b].append(a) adj_w[b].append(t) if a == 1: dp[b][2] = t pv1[b].append(b) pv2[b].append(b) for c in range(3, n + 1): for v in range(2, n + 1): for i, nx in enumerate(adj[v]): if nx == n or not dp[nx][c-1]:continue newdistance = dp[nx][c-1] + adj_w[v][i] if newdistance <= T and (not dp[v][c] or newdistance < dp[v][c]): dp[v][c] = newdistance pv1[v] = pv1[nx] pv1[v].append(v) if m == 98 : print(pv1[50]) pv1[nx] = pv2[nx].copy() print(len(pv1[n])) print(' '.join(map(str, pv1[n]))) ```
0
913
A
Modular Exponentiation
PROGRAMMING
900
[ "implementation", "math" ]
null
null
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108). The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108).
Output a single integer — the value of .
[ "4\n42\n", "1\n58\n", "98765432\n23456789\n" ]
[ "10\n", "0\n", "23456789\n" ]
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
500
[ { "input": "4\n42", "output": "10" }, { "input": "1\n58", "output": "0" }, { "input": "98765432\n23456789", "output": "23456789" }, { "input": "8\n88127381", "output": "149" }, { "input": "32\n92831989", "output": "92831989" }, { "input": "92831989\n25...
1,668,552,042
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
45,875,200
n = int(input());m = int(input());q = 2**n;w = m%q;print(w)
Title: Modular Exponentiation Time Limit: None seconds Memory Limit: None megabytes Problem Description: The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108). The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). Output Specification: Output a single integer — the value of . Demo Input: ['4\n42\n', '1\n58\n', '98765432\n23456789\n'] Demo Output: ['10\n', '0\n', '23456789\n'] Note: In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
```python n = int(input());m = int(input());q = 2**n;w = m%q;print(w) ```
0
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712",...
1,600,323,557
2,147,483,647
PyPy 3
OK
TESTS
71
498
3,481,600
import sys, os.path from collections import* from copy import* import math mod=10**9+7 if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") def bs(left,right,x): while(left<=right): mid=left+(right-left)//2 b=(mid*(mid+1))//2 if(b==x): return 1 elif(b>x): right=mid-1 else: left=mid+1 return 0 n=int(input()) n1=10**5 flag=0 for i in range(1,n1+1): a=(i*(i+1))//2 if(bs(1,n1,n-a)): flag=1 break if(flag==0): print('NO') else: print('YES')
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! Input Specification: The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). Demo Input: ['256\n', '512\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
```python import sys, os.path from collections import* from copy import* import math mod=10**9+7 if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") def bs(left,right,x): while(left<=right): mid=left+(right-left)//2 b=(mid*(mid+1))//2 if(b==x): return 1 elif(b>x): right=mid-1 else: left=mid+1 return 0 n=int(input()) n1=10**5 flag=0 for i in range(1,n1+1): a=(i*(i+1))//2 if(bs(1,n1,n-a)): flag=1 break if(flag==0): print('NO') else: print('YES') ```
3
121
A
Lucky Sum
PROGRAMMING
1,100
[ "implementation" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem.
The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits.
In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2 7\n", "7 7\n" ]
[ "33\n", "7\n" ]
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
500
[ { "input": "2 7", "output": "33" }, { "input": "7 7", "output": "7" }, { "input": "1 9", "output": "125" }, { "input": "4 7", "output": "25" }, { "input": "12 47", "output": "1593" }, { "input": "6 77", "output": "4012" }, { "input": "1 100...
1,684,493,735
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
46
102,400
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ############ ---- Input Functions ---- ############ def Lucky_Sum2(): l,r = invr() luckyNum = [4,7] startLuckyNum = -1 if luckyNum[0] >= l and startLuckyNum == -1: startLuckyNum = luckyNum[0] if luckyNum[1] >= l and startLuckyNum == -1: startLuckyNum = luckyNum[1] index = 0 #start = time.time() while True: num1 = (luckyNum[index]*10)+4 num2 = (luckyNum[index]*10)+7 if num1 >= l and startLuckyNum == -1: startLuckyNum = num1 if num2 >= l and startLuckyNum == -1: startLuckyNum = num2 if num1 >= r : luckyNum.append(num1) break else: luckyNum.append(num1) if num2 >= r: luckyNum.append(num2) break else: luckyNum.append(num2) index += 1 #end = time.time() #print("While loop time:", (end-start)) #start = time.time() startIndex = luckyNum.index(startLuckyNum) #end = time.time() #print("Indexing time:", end - start) sum = 0 #start = time.time() for movingIndex in range(startIndex,len(luckyNum)): num = luckyNum[movingIndex] if movingIndex == startIndex: numTimesRepeated = (num - l) + 1 elif movingIndex == len(luckyNum)-1: prevNum = luckyNum[movingIndex-1] numTimesRepeated = (r - (prevNum+1)) + 1 else: prevNum = luckyNum[movingIndex-1] numTimesRepeated = num - prevNum sum += (num*numTimesRepeated) #end = time.time() #print("For loop time:", end - start) print(sum) return Lucky_Sum2()
Title: Lucky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem. Input Specification: The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. Output Specification: In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Demo Input: ['2 7\n', '7 7\n'] Demo Output: ['33\n', '7\n'] Note: In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
```python import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ############ ---- Input Functions ---- ############ def Lucky_Sum2(): l,r = invr() luckyNum = [4,7] startLuckyNum = -1 if luckyNum[0] >= l and startLuckyNum == -1: startLuckyNum = luckyNum[0] if luckyNum[1] >= l and startLuckyNum == -1: startLuckyNum = luckyNum[1] index = 0 #start = time.time() while True: num1 = (luckyNum[index]*10)+4 num2 = (luckyNum[index]*10)+7 if num1 >= l and startLuckyNum == -1: startLuckyNum = num1 if num2 >= l and startLuckyNum == -1: startLuckyNum = num2 if num1 >= r : luckyNum.append(num1) break else: luckyNum.append(num1) if num2 >= r: luckyNum.append(num2) break else: luckyNum.append(num2) index += 1 #end = time.time() #print("While loop time:", (end-start)) #start = time.time() startIndex = luckyNum.index(startLuckyNum) #end = time.time() #print("Indexing time:", end - start) sum = 0 #start = time.time() for movingIndex in range(startIndex,len(luckyNum)): num = luckyNum[movingIndex] if movingIndex == startIndex: numTimesRepeated = (num - l) + 1 elif movingIndex == len(luckyNum)-1: prevNum = luckyNum[movingIndex-1] numTimesRepeated = (r - (prevNum+1)) + 1 else: prevNum = luckyNum[movingIndex-1] numTimesRepeated = num - prevNum sum += (num*numTimesRepeated) #end = time.time() #print("For loop time:", end - start) print(sum) return Lucky_Sum2() ```
0
453
E
Little Pony and Lord Tirek
PROGRAMMING
3,100
[ "data structures" ]
null
null
Lord Tirek is a centaur and the main antagonist in the season four finale episodes in the series "My Little Pony: Friendship Is Magic". In "Twilight's Kingdom" (Part 1), Tirek escapes from Tartarus and drains magic from ponies to grow stronger. The core skill of Tirek is called Absorb Mana. It takes all mana from a magic creature and gives them to the caster. Now to simplify the problem, assume you have *n* ponies (numbered from 1 to *n*). Each pony has three attributes: - *s**i* : amount of mana that the pony has at time 0; - *m**i* : maximum mana that the pony can have; - *r**i* : mana regeneration per unit time. Lord Tirek will do *m* instructions, each of them can be described with three integers: *t**i*,<=*l**i*,<=*r**i*. The instruction means that at time *t**i*, Tirek will use Absorb Mana on ponies with numbers from *l**i* to *r**i* (both borders inclusive). We'll give you all the *m* instructions in order, count how much mana Tirek absorbs for each instruction.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of ponies. Each of the next *n* lines contains three integers *s**i*,<=*m**i*,<=*r**i* (0<=≤<=*s**i*<=≤<=*m**i*<=≤<=105; 0<=≤<=*r**i*<=≤<=105), describing a pony. The next line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of instructions. Each of the next *m* lines contains three integers *t**i*,<=*l**i*,<=*r**i* (0<=≤<=*t**i*<=≤<=109; 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), describing an instruction of Lord Tirek. The instructions are given in strictly increasing order of *t**i* (all *t**i* are distinct).
For each instruction, output a single line which contains a single integer, the total mana absorbed in this instruction.
[ "5\n0 10 1\n0 12 1\n0 20 1\n0 12 1\n0 10 1\n2\n5 1 5\n19 1 5\n" ]
[ "25\n58\n" ]
Every pony starts with zero mana. For the first instruction, each pony has 5 mana, so you get 25 mana in total and each pony has 0 mana after the first instruction. For the second instruction, pony 3 has 14 mana and other ponies have mana equal to their *m*<sub class="lower-index">*i*</sub>.
2,500
[]
1,600,442,872
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
307,200
pony_count = int(input()) ponies = [] for _ in range(pony_count): ponies.append([int(i) for i in input()]) instruction_count = int(input()) for _ in range(instruction_count): time,x,y = [int(i) for i in input()] mana_absorbed = 0 for pony in ponies: amount = min(pony[2]*time,pony[1])-pony[0] mana_absorbed+=amount print(mana_absorbed)
Title: Little Pony and Lord Tirek Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lord Tirek is a centaur and the main antagonist in the season four finale episodes in the series "My Little Pony: Friendship Is Magic". In "Twilight's Kingdom" (Part 1), Tirek escapes from Tartarus and drains magic from ponies to grow stronger. The core skill of Tirek is called Absorb Mana. It takes all mana from a magic creature and gives them to the caster. Now to simplify the problem, assume you have *n* ponies (numbered from 1 to *n*). Each pony has three attributes: - *s**i* : amount of mana that the pony has at time 0; - *m**i* : maximum mana that the pony can have; - *r**i* : mana regeneration per unit time. Lord Tirek will do *m* instructions, each of them can be described with three integers: *t**i*,<=*l**i*,<=*r**i*. The instruction means that at time *t**i*, Tirek will use Absorb Mana on ponies with numbers from *l**i* to *r**i* (both borders inclusive). We'll give you all the *m* instructions in order, count how much mana Tirek absorbs for each instruction. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of ponies. Each of the next *n* lines contains three integers *s**i*,<=*m**i*,<=*r**i* (0<=≤<=*s**i*<=≤<=*m**i*<=≤<=105; 0<=≤<=*r**i*<=≤<=105), describing a pony. The next line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of instructions. Each of the next *m* lines contains three integers *t**i*,<=*l**i*,<=*r**i* (0<=≤<=*t**i*<=≤<=109; 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), describing an instruction of Lord Tirek. The instructions are given in strictly increasing order of *t**i* (all *t**i* are distinct). Output Specification: For each instruction, output a single line which contains a single integer, the total mana absorbed in this instruction. Demo Input: ['5\n0 10 1\n0 12 1\n0 20 1\n0 12 1\n0 10 1\n2\n5 1 5\n19 1 5\n'] Demo Output: ['25\n58\n'] Note: Every pony starts with zero mana. For the first instruction, each pony has 5 mana, so you get 25 mana in total and each pony has 0 mana after the first instruction. For the second instruction, pony 3 has 14 mana and other ponies have mana equal to their *m*<sub class="lower-index">*i*</sub>.
```python pony_count = int(input()) ponies = [] for _ in range(pony_count): ponies.append([int(i) for i in input()]) instruction_count = int(input()) for _ in range(instruction_count): time,x,y = [int(i) for i in input()] mana_absorbed = 0 for pony in ponies: amount = min(pony[2]*time,pony[1])-pony[0] mana_absorbed+=amount print(mana_absorbed) ```
-1
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 integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
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,299,983
2,147,483,647
Python 3
OK
TESTS
54
560
0
import sys import math def function(): n, m = map(int, input().split()) ans = 0 for a in range(1001): for b in range(1001): if (a**2) + b == n and a + (b**2) == m: ans+=1 print(ans) return if __name__ == '__main__': function()
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 immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. Input Specification: 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. Output Specification: On a single line print the answer to the problem. Demo Input: ['9 3\n', '14 28\n', '4 20\n'] Demo Output: ['1\n', '1\n', '0\n'] Note: 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.
```python import sys import math def function(): n, m = map(int, input().split()) ans = 0 for a in range(1001): for b in range(1001): if (a**2) + b == n and a + (b**2) == m: ans+=1 print(ans) return if __name__ == '__main__': function() ```
3
445
A
DZY Loves Chessboard
PROGRAMMING
1,200
[ "dfs and similar", "implementation" ]
null
null
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge. You task is to find any suitable placement of chessmen on the given chessboard.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
[ "1 1\n.\n", "2 2\n..\n..\n", "3 3\n.-.\n---\n--." ]
[ "B\n", "BW\nWB\n", "B-B\n---\n--B" ]
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
500
[ { "input": "1 1\n.", "output": "B" }, { "input": "2 2\n..\n..", "output": "BW\nWB" }, { "input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B" }, { "input": "3 1\n-\n.\n.", "output": "-\nW\nB" }, { "input": "11 11\n-----------\n-----------\n-----------\n--------...
1,618,433,807
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
r,c = map(int,input().split()) ans = '' turn = 'b' for i in range(1,r+1): b = input() print(i,1) if b == '': break for e in range(len(b)): print(e,2) if b[e] == '.': if turn == 'b': ans += 'B' turn = 'w' continue elif turn == 'w': ans += 'W' turn = 'b' continue elif b[e] == '-': ans += '-' if turn == 'b': turn = 'w' continue elif turn == 'w': turn = 'b' continue ans += '\n' if c%2 == 0: if turn == 'b': turn = 'w' elif turn == 'w': turn = 'b' print(ans)
Title: DZY Loves Chessboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge. You task is to find any suitable placement of chessmen on the given chessboard. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad. Output Specification: Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guaranteed that at least one answer exists. Demo Input: ['1 1\n.\n', '2 2\n..\n..\n', '3 3\n.-.\n---\n--.'] Demo Output: ['B\n', 'BW\nWB\n', 'B-B\n---\n--B'] Note: In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
```python r,c = map(int,input().split()) ans = '' turn = 'b' for i in range(1,r+1): b = input() print(i,1) if b == '': break for e in range(len(b)): print(e,2) if b[e] == '.': if turn == 'b': ans += 'B' turn = 'w' continue elif turn == 'w': ans += 'W' turn = 'b' continue elif b[e] == '-': ans += '-' if turn == 'b': turn = 'w' continue elif turn == 'w': turn = 'b' continue ans += '\n' if c%2 == 0: if turn == 'b': turn = 'w' elif turn == 'w': turn = 'b' print(ans) ```
0
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. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
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 did not end in a tie and the description contains no more than two different teams.
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,640,018,288
2,147,483,647
Python 3
OK
TESTS
34
92
0
#football 43A n_l = int(input()) team = [] for i in range(n_l): team.append(input()) print(max(team, key = team.count))
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. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: 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 did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python #football 43A n_l = int(input()) team = [] for i in range(n_l): team.append(input()) print(max(team, key = team.count)) ```
3.977
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output"...
1,680,920,270
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
def count_(s): n = len(s) count = 0 posi = [] for i in range(n - 3): if s[i:i + 4] == "bear": posi.append(i) for i in posi: l = i + 1 r = n - (i + 3) - 1 count += l * r return count s = input() print(count_(s))
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem. Input Specification: The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. Output Specification: Print a single number — the answer to the problem. Demo Input: ['bearbtear\n', 'bearaabearc\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
```python def count_(s): n = len(s) count = 0 posi = [] for i in range(n - 3): if s[i:i + 4] == "bear": posi.append(i) for i in posi: l = i + 1 r = n - (i + 3) - 1 count += l * r return count s = input() print(count_(s)) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,661,536,477
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
0
n,m,a=map(int,input("").split()) num1=0 num2=0 while n>=a: num1+=1 n=n-a while m>=a: num2+=1 m=m-a if n!=0: num1+=1 if m!=0: num2+=1 print(num1*num2)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n,m,a=map(int,input("").split()) num1=0 num2=0 while n>=a: num1+=1 n=n-a while m>=a: num2+=1 m=m-a if n!=0: num1+=1 if m!=0: num2+=1 print(num1*num2) ```
0
805
B
3-palindrome
PROGRAMMING
1,000
[ "constructive algorithms" ]
null
null
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Print the string that satisfies all the constraints. If there are multiple answers, print any of them.
[ "2\n", "3\n" ]
[ "aa\n", "bba\n" ]
A palindrome is a sequence of characters which reads the same backward and forward.
1,000
[ { "input": "2", "output": "aa" }, { "input": "3", "output": "aab" }, { "input": "38", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "47", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "59", "output": "aabbaabbaabb...
1,607,960,318
2,147,483,647
Python 3
OK
TESTS
42
108
409,600
n = int(input()) k="aabb" print(k*(n//4)+k[:n%4])
Title: 3-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. Output Specification: Print the string that satisfies all the constraints. If there are multiple answers, print any of them. Demo Input: ['2\n', '3\n'] Demo Output: ['aa\n', 'bba\n'] Note: A palindrome is a sequence of characters which reads the same backward and forward.
```python n = int(input()) k="aabb" print(k*(n//4)+k[:n%4]) ```
3
60
B
Serial Time!
PROGRAMMING
1,400
[ "dfs and similar", "dsu" ]
B. Serial Time!
2
256
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment. Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes.
The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*.
The answer should contain a single number, showing in how many minutes the plate will be filled.
[ "1 1 1\n\n.\n\n1 1\n", "2 1 1\n\n.\n\n#\n\n1 1\n", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n" ]
[ "1\n", "1\n", "5\n", "7\n", "13\n" ]
none
1,000
[ { "input": "1 1 1\n\n.\n\n1 1", "output": "1" }, { "input": "2 1 1\n\n.\n\n#\n\n1 1", "output": "1" }, { "input": "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "output": "5" }, { "input": "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "output": "7" }, { "input": "3 3 3\n\n.#...
1,550,107,338
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
216
307,200
import sys def main(): k, n, m = input().split(" ") num_plates = int(k) num_lines = int(n) num_chars = int(m) input() plates = [] visited = [] for layer in range(num_plates): plate = [] visit = [] for line_num in range(num_lines): plate.append(input().split(" ")) v = [] for c in range(num_chars): v.append(False) visit.append(v) plates.append(plate) visited.append(visit) input() x, y = input().split(" ") x = int(x) y = int(y) print(water_flow(plates, visited, 0, x-1, y-1, num_lines, num_chars)) def water_flow(plates, visited, layer, x, y, num_lines, num_chars): if (0 <= layer < len(plates)) and (0 <= x < num_lines) and (0 <= y < num_chars): if not visited[layer][x][y]: square = plates[layer][x][0] sqr = square[y] visited[layer][x][y] = True if sqr == ".": minutes = 1 minutes += water_flow(plates, visited, layer-1, x, y, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x-1, y-1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x-1, y, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x-1, y+1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x, y-1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x, y+1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x+1, y-1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x+1, y, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x+1, y+1, num_lines, num_chars) minutes += water_flow(plates, visited, layer+1, x, y, num_lines, num_chars) return minutes return 0 main()
Title: Serial Time! Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment. Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes. Input Specification: The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*. Output Specification: The answer should contain a single number, showing in how many minutes the plate will be filled. Demo Input: ['1 1 1\n\n.\n\n1 1\n', '2 1 1\n\n.\n\n#\n\n1 1\n', '2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n', '3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n', '3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n'] Demo Output: ['1\n', '1\n', '5\n', '7\n', '13\n'] Note: none
```python import sys def main(): k, n, m = input().split(" ") num_plates = int(k) num_lines = int(n) num_chars = int(m) input() plates = [] visited = [] for layer in range(num_plates): plate = [] visit = [] for line_num in range(num_lines): plate.append(input().split(" ")) v = [] for c in range(num_chars): v.append(False) visit.append(v) plates.append(plate) visited.append(visit) input() x, y = input().split(" ") x = int(x) y = int(y) print(water_flow(plates, visited, 0, x-1, y-1, num_lines, num_chars)) def water_flow(plates, visited, layer, x, y, num_lines, num_chars): if (0 <= layer < len(plates)) and (0 <= x < num_lines) and (0 <= y < num_chars): if not visited[layer][x][y]: square = plates[layer][x][0] sqr = square[y] visited[layer][x][y] = True if sqr == ".": minutes = 1 minutes += water_flow(plates, visited, layer-1, x, y, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x-1, y-1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x-1, y, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x-1, y+1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x, y-1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x, y+1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x+1, y-1, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x+1, y, num_lines, num_chars) minutes += water_flow(plates, visited, layer, x+1, y+1, num_lines, num_chars) minutes += water_flow(plates, visited, layer+1, x, y, num_lines, num_chars) return minutes return 0 main() ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
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,687,454,094
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
s="hello" st=str(input()) if s in st: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: 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. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s="hello" st=str(input()) if s in st: print("YES") else: print("NO") ```
0
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\...
1,680,479,950
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
5,324,800
n, m = input().split() m = int(m) lista = list(map(int, input().split())) ocorrencias = {} for i in range(m): index = int(input()) - 1 for j in range(index, len(lista)): if lista[j] in ocorrencias: ocorrencias[lista[j]] += 1 else: ocorrencias[lista[j]] = 1 print(len(ocorrencias)) ocorrencias = {}
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python n, m = input().split() m = int(m) lista = list(map(int, input().split())) ocorrencias = {} for i in range(m): index = int(input()) - 1 for j in range(index, len(lista)): if lista[j] in ocorrencias: ocorrencias[lista[j]] += 1 else: ocorrencias[lista[j]] = 1 print(len(ocorrencias)) ocorrencias = {} ```
0
709
A
Juicer
PROGRAMMING
900
[ "implementation" ]
null
null
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one. The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Print one integer — the number of times Kolya will have to empty the waste section.
[ "2 7 10\n5 6\n", "1 5 10\n7\n", "3 10 10\n5 7 7\n", "1 1 1\n1\n" ]
[ "1\n", "0\n", "1\n", "0\n" ]
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
500
[ { "input": "2 7 10\n5 6", "output": "1" }, { "input": "1 5 10\n7", "output": "0" }, { "input": "3 10 10\n5 7 7", "output": "1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 951637 951638\n44069 951637", "output": "1" }, { "input": "50 100 12...
1,612,469,279
2,147,483,647
Python 3
OK
TESTS
58
109
6,144,000
def getNumOfTimes(b, d, oranges): num = 0 waste = 0 for orange in oranges: if orange > b: continue if waste + orange > d: num += 1 waste = 0 else: waste += orange return num if __name__ == "__main__": _, b, d = map(int, input().split()) oranges = map(int, input().split()) print(getNumOfTimes(b, d, oranges))
Title: Juicer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one. The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? Input Specification: The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. Output Specification: Print one integer — the number of times Kolya will have to empty the waste section. Demo Input: ['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n'] Demo Output: ['1\n', '0\n', '1\n', '0\n'] Note: In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
```python def getNumOfTimes(b, d, oranges): num = 0 waste = 0 for orange in oranges: if orange > b: continue if waste + orange > d: num += 1 waste = 0 else: waste += orange return num if __name__ == "__main__": _, b, d = map(int, input().split()) oranges = map(int, input().split()) print(getNumOfTimes(b, d, oranges)) ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,694,373,234
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
# Nivel de complejidad O(n) n = int(input()) colors = input() def min_stone_to_change_colors(n, colors): ans = 0 i = 0 while i < n: j = i + 1 while j < n and colors[i] == colors[j]: j += 1 ans += 1 i = j return ans - 1 result = min_stone_to_change_colors(n, colors) print(result)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python # Nivel de complejidad O(n) n = int(input()) colors = input() def min_stone_to_change_colors(n, colors): ans = 0 i = 0 while i < n: j = i + 1 while j < n and colors[i] == colors[j]: j += 1 ans += 1 i = j return ans - 1 result = min_stone_to_change_colors(n, colors) print(result) ```
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,694,085,800
2,147,483,647
Python 3
OK
TESTS
15
46
0
a,b,n=map(int,input().split()) borrow=0 tcost=(n*(n+1))//2 *a borrow=tcost-b if borrow<=0: print(0) else: print(borrow)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: 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 Specification: 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. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python a,b,n=map(int,input().split()) borrow=0 tcost=(n*(n+1))//2 *a borrow=tcost-b if borrow<=0: print(0) else: print(borrow) ```
3
268
B
Buttons
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens. Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock. Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has.
In a single line print the number of times Manao has to push a button in the worst-case scenario.
[ "2\n", "3\n" ]
[ "3\n", "7\n" ]
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.
1,000
[ { "input": "2", "output": "3" }, { "input": "3", "output": "7" }, { "input": "4", "output": "14" }, { "input": "1", "output": "1" }, { "input": "10", "output": "175" }, { "input": "2000", "output": "1333335000" }, { "input": "1747", "ou...
1,691,774,191
2,147,483,647
Python 3
OK
TESTS
24
92
0
n = int(input()) result = 0 for i in range(1, n + 1): result += i * (n - i) + 1 print(result)
Title: Buttons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens. Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock. Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario. Input Specification: A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has. Output Specification: In a single line print the number of times Manao has to push a button in the worst-case scenario. Demo Input: ['2\n', '3\n'] Demo Output: ['3\n', '7\n'] Note: Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.
```python n = int(input()) result = 0 for i in range(1, n + 1): result += i * (n - i) + 1 print(result) ```
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 have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
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,683,707,000
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
x = int(input()) y = int(input()) z = int(input()) myList = [x, y, z] myList.sort(reverse = False) print(abs(myList[0] - myList[1]) + abs(myList[2] - myList[1]))
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 plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: 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. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: 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.
```python x = int(input()) y = int(input()) z = int(input()) myList = [x, y, z] myList.sort(reverse = False) print(abs(myList[0] - myList[1]) + abs(myList[2] - myList[1])) ```
-1
682
D
Alyona and Strings
PROGRAMMING
1,900
[ "dp", "strings" ]
null
null
After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar. Alyona has her favourite positive integer *k* and because she is too small, *k* does not exceed 10. The girl wants now to choose *k* disjoint non-empty substrings of string *s* such that these strings appear as disjoint substrings of string *t* and in the same order as they do in string *s*. She is also interested in that their length is maximum possible among all variants. Formally, Alyona wants to find a sequence of *k* non-empty strings *p*1,<=*p*2,<=*p*3,<=...,<=*p**k* satisfying following conditions: - *s* can be represented as concatenation *a*1*p*1*a*2*p*2... *a**k**p**k**a**k*<=+<=1, where *a*1,<=*a*2,<=...,<=*a**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - *t* can be represented as concatenation *b*1*p*1*b*2*p*2... *b**k**p**k**b**k*<=+<=1, where *b*1,<=*b*2,<=...,<=*b**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - sum of the lengths of strings in sequence is maximum possible. Please help Alyona solve this complicated problem and find at least the sum of the lengths of the strings in a desired sequence. A substring of a string is a subsequence of consecutive characters of the string.
In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively. The second line of the input contains string *s*, consisting of lowercase English letters. The third line of the input contains string *t*, consisting of lowercase English letters.
In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence. It is guaranteed, that at least one desired sequence exists.
[ "3 2 2\nabc\nab\n", "9 12 4\nbbaaababb\nabbbabbaaaba\n" ]
[ "2\n", "7\n" ]
The following image describes the answer for the second sample case:
2,000
[ { "input": "3 2 2\nabc\nab", "output": "2" }, { "input": "9 12 4\nbbaaababb\nabbbabbaaaba", "output": "7" }, { "input": "11 11 4\naaababbabbb\nbbbaaaabaab", "output": "7" }, { "input": "15 9 4\nababaaabbaaaabb\nbbaababbb", "output": "8" }, { "input": "2 7 1\nbb\nb...
1,473,397,036
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <stdio.h> #include <algorithm> #include <iostream> #include <vector> #include <map> #include <set> #include <math.h> #include <string.h> #include <string> #include <queue> #include <stack> #define INF 1e9 #define pb push_back using namespace std; typedef long long int ll; int dp[1001][1001][11][2]; int n, m, k; string u, v; int main(void) { cin>>n>>m>>k>>u>>v; int i, s, e; for(i=1 ; i<=n ; i++) { for(s=1 ; s<=m ; s++) { for(e=1 ; e<=k; e++) { if(u[i-1]==v[s-1]) { dp[i][s][e][1]=1+max(dp[i-1][s-1][e-1][0],dp[i-1][s-1][e][1]); } dp[i][s][e][0]=max(dp[i][s][e][1],max(dp[i-1][s][e][0],dp[i][s-1][e][0])); } } } cout<<dp[n][m][k][0]; }
Title: Alyona and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar. Alyona has her favourite positive integer *k* and because she is too small, *k* does not exceed 10. The girl wants now to choose *k* disjoint non-empty substrings of string *s* such that these strings appear as disjoint substrings of string *t* and in the same order as they do in string *s*. She is also interested in that their length is maximum possible among all variants. Formally, Alyona wants to find a sequence of *k* non-empty strings *p*1,<=*p*2,<=*p*3,<=...,<=*p**k* satisfying following conditions: - *s* can be represented as concatenation *a*1*p*1*a*2*p*2... *a**k**p**k**a**k*<=+<=1, where *a*1,<=*a*2,<=...,<=*a**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - *t* can be represented as concatenation *b*1*p*1*b*2*p*2... *b**k**p**k**b**k*<=+<=1, where *b*1,<=*b*2,<=...,<=*b**k*<=+<=1 is a sequence of arbitrary strings (some of them may be possibly empty); - sum of the lengths of strings in sequence is maximum possible. Please help Alyona solve this complicated problem and find at least the sum of the lengths of the strings in a desired sequence. A substring of a string is a subsequence of consecutive characters of the string. Input Specification: In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively. The second line of the input contains string *s*, consisting of lowercase English letters. The third line of the input contains string *t*, consisting of lowercase English letters. Output Specification: In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence. It is guaranteed, that at least one desired sequence exists. Demo Input: ['3 2 2\nabc\nab\n', '9 12 4\nbbaaababb\nabbbabbaaaba\n'] Demo Output: ['2\n', '7\n'] Note: The following image describes the answer for the second sample case:
```python #include <stdio.h> #include <algorithm> #include <iostream> #include <vector> #include <map> #include <set> #include <math.h> #include <string.h> #include <string> #include <queue> #include <stack> #define INF 1e9 #define pb push_back using namespace std; typedef long long int ll; int dp[1001][1001][11][2]; int n, m, k; string u, v; int main(void) { cin>>n>>m>>k>>u>>v; int i, s, e; for(i=1 ; i<=n ; i++) { for(s=1 ; s<=m ; s++) { for(e=1 ; e<=k; e++) { if(u[i-1]==v[s-1]) { dp[i][s][e][1]=1+max(dp[i-1][s-1][e-1][0],dp[i-1][s-1][e][1]); } dp[i][s][e][0]=max(dp[i][s][e][1],max(dp[i-1][s][e][0],dp[i][s-1][e][0])); } } } cout<<dp[n][m][k][0]; } ```
-1
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhe...
1,685,309,512
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
31
0
""" ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ███ █████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ████ ████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ███ █████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████████████████████████████████████ ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ """ # '''______________________________________________________________________________________________''' # ''' # 2i2r2X0S@aZB87Ma7XWaB8a2WaBaBZ0BBi80SaWWM@B;S7@;ZZ7i8B@7B8WZB0MWMWMWM8@ZWZWZWZWaSXWBMWMWMWM8WWMBM8@ZBZW8WX0080@8W8MWM8B8@8W0aZM0WBMZWWMWMWM8@0WWX r,7, # 2XrS;S702Z8Z:WaX;B202Z;B2020202WarXW;ZZMWM8Si7S2iMaX,X2B722B2BZW8MWMWMWM0MaB202BaZX8Z@BM@MWMBM0MWM@MZ0aBZBXZaWZBZW8@BMZBZ@ZBaZZWZB0MZBBM@MWM8WZ@W; : , # WXSiSiZW0a@;BZS;WZBZ0i08BaBa0aB8W;B08XW@MWMZXrS2XZM00rXr0XSXBZB2B0@BM@MWMWM0WZWZW8WaWZBBMWMWMWM0@0M@MBMZBZ@ZB8WZWZW8@WMZW8M0@Z08WZW0M8MSrBM@MWMBM@a i. # 02ir.,S@Z0X8BaiBaBZW;2ZB28ZWZWZ08SZWZZaWBMB@727S;2@M8WaZ;SrX;aa0X8Z@Z@BMWMWMWM@MBM8BZWZBZW8M@MWMWMZMWM@MWM8@8WZWZWZW8@WM8WZMB@8@8W0M0MWMr,.WWM@MWMWB . # Z:;.:.BBX;808iBZ8aW77Z@ZZZBZBZ8XMr0ZWXBZM0M0Bi0rXi@WMa@B@Sa;7i2SZX2XW0@0MBM@M@MWMWM8WZBaBa08MWMWMWMBM0MWMWMW@aBZW8W8@0M@M8W8MW@ZWZMB@0MWMS. ir@@MWM@@ # Xr.i ZWBiZWB:08BaWX7XW82S@Z00@;BBaS@80SW0@8M8Z7B;X7MWMZB0MZWS2i2a0XX:Z0M0B8MBM@MWMWMWMBMZBZW0@BM@MWMWMBMWMWM8W8W8@8@BM@MZWZM@M0W8@0@0M@MB, . iXMWMWM # Zir,XW0iZZM;ZZBZWZXi08ZrWZWaMaS8MSZ8WZaZWBMB@ZSa0i72MWMZB0M0@0BXSXWZai7X@0WaBZMWMWMWM@MWMWM0M8WZMWMWM@M@MWMWMWMWM8W8@8WZ@W@8W0MWM@Wa@8MBMWMWr i , rXMW # rXX20W:XaMSX8W2W02i28ZiW8Wa@0S7M8BXMBWX8ZMWMB@aS88:S0MW@ZB0MB@8MZ8780@2Xi80@ZBZMWMWMWMWMWMWMBWaBZ@WMWMWMWMWM@MWM@MBW8WZW8MBW0@WMWMWM8W0MBMWMW2 :.; , i # Z;SSMXai0B2ZBaB02iXZ0:Z0BZ00W:BB@Z08WZWS@0MWMBMSaBZ,Z@M@M8BBMWM8@0@28aM00;Sa@8WZBZM@MWMWM@M@MWMWWZWBMWMWM@MWMWM@MWM@M8W8M0M0@0MWMWMWMBMWMWMWMWM,,.;,; # Za:ZSS;S80S@ZBW8;8r0;S8WZWZM2X0@ZW8WZW8W8WBMWMBM70BZ:@WM@M0BBMWMBM8WZ08@0@a2XWBMBWZ@BM@MWMWMWMWMWM8WWMWMWMWMWMWMWMWMWMZW8M8M8@WM@MWMWMWMBMBMWMBMZ: ;,i # MX7XrrSS@SBaBB@iWXSrX2@8BZ@027M8WZ@ZW8WW@8WWMWM0WZ@08:MWMWMBW0MBMBMWM0WZW0M8BS0Z@BMB@0M@M@MWMWMWM@MBM0M@MWMWM@MBMWMWM@M0@BM0MZMWMWMWMWM@MWMWMWWrBW8 i # SXr8:XXMa8ZBBMr80X;SrWZ@XB0@i80@B@@@ZWZM0Ba@WMWMZWB@88;MWMWMW@BM@M@MWM@M0@ZW0@ZWZW0MWMBMWMWMWMWM@M@MWMBM@MWMWMWMBMWMWMWMWMB@8WWMWM@MWM@MWM@MBMWM7r2MX: # Sia7S:08BaBBM22BWia;8Z@Z28MZXZ@8W0MWBZBZMZBZMWM@Wa@@W80XM@MWMWMBMWMWMWMWM@MZWZWZW8W8M@MWMWM@M@M@MWMWMWMBMWMWM@M@MWMWMBMWMW@W@ZM0M@MWM@M@M@M@MWM0MBX ZS # 7XX2;XaWZWWM02ZMrZXX0@80S@0Bi@8WZ@WMBMBWBMZBZMWMWWZMWW88ZMWMWMWMWM@M@M@M@MWMWM0W8@8WZ@0MWM@MWMWMWMWMWM@MBMWMWMBMBM@MWMWMWMWM@MWMBM@MWM@MWMWM@M@MWMWM , # 2iarX7@@WWMW0XM8S8X2M8MX00M2S0@8B0M@MB@ZWW@aW8MWM0W8MB@ZW0MWMWMWM@M@M@MWM@MWM@MWMWMZW8W0MWMWM@MWM@MWMWM@MWMWMWMWM@MWMWM@MWM@MWMBMWMWMWM@MWMWMWM@MWMWMX # 7X7S;00MWMWWXWBZZ0;M8W0aZ@BZ7M0WZMBM@M0B8M@@ZW8MBM8WBMWMZWWMWMWM@MWMWM@MWMWMWMWM@MWM0@0MBMWM@MWMWM@MWMWM@MWMWM@MWMWM@MWM@MWMWMWMWMWM@MWM@MWM2aWM@MWM@M # a;2i2000MWWa0BBSMrZ0BZB7@0MXZ0MZWB@WM@M0WBM@WZW0M@M8@WM@M8BBMWMWMWMWM@MWMWMWMWMWMWM@MWMWMB@WMWMWMWM@MWM@M@MWMWMWMWM@MWM@M@MWMWMWMWMWMWMWMWMWMX.;MWM@MW # 22rXSBZMWMZW8M2@ZXZ@8MSZ0@BZSMBB8@8M@MWM0@@MB@ZBWMWMZMWMWM0WBMWM@M@MWM8MWM@M@MWMWMWM@MWMWMBMWMWMWMWMWM@M@MWM@MWMWMWMWM@MWMWM@MWMWMWMWM@M@M@MWMZ. ;7@WM # 07X,MaMWM8WZM0W087M8WWaSM0MSB0MZMWMBMZMWM0MWM0@8@BMWMZM@MWMBMWMWM@MWMWMXW@MWM@MWMBMBMWMWMWMBMBMWMWMWM@MWMWMWMWMWM@M@M@MWMWMWM@M@MBMWMWMWMWMWMWM8, : ii # :r:Z@@WMaWZWW@ZM7WBWZM;80MB8aMWWWMWMBXWM28WM@M8@8WBMW@0M@MWM@MWMWM@MWMWMX2WMWM@MBMWMWMWMWMWMWMBMWMWMWMWMWM@MWMWM@M@MWM@MWM@MWMWMWMWM@MWMWM@MWMWMZ,.r,: # 7 i2MWMX0BB0MZWZZ@@ZMWX2M0Ma00M0MWMWB M@@ BWMWBZM8@BMW@BMWMWMWMWMWMWM@MWMXiXMWMWMWM@M@MWM@MWMWMWMWM@MWMWMWM@MWM@M@M@MWM@MWMWMWMWMWM@M@MWMWMWMWM@MS::7, # ::i8WMXXW@8MBW808M8WWM;[email protected],.W@MW0ZM8W0MWWWMWM@MWMWM@M@MWMWM0i ZWMWMWMWMWM@MWM@MWMWM@M@MWM@MWMWMWM@MWMWMWM@M@MWMWMWM@MWMWMWM@M@M@MWM;iir # i M@MX7XMZMBMZWZMBW0M@XZ@BM8W8M0M@MWZ 2WM.;.Z@MW2aM0M0MWMWMWMBMBMWMWMW@WM@M@a i7MWMWMBM@M@MWMWMWMWMWM@MWMWM@MWM@MWMWM@M@MWMWMWM@MWMWMWMWMWM@[email protected], # aWM;r;ZWWBM0MBMWMZMWM;W0MBW8@WM@[email protected],7 2WM@7SMW@8MBMWMWMWMWM@MWMBZZMWMWM;: X2M@MZ@WM@MWMWMWMWMWMWMWM@MWMWMWMWMWMWMWMWMWM@MWMWMWMWMWMWMWM@MZ@WM:; # ZWMXrrXrM8M0@8MWMWMWM@Sa@0M8@[email protected]@MWrXMW@8MWMWM@M@MWM@MWMWX;MWM@M87 i,ZWM082M@MWMWM@MWM@MWM@M@MWMWMWM@M@MWMWM@MWMWM@MWMWM@MWM@MWM@M MW8i # WM7;;Si2@@WZW@WMWM8M@Mr0B@WM8WWMWMWMi;:iWM r:7.i8MW7:M@@ZMBMWMWM@MWMWMWMW7 SSMWMWB:;,rrB@@X2SM@MWM@MWM@M@MWMWM@M@MWMWM@MWM@MWMWMWMWMWMWMWMWMWM@MWZ MW. # M7;iX;S7MW@:M0M@[email protected] XWr ;.i .rM@X W@M0W8M@M@M@MWM@MWMWS ;ia2MWM8S:r,r7BZZ,;rWWMWMWMWMWM@MWMWMWMWM@MWM@M@MWM@M@[email protected] # 0aiX;2;2@MZ7@MWMWMWMWM70B@WMBMWM@MWMiXS80MWW0MZZi, W@a aWM0@0MWM@M@MBM@[email protected]:7iXX@WWr;.i.XaMaZS@8M@M@MWMWM@M@MWMWMWMWM@M@MWMWM@M@MWM@M@MWM@MWMWM:,8M # M2XiSr2;MWZ;MWMWMWMWMW0SM8M@MBMWMWM@2,r@MiMiZWM@MW@XB@M .BMBWWMWM@MW82MWM@MW8 X;Xi; rS@ZMWMWMWM0M8MWMZMWMWMWM@MWM@M@M@MWMWMWM@MWMWMWMWMWMWMWMWMWMWa :W # 8Z;X;SrXBM2X2MWM@MWM@M8ZB@WMWMBMWMWMX.,M;.:[email protected]@MWMWMW@[email protected]:X7MWWWM@M@MWMW0ar [email protected]@MWMWM@MWMWMWM@MWMWMWM@M@MWM@MWM2@WMWM8: 2 # @XSiX;2XMW. :WM@MWM@M0MSM0MWMWMWMWMWW X@, . B2@WMWM@MWMS8X. WWMWMWM@[email protected] 82MWM@M@M8BX: [email protected]@MWM@MWMWM@M@M@[email protected],;, # 0Z;X78X:XM . M@MWMWMWXBB0@WMWMWMWMWM@:,M , . @ZMWM@M@ZBMX::: rWM@MWMWMWMWZ70WMWMiaZ,.,;WSMWMWMW0Bi i.iWZ,XWMWMWMWMWM@[email protected]@MWZ.: # M2ZSZ.. r@. ,XMWMWM@M B0W0MWM@MWMWM@M;:@S , . W0MWMWW8X Mi,.: ,XMWMWMWMWMZ872SM@M0i:i .2@0M@MB@B2 . , M0r:M@MWMWMWM@MWMWMWMWMWMWM@MWMWMWMWMWM :ZM@MB. # B0r: . , M . ,@MWMWMW.iMZMWMWMWMWM@M@W,WW. , . r;Z2a;. ;;S : : . S8MWM@M@M88rX;2ZM;: . .:aX8S8r: , . iWMX;8M@MWMWMWM@M@MWM@MWMWMWMWMWMWMWMWMWi.:BM@M , # ; . : : .Z: , ZWMWMWM .@WWMWMWM@MWMWM@iXMW; , . . . . .i; : i : . ,;B0M@M@M8BSS:;,i . , . . , . . . ,@M8S,BWM@MWMWMWMWM@MWMWM@MWM@MWM@MWMWMWM.;,iWMWZ # . : : , S,. , MWM@MW: MWMBM@[email protected].. . . . iir : i i i : . XXZZM@M0ZXZXa:7 , . . . . . .,WWMr::XXM@MWMWMWM@MWMWMWMWM@M@MWM@M@MWM@MW7,7.i@MW. # i : : : ,,X , [email protected]@MWM@MWM.. S8M@@a02B2a;i i.i.i i i i , . ;,XaMWMX7iXXBZ0SSiXiX;aS@WMW2 , ria@MWMWMWMWM@M@MWMWMWMWMWM@M@MWW8MWMSiiX 8WMX # , : : : ,r, : .BMWM@X :WMWM@M@MWM0MWMW@ . . XX0ZBZa,: i i i i i i : : , : . raMaS:ii80M@MWMWMWMB8:: i.i:X7MWMWM@MWMWMWMWM@[email protected]:77S8M # i : : : : X,, : ,WMWMX. @WMWMWMWMW@rM@MW2 , , . . . : : i i i i i i i i i : , . i:X,, , : i.i : , , i.r.;ia@MWMWMWMWMWM@M@M@[email protected]: Sa,0 # . : : : , X : . Z@M@Z .,[email protected] : : : : : i i i i i i i i i i.i i : : : : : , , : : : i.i.;,i,X7MWMWM@MWMWMWMWM@MWMWM@M@MWM@M8iaMWB7ri. 0.i # i i : : : : : : . MWMZ. .BM@[email protected];r i i i i i i i i i i i i i i i i.i i i : i i i i.i.i.i.i.i,; riaWM@M@M@MWMWMWMWM@[email protected]:X,.X: # . : : : : , : : .XM@M , :WM@MWMWM@M7. MWZ.r i i i : i i i i i i i i i i i i i.i.i i i i i :.i.i.i.;.;.i:72MWM@MWM@M@M@MWMBMWMWMWM@MWMWMXr:2WMXZ,X 2.. # i : : : : : : : , .WMW. , 0WMWMWMZMWM . B@Z : i i i i i i i i i i i i i i i i i i.i i i i i i i i.i.i.i X:MBMWMWMWM@M@MWMWWWMWMWMWM@MWMWa:S.B@2ari7ar # . : : : : : : : , rWMi. . MWMWM@Z0MW8 . X@8 : i i i i i i i i i i i i i i i i i i.i i.i i i.i i i i.i i;2@X@MWMWM@M@MWMWMrMWMWMWMWMWMWMX7;X,MBZ7r:ZX. # i : : : : : : : : . WWM . ,,M@MWMSX@M@, , .Xa : i i i i i i , : i i i i i i i i i i i.i i.i i i.i i i.:.7ZW,MWMWM@MWMBMWMZi@MWMWM@MWMWMWZ:SrX:@SB,7:@ # . : : : : : : : : , MW, , ,2M@M@M MWMB. : ..; i i i i i i :i: i : i : : i i i i i i i i.i.i : i i.i.i [email protected]@MWMWM@M@0WMW8 MWMWMSMWMWMWMar;S;X;22S:7;0 # i : : : : : : : : ,.. M0, , .@[email protected]. : : i i i i i i i a2. , : , , : i i i i i i i i i i.i i i i i;Zi:ZM@M@MWMWMrMWMS:BMWM8i@MWMWMWW,SrSrX,0XrirS # , : : : : : : : : r .:M,. . ;WMWM,,WMWM . : i i i i i i i : M0r.r:7iXir , i i i i i i : i i.i.i i i :i2i:,MWMWM@MWMaSBMW8 @WMWa B@MWMWM8;rS;S;72a:Xi7 # i : : : : : : : : ,,r .7M , , 2WM@a @WMWM , i i i i i i i i . @W8iSrS;8aBXr i i i i i i i i i i i i :.X .,7@M@[email protected],aM@M:riMWMWMWM,X;S;X;W:7iX, # . : : : : : : : : ri, .;Z : ; 0WM2.XMW8@M . i i i i i i i i , ;0S;XrSrSrS,: i i i i i i i i i i i i ; . 77MWMWMWMWZ,irM@Z @WM8;irXM@MWMWriX;X:W7riXir # i : : : : : : : : ,,X , .,i ,,r M@W 7WM:M@M . i i i i i i i i : ,,Xr2rSi; : i : : i i i i i i i i i.i : 7,[email protected]:;WMS,BMWX:X;;ZM@MWMi7;S:Ba;iXiX, # . : : : : : : : : r;; , , : iii,[email protected]@M . : i i i i i i.i.: , i,; , : i i i i i i i i i i i i i : i;;WMWMWMWM.7iX.M@8 MWM.X;S:[email protected]:Z # i : : : : : : : : ,.X:, : : : 7:,aM ,WM 0WM@M,. : i i i i i i i : : : : : i : i i i i i i i i i i i i ,iriM@MWMWM;;iXirrM2,WM7;;X;X:r@M@MW;,ZZr:7:77Z # . : : : : : : : : :iX , : : .:X,;@r Ma,:MWM@MX. :.i.i i i i : : , , , . . , , , : : i i i i i i i : ,:X 8WMWMWMaiiXiXi;@B MWriX;S;X:7WM@M77ar:X:7aZ . # i : ; : : : : : : , r;7 : : : ii7.2iiWa ,WMWSBM0. , i.i.i.i.i.ZXZXa7arX7aXaXZSZXa7a:: i.i.i i i i : :iXiZWMZMWM@;:XiX;X,00;@a.X;X;X;X,rWM@MX;:XirZ7 . # . ,ir , : : : : : , X;: : : : riX,r:M:r Z@M;:WMWX , : i i i i.i.;,riX,Xi7:;,;,i.ri; i i.i.i.i.i : iiXS0aMX@WM@X:X;X;S;7:0ZM.7;X;X;X;X,;ZMWW 7ir2S , , # : : 2X. : : : : : : , X:, : , : ::X,aa;:;,M@M BW0Za,. : i i i : : , , : , , . , : , : i i i.i i , 7i2ZB;MW:WMWZ.XiXiXiXir;MrriXi7iX;XiX:;ZMW0.;rS , : # . :XZ : : : : : : : ,.S , ; : : ..7XX:7::0MS7 Mia727; , i i i i :.i , . . , r.: i i i i i i : :,7r8Z8ra@i;MWB 7;XiXiXiX,Sai:7i2X8XSiXi7Z7 8Wa a , i . # i , aS. : : : : : : : ,:X ,,r , : , r:7i7.a@Xr;@2,B:S2S , i i i i irWZ020aW8M8X i i.i i i : , ;:SSWaZr;Ba MWM riXi7i7:7:r8a7828SZ;XiX;7aZ.r r7r , : : # , i78 , : : : : : : : ,:r :ir , : , iiX:;:M7;S8ri2Z,77B;, i i i.i :,Xr272;7.: i i.i i i i , 7;Z8BXa;rX0 SWM.r:r:XraXZ208@XarX:r:X;Xir28.7i; . . , , . # : ,.2Si : : : : : : : : :ii :;a,. : : ::X:i@8 Z7;:r0Z7XiZS; , i i i , , , , , i i.i.i.i : :.XSW2a7X,r:X,i@M,rrZS820XarX:X:r:7iX;Si7:XZB.7;: a : , : i # , ;7Z,: : : : : : : : : ::, ;;0i. : , ,,X,Bai:W,7.88Z20S080 . i i i i : i i i i i i i , ii8Z0XZ20XZXa7SZMaaS8X2ir:r:7:7:X;SrS;7..,Za2.7i, M2ZSZXaXa:: # i :.22r:, : : : : , . , : :., 7:ZX, , : , ;X0,rSZ,r:B,riS7ZZW;, : i i i i i i i i i : : 72Wa8a0XZXZX8XX7Mr;ir:X7ZXZS8Xa;7iX:; . iXBXr,X,. 2 , i.rir : # . ;rB.X:: , , . :.ri7:i . , , X:a2; , : , ;rXi7Z7:;XZ:X;Xi7iZ27 : i i.i i.i i i i : ii08WZW22i7:7:7:7,MSiiSX0S2;r.7iX7BXX., .:ZZa:riX .;X . 77ZXS., , # ; ..XZ;:Xir :.riSrS;Xi27a;; . . X:r22 , : , :,X,8SriraZ:X;X;SiS2Z., i i.i.i.;.i : :.2ZM8BZ8;r:X;X;X;X,M2XXBSS.. . , , . ii27800;i.7:: ;22:a20XX . , : # 7i ,:W,;,XX8aZi; : , : : 7;272ii.7,;XB,, : : , ri@iX:r20;7;X;X;X70X; , i i i : : rXWaZ;Xr7:XiX;S;XiX;MBZXX.. ,.: i i : : . :,7;Z2Z:, Sa8XZ;i . , , : . # BXr.iZZX0Sa:: , i i i.i : , i:X72S8XXi07, : i : ,7B:XirXWSXiX;X;S;ZaZ;; , , ,.77B807XiXiX;X;XiX;2S8a8X7 . .:X i.i i : i i : , . ;iXXMWa.. , , , : : : # .S8ZX877 . , : : : i i i :.i : , iiSXZ70Z7 . : i .7X,S;7iZZ0rXi;.7;SSBZ0XaX8aBa8XXiXrS;X;X;S7820XS,i . : ,rZ.i.i.: i.r,;.: , : : , :.aXSi7.: . : : : , # 8rSii . : : , i.;.i , i i a8i i.i : , ri20Mi, , : ,r; ;:7:XXWZZi; :.riXXZSZXa;XiX;SrSrSiS2Baa;; . : : : iSS i.;.i;2;XiSr27a;7.: : : , ,.riS7arX,: , : # ,. . , , :,XraX27ZXZrr.i i.WWi i.i.i : , :r8XarS:i :7X . : i.2Z@2X.: i.riX;Sr2rSrSr2r2rZZX,: : i : i.;,2BZri.;.i,X.;.;.i.;,Xra72ir,; : i : :.riXr2;X:, # : :.riX7arS:; , , :.X;S:i.: ZZX.: i i.i.i , i,ri2X2 ,i2;; . , :i080:, ;.i.;:Xr2727272iSai i i : i,7;aSB0a,i i.;.i riXr27a7Si;.;:7iXrSii.i.i.i : :.;iSi # ,7a7Sir , ;iXrSi7,i : ;.; i ir8XX.: : i.i.i.i.i :XZ , rraii : . iXWSr i.;.i.i,r:7i7.;S; i i,7iX;aa@aai: :.;.;.;.;.i i.;,r:7:r:; : i.;.i.;.;.i.i.i i , # i i , , r;aX2;7,i i i i ;.i.;.: 7X0SS:r,;.;.i.;.;.:2X i :.SXS,: : . 2ZZ:i i.;.i.i i ;a7 :.X;XrZ2Baa:i i.;.;.;.;.;.;.;.i.i i i i.i.i.i.i.;.;.i.i.i.;.; # .. i,r;SrX:; i : i i i : :.;.;.; :.S2W2arSrSir.i.;.iZ; i i i:2XS.:.i :iZ2ai; i.i.i Xar i:2X0ZWaa:: i.;.;,r.;.;.i i i.;.;.;.;.;.;.;.;.;.;.;.;.;.;,;.;,i # ; r:r:;.: i i.;.i XSS;r:r,i i.;.;.; :,ZaB2Z7272:i.;.7Br :.;.i irZr; :.: ;;ZS8XS;r:8Si i;BZ8XX,: i.;,;.;.i i i.i ;:7:;.r,;.;,i i.i i : i.i.;.;.;.;.;,; # .,.i : : i.i.;.i.i,08WZ2i7;X:i i.;.;.i i:SXB2Sra:i,r S0X,i ;.;.: XXZ:i i : i,7iX2W;: ;r@Sr : ;.;,;.i i.r:7:7:XXWZ0X2Si,;,r,;iS;aXZr2rX:r.i.;,;.;.;.;:i # i i i,r,i i.;.;,;.i 2@M@MaSiXi7:; i.;.;.i :.SZara:i,; Z0Si; ;.i.; :iaXai; : , 7S2 i r7M;:.;,r,;.i.;:X;S;X;aaM@MWM8aZS.;,r,;,7ir,r:ri7;Sr277.;,r,;,;,r. # 7Xr27Sr2Xa,;.;,;.;,i 2@MWMWM2SiX;Si;.i.;.;,; ;8Zra:;,r aZ2;X,i.i.;.i iiaXZ7XrZXr i.7XMi:.r,r.i,7;S;S;XrZZMWMWMWMWMS; ;,;,;.;.i,7iX;S;X:r,;,;,;,r,r,r:i # ; i i.i :i7.;.;.;,;.i ;8MWMWMWMSXiXrS;7,;,r:;.;Z0r2.;:r 7ZZ;2ir.i.;.;.i i,rXM,i.;,Sa@ii,r,;.r;arXi22@WM@MWMWMWMX7 ,.r,;,;,;,;,;,;.;,r:r,;,r,r,;,r,r,r # :;;SrXir.i.;,;,r,r,;.i .;@@MWMWMWMSSiS72;;.r,r.i2@7S,r,r.;88iSrX:;.;.;,;,; 0,;,;:Z0B,i:r:r.77a;2aMWM@MWM@MaS,: . i.;,;.;.;,r,;,r,;,;,;,;,r,;,r,r,;,r,i # 7.r,i.;.;,;,;,;,;,;,;,;., :;@WM@M@MWW;7rZr;.r,r,:r@2X,r:7.iZZiXr2rXir.i.; X2i:;,0Ba ;:7ir.XXSiB@MWMWMZ2,: , :.;.;.i.i.;.i i.;,r:r,r,r,r,;,;,r,;,r,r,r. # ,.i.;,;,;,;.;.i.;,r,r,r,; , ;X@[email protected]:7:i:WaS,r:r.;@07X;Sr272;7,iX8.;:@87.r:7:;,SXSXMWMWMWB . i.;,;,;.;,r:XiXiX7Z;Sr;,r:r,r:r,r:r:r,r,r:r:r:; # ; ;,;,r,;.i.;.i i.i ;,r:r:r,; , X8MWMWMWai2XX,r:7:;.082,r:r,WX@8aiX;S7272iW2::@2i,7:r:;:arSZM@MBMWX i,r:r,;.riSrS;X;aSBZ@a8X7,r:r:r,r,r,r:r:r:r:r:r:7.| # :i,;,;,;,;72XWZ077:7.; ;,r,r,;,; ,:MWMWMWWr2XX.r:7:r.Z0S,7:;0S;88BXXiS;SrXaZ,W;;:7i7,r;a70WM@M@MWi r:7:r,riS72r22BBMWM@MrBS;:7,r,r:r:r:r:r:r,r,7,r:r:;| # 7 r,;,r,r.S72rXXMWZ;X;7:;.;.r:r:r,: 8WM@MWMSSXS,r:7i7 007:7.07S;XXW807X;2;Z00i;:7ir:XXZ2MWM@M@M0: 7ir:;,7rZ722M@MWM@MWMW0;i,7:7:r:r:r,;,;,r,;,;,r:7:7.| # :i,;,r,r,;:WaSiMWMWMZarS;S;Xir,r:7:r 7WMWMWM0a72:ri7ir:M7riiZ2i2rSraa@80XXXM:r;XiriaX8WM@MWMWMS:,7i7,r;ZX2r0WMWMWMWMWB7i ;:7i7:7i7:r,r:X;Sr27S;X:r,r:;| # ''' x = input();n = int(input()) if n > len(x):print("impossible") else:x = set(x);print(abs(n - len(x)))
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input Specification: First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). Output Specification: Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. Demo Input: ['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n'] Demo Output: ['0\n', '1\n', 'impossible\n'] Note: In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
```python """ ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ███ █████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ████ ████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ ██ ██ ██ ██ ██ ██ ███ █████████████████████████████████████ ██████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████████████████████████████████████ ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ ███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ """ # '''______________________________________________________________________________________________''' # ''' # 2i2r2X0S@aZB87Ma7XWaB8a2WaBaBZ0BBi80SaWWM@B;S7@;ZZ7i8B@7B8WZB0MWMWMWM8@ZWZWZWZWaSXWBMWMWMWM8WWMBM8@ZBZW8WX0080@8W8MWM8B8@8W0aZM0WBMZWWMWMWM8@0WWX r,7, # 2XrS;S702Z8Z:WaX;B202Z;B2020202WarXW;ZZMWM8Si7S2iMaX,X2B722B2BZW8MWMWMWM0MaB202BaZX8Z@BM@MWMBM0MWM@MZ0aBZBXZaWZBZW8@BMZBZ@ZBaZZWZB0MZBBM@MWM8WZ@W; : , # WXSiSiZW0a@;BZS;WZBZ0i08BaBa0aB8W;B08XW@MWMZXrS2XZM00rXr0XSXBZB2B0@BM@MWMWM0WZWZW8WaWZBBMWMWMWM0@0M@MBMZBZ@ZB8WZWZW8@WMZW8M0@Z08WZW0M8MSrBM@MWMBM@a i. # 02ir.,S@Z0X8BaiBaBZW;2ZB28ZWZWZ08SZWZZaWBMB@727S;2@M8WaZ;SrX;aa0X8Z@Z@BMWMWMWM@MBM8BZWZBZW8M@MWMWMZMWM@MWM8@8WZWZWZW8@WM8WZMB@8@8W0M0MWMr,.WWM@MWMWB . # Z:;.:.BBX;808iBZ8aW77Z@ZZZBZBZ8XMr0ZWXBZM0M0Bi0rXi@WMa@B@Sa;7i2SZX2XW0@0MBM@M@MWMWM8WZBaBa08MWMWMWMBM0MWMWMW@aBZW8W8@0M@M8W8MW@ZWZMB@0MWMS. ir@@MWM@@ # Xr.i ZWBiZWB:08BaWX7XW82S@Z00@;BBaS@80SW0@8M8Z7B;X7MWMZB0MZWS2i2a0XX:Z0M0B8MBM@MWMWMWMBMZBZW0@BM@MWMWMBMWMWM8W8W8@8@BM@MZWZM@M0W8@0@0M@MB, . iXMWMWM # Zir,XW0iZZM;ZZBZWZXi08ZrWZWaMaS8MSZ8WZaZWBMB@ZSa0i72MWMZB0M0@0BXSXWZai7X@0WaBZMWMWMWM@MWMWM0M8WZMWMWM@M@MWMWMWMWM8W8@8WZ@W@8W0MWM@Wa@8MBMWMWr i , rXMW # rXX20W:XaMSX8W2W02i28ZiW8Wa@0S7M8BXMBWX8ZMWMB@aS88:S0MW@ZB0MB@8MZ8780@2Xi80@ZBZMWMWMWMWMWMWMBWaBZ@WMWMWMWMWM@MWM@MBW8WZW8MBW0@WMWMWM8W0MBMWMW2 :.; , i # Z;SSMXai0B2ZBaB02iXZ0:Z0BZ00W:BB@Z08WZWS@0MWMBMSaBZ,Z@M@M8BBMWM8@0@28aM00;Sa@8WZBZM@MWMWM@M@MWMWWZWBMWMWM@MWMWM@MWM@M8W8M0M0@0MWMWMWMBMWMWMWMWM,,.;,; # Za:ZSS;S80S@ZBW8;8r0;S8WZWZM2X0@ZW8WZW8W8WBMWMBM70BZ:@WM@M0BBMWMBM8WZ08@0@a2XWBMBWZ@BM@MWMWMWMWMWM8WWMWMWMWMWMWMWMWMWMZW8M8M8@WM@MWMWMWMBMBMWMBMZ: ;,i # MX7XrrSS@SBaBB@iWXSrX2@8BZ@027M8WZ@ZW8WW@8WWMWM0WZ@08:MWMWMBW0MBMBMWM0WZW0M8BS0Z@BMB@0M@M@MWMWMWM@MBM0M@MWMWM@MBMWMWM@M0@BM0MZMWMWMWMWM@MWMWMWWrBW8 i # SXr8:XXMa8ZBBMr80X;SrWZ@XB0@i80@B@@@ZWZM0Ba@WMWMZWB@88;MWMWMW@BM@M@MWM@M0@ZW0@ZWZW0MWMBMWMWMWMWM@M@MWMBM@MWMWMWMBMWMWMWMWMB@8WWMWM@MWM@MWM@MBMWM7r2MX: # Sia7S:08BaBBM22BWia;8Z@Z28MZXZ@8W0MWBZBZMZBZMWM@Wa@@W80XM@MWMWMBMWMWMWMWM@MZWZWZW8W8M@MWMWM@M@M@MWMWMWMBMWMWM@M@MWMWMBMWMW@W@ZM0M@MWM@M@M@M@MWM0MBX ZS # 7XX2;XaWZWWM02ZMrZXX0@80S@0Bi@8WZ@WMBMBWBMZBZMWMWWZMWW88ZMWMWMWMWM@M@M@M@MWMWM0W8@8WZ@0MWM@MWMWMWMWMWM@MBMWMWMBMBM@MWMWMWMWM@MWMBM@MWM@MWMWM@M@MWMWM , # 2iarX7@@WWMW0XM8S8X2M8MX00M2S0@8B0M@MB@ZWW@aW8MWM0W8MB@ZW0MWMWMWM@M@M@MWM@MWM@MWMWMZW8W0MWMWM@MWM@MWMWM@MWMWMWMWM@MWMWM@MWM@MWMBMWMWMWM@MWMWMWM@MWMWMX # 7X7S;00MWMWWXWBZZ0;M8W0aZ@BZ7M0WZMBM@M0B8M@@ZW8MBM8WBMWMZWWMWMWM@MWMWM@MWMWMWMWM@MWM0@0MBMWM@MWMWM@MWMWM@MWMWM@MWMWM@MWM@MWMWMWMWMWM@MWM@MWM2aWM@MWM@M # a;2i2000MWWa0BBSMrZ0BZB7@0MXZ0MZWB@WM@M0WBM@WZW0M@M8@WM@M8BBMWMWMWMWM@MWMWMWMWMWMWM@MWMWMB@WMWMWMWM@MWM@M@MWMWMWMWM@MWM@M@MWMWMWMWMWMWMWMWMWMX.;MWM@MW # 22rXSBZMWMZW8M2@ZXZ@8MSZ0@BZSMBB8@8M@MWM0@@MB@ZBWMWMZMWMWM0WBMWM@M@MWM8MWM@M@MWMWMWM@MWMWMBMWMWMWMWMWM@M@MWM@MWMWMWMWM@MWMWM@MWMWMWMWM@M@M@MWMZ. ;7@WM # 07X,MaMWM8WZM0W087M8WWaSM0MSB0MZMWMBMZMWM0MWM0@8@BMWMZM@MWMBMWMWM@MWMWMXW@MWM@MWMBMBMWMWMWMBMBMWMWMWM@MWMWMWMWMWM@M@M@MWMWMWM@M@MBMWMWMWMWMWMWM8, : ii # :r:Z@@WMaWZWW@ZM7WBWZM;80MB8aMWWWMWMBXWM28WM@M8@8WBMW@0M@MWM@MWMWM@MWMWMX2WMWM@MBMWMWMWMWMWMWMBMWMWMWMWMWM@MWMWM@M@MWM@MWM@MWMWMWMWM@MWMWM@MWMWMZ,.r,: # 7 i2MWMX0BB0MZWZZ@@ZMWX2M0Ma00M0MWMWB M@@ BWMWBZM8@BMW@BMWMWMWMWMWMWM@MWMXiXMWMWMWM@M@MWM@MWMWMWMWM@MWMWMWM@MWM@M@M@MWM@MWMWMWMWMWM@M@MWMWMWMWM@MS::7, # ::i8WMXXW@8MBW808M8WWM;[email protected],.W@MW0ZM8W0MWWWMWM@MWMWM@M@MWMWM0i ZWMWMWMWMWM@MWM@MWMWM@M@MWM@MWMWMWM@MWMWMWM@M@MWMWMWM@MWMWMWM@M@M@MWM;iir # i M@MX7XMZMBMZWZMBW0M@XZ@BM8W8M0M@MWZ 2WM.;.Z@MW2aM0M0MWMWMWMBMBMWMWMW@WM@M@a i7MWMWMBM@M@MWMWMWMWMWM@MWMWM@MWM@MWMWM@M@MWMWMWM@MWMWMWMWMWM@[email protected], # aWM;r;ZWWBM0MBMWMZMWM;W0MBW8@WM@[email protected],7 2WM@7SMW@8MBMWMWMWMWM@MWMBZZMWMWM;: X2M@MZ@WM@MWMWMWMWMWMWMWM@MWMWMWMWMWMWMWMWMWM@MWMWMWMWMWMWMWM@MZ@WM:; # ZWMXrrXrM8M0@8MWMWMWM@Sa@0M8@[email protected]@MWrXMW@8MWMWM@M@MWM@MWMWX;MWM@M87 i,ZWM082M@MWMWM@MWM@MWM@M@MWMWMWM@M@MWMWM@MWMWM@MWMWM@MWM@MWM@M MW8i # WM7;;Si2@@WZW@WMWM8M@Mr0B@WM8WWMWMWMi;:iWM r:7.i8MW7:M@@ZMBMWMWM@MWMWMWMW7 SSMWMWB:;,rrB@@X2SM@MWM@MWM@M@MWMWM@M@MWMWM@MWM@MWMWMWMWMWMWMWMWMWM@MWZ MW. # M7;iX;S7MW@:M0M@[email protected] XWr ;.i .rM@X W@M0W8M@M@M@MWM@MWMWS ;ia2MWM8S:r,r7BZZ,;rWWMWMWMWMWM@MWMWMWMWM@MWM@M@MWM@M@[email protected] # 0aiX;2;2@MZ7@MWMWMWMWM70B@WMBMWM@MWMiXS80MWW0MZZi, W@a aWM0@0MWM@M@MBM@[email protected]:7iXX@WWr;.i.XaMaZS@8M@M@MWMWM@M@MWMWMWMWM@M@MWMWM@M@MWM@M@MWM@MWMWM:,8M # M2XiSr2;MWZ;MWMWMWMWMW0SM8M@MBMWMWM@2,r@MiMiZWM@MW@XB@M .BMBWWMWM@MW82MWM@MW8 X;Xi; rS@ZMWMWMWM0M8MWMZMWMWMWM@MWM@M@M@MWMWMWM@MWMWMWMWMWMWMWMWMWMWa :W # 8Z;X;SrXBM2X2MWM@MWM@M8ZB@WMWMBMWMWMX.,M;.:[email protected]@MWMWMW@[email protected]:X7MWWWM@M@MWMW0ar [email protected]@MWMWM@MWMWMWM@MWMWMWM@M@MWM@MWM2@WMWM8: 2 # @XSiX;2XMW. :WM@MWM@M0MSM0MWMWMWMWMWW X@, . B2@WMWM@MWMS8X. WWMWMWM@[email protected] 82MWM@M@M8BX: [email protected]@MWM@MWMWM@M@M@[email protected],;, # 0Z;X78X:XM . M@MWMWMWXBB0@WMWMWMWMWM@:,M , . @ZMWM@M@ZBMX::: rWM@MWMWMWMWZ70WMWMiaZ,.,;WSMWMWMW0Bi i.iWZ,XWMWMWMWMWM@[email protected]@MWZ.: # M2ZSZ.. r@. ,XMWMWM@M B0W0MWM@MWMWM@M;:@S , . W0MWMWW8X Mi,.: ,XMWMWMWMWMZ872SM@M0i:i .2@0M@MB@B2 . , M0r:M@MWMWMWM@MWMWMWMWMWMWM@MWMWMWMWMWM :ZM@MB. # B0r: . , M . ,@MWMWMW.iMZMWMWMWMWM@M@W,WW. , . r;Z2a;. ;;S : : . S8MWM@M@M88rX;2ZM;: . .:aX8S8r: , . iWMX;8M@MWMWMWM@M@MWM@MWMWMWMWMWMWMWMWMWi.:BM@M , # ; . : : .Z: , ZWMWMWM .@WWMWMWM@MWMWM@iXMW; , . . . . .i; : i : . ,;B0M@M@M8BSS:;,i . , . . , . . . ,@M8S,BWM@MWMWMWMWM@MWMWM@MWM@MWM@MWMWMWM.;,iWMWZ # . : : , S,. , MWM@MW: MWMBM@[email protected].. . . . iir : i i i : . XXZZM@M0ZXZXa:7 , . . . . . .,WWMr::XXM@MWMWMWM@MWMWMWMWM@M@MWM@M@MWM@MW7,7.i@MW. # i : : : ,,X , [email protected]@MWM@MWM.. S8M@@a02B2a;i i.i.i i i i , . ;,XaMWMX7iXXBZ0SSiXiX;aS@WMW2 , ria@MWMWMWMWM@M@MWMWMWMWMWM@M@MWW8MWMSiiX 8WMX # , : : : ,r, : .BMWM@X :WMWM@M@MWM0MWMW@ . . XX0ZBZa,: i i i i i i : : , : . raMaS:ii80M@MWMWMWMB8:: i.i:X7MWMWM@MWMWMWMWM@[email protected]:77S8M # i : : : : X,, : ,WMWMX. @WMWMWMWMW@rM@MW2 , , . . . : : i i i i i i i i i : , . i:X,, , : i.i : , , i.r.;ia@MWMWMWMWMWM@M@M@[email protected]: Sa,0 # . : : : , X : . Z@M@Z .,[email protected] : : : : : i i i i i i i i i i.i i : : : : : , , : : : i.i.;,i,X7MWMWM@MWMWMWMWM@MWMWM@M@MWM@M8iaMWB7ri. 0.i # i i : : : : : : . MWMZ. .BM@[email protected];r i i i i i i i i i i i i i i i i.i i i : i i i i.i.i.i.i.i,; riaWM@M@M@MWMWMWMWM@[email protected]:X,.X: # . : : : : , : : .XM@M , :WM@MWMWM@M7. MWZ.r i i i : i i i i i i i i i i i i i.i.i i i i i :.i.i.i.;.;.i:72MWM@MWM@M@M@MWMBMWMWMWM@MWMWMXr:2WMXZ,X 2.. # i : : : : : : : , .WMW. , 0WMWMWMZMWM . B@Z : i i i i i i i i i i i i i i i i i i.i i i i i i i i.i.i.i X:MBMWMWMWM@M@MWMWWWMWMWMWM@MWMWa:S.B@2ari7ar # . : : : : : : : , rWMi. . MWMWM@Z0MW8 . X@8 : i i i i i i i i i i i i i i i i i i.i i.i i i.i i i i.i i;2@X@MWMWM@M@MWMWMrMWMWMWMWMWMWMX7;X,MBZ7r:ZX. # i : : : : : : : : . WWM . ,,M@MWMSX@M@, , .Xa : i i i i i i , : i i i i i i i i i i i.i i.i i i.i i i.:.7ZW,MWMWM@MWMBMWMZi@MWMWM@MWMWMWZ:SrX:@SB,7:@ # . : : : : : : : : , MW, , ,2M@M@M MWMB. : ..; i i i i i i :i: i : i : : i i i i i i i i.i.i : i i.i.i [email protected]@MWMWM@M@0WMW8 MWMWMSMWMWMWMar;S;X;22S:7;0 # i : : : : : : : : ,.. M0, , .@[email protected]. : : i i i i i i i a2. , : , , : i i i i i i i i i i.i i i i i;Zi:ZM@M@MWMWMrMWMS:BMWM8i@MWMWMWW,SrSrX,0XrirS # , : : : : : : : : r .:M,. . ;WMWM,,WMWM . : i i i i i i i : M0r.r:7iXir , i i i i i i : i i.i.i i i :i2i:,MWMWM@MWMaSBMW8 @WMWa B@MWMWM8;rS;S;72a:Xi7 # i : : : : : : : : ,,r .7M , , 2WM@a @WMWM , i i i i i i i i . @W8iSrS;8aBXr i i i i i i i i i i i i :.X .,7@M@[email protected],aM@M:riMWMWMWM,X;S;X;W:7iX, # . : : : : : : : : ri, .;Z : ; 0WM2.XMW8@M . i i i i i i i i , ;0S;XrSrSrS,: i i i i i i i i i i i i ; . 77MWMWMWMWZ,irM@Z @WM8;irXM@MWMWriX;X:W7riXir # i : : : : : : : : ,,X , .,i ,,r M@W 7WM:M@M . i i i i i i i i : ,,Xr2rSi; : i : : i i i i i i i i i.i : 7,[email protected]:;WMS,BMWX:X;;ZM@MWMi7;S:Ba;iXiX, # . : : : : : : : : r;; , , : iii,[email protected]@M . : i i i i i i.i.: , i,; , : i i i i i i i i i i i i i : i;;WMWMWMWM.7iX.M@8 MWM.X;S:[email protected]:Z # i : : : : : : : : ,.X:, : : : 7:,aM ,WM 0WM@M,. : i i i i i i i : : : : : i : i i i i i i i i i i i i ,iriM@MWMWM;;iXirrM2,WM7;;X;X:r@M@MW;,ZZr:7:77Z # . : : : : : : : : :iX , : : .:X,;@r Ma,:MWM@MX. :.i.i i i i : : , , , . . , , , : : i i i i i i i : ,:X 8WMWMWMaiiXiXi;@B MWriX;S;X:7WM@M77ar:X:7aZ . # i : ; : : : : : : , r;7 : : : ii7.2iiWa ,WMWSBM0. , i.i.i.i.i.ZXZXa7arX7aXaXZSZXa7a:: i.i.i i i i : :iXiZWMZMWM@;:XiX;X,00;@a.X;X;X;X,rWM@MX;:XirZ7 . # . ,ir , : : : : : , X;: : : : riX,r:M:r Z@M;:WMWX , : i i i i.i.;,riX,Xi7:;,;,i.ri; i i.i.i.i.i : iiXS0aMX@WM@X:X;X;S;7:0ZM.7;X;X;X;X,;ZMWW 7ir2S , , # : : 2X. : : : : : : , X:, : , : ::X,aa;:;,M@M BW0Za,. : i i i : : , , : , , . , : , : i i i.i i , 7i2ZB;MW:WMWZ.XiXiXiXir;MrriXi7iX;XiX:;ZMW0.;rS , : # . :XZ : : : : : : : ,.S , ; : : ..7XX:7::0MS7 Mia727; , i i i i :.i , . . , r.: i i i i i i : :,7r8Z8ra@i;MWB 7;XiXiXiX,Sai:7i2X8XSiXi7Z7 8Wa a , i . # i , aS. : : : : : : : ,:X ,,r , : , r:7i7.a@Xr;@2,B:S2S , i i i i irWZ020aW8M8X i i.i i i : , ;:SSWaZr;Ba MWM riXi7i7:7:r8a7828SZ;XiX;7aZ.r r7r , : : # , i78 , : : : : : : : ,:r :ir , : , iiX:;:M7;S8ri2Z,77B;, i i i.i :,Xr272;7.: i i.i i i i , 7;Z8BXa;rX0 SWM.r:r:XraXZ208@XarX:r:X;Xir28.7i; . . , , . # : ,.2Si : : : : : : : : :ii :;a,. : : ::X:i@8 Z7;:r0Z7XiZS; , i i i , , , , , i i.i.i.i : :.XSW2a7X,r:X,i@M,rrZS820XarX:X:r:7iX;Si7:XZB.7;: a : , : i # , ;7Z,: : : : : : : : : ::, ;;0i. : , ,,X,Bai:W,7.88Z20S080 . i i i i : i i i i i i i , ii8Z0XZ20XZXa7SZMaaS8X2ir:r:7:7:X;SrS;7..,Za2.7i, M2ZSZXaXa:: # i :.22r:, : : : : , . , : :., 7:ZX, , : , ;X0,rSZ,r:B,riS7ZZW;, : i i i i i i i i i : : 72Wa8a0XZXZX8XX7Mr;ir:X7ZXZS8Xa;7iX:; . iXBXr,X,. 2 , i.rir : # . ;rB.X:: , , . :.ri7:i . , , X:a2; , : , ;rXi7Z7:;XZ:X;Xi7iZ27 : i i.i i.i i i i : ii08WZW22i7:7:7:7,MSiiSX0S2;r.7iX7BXX., .:ZZa:riX .;X . 77ZXS., , # ; ..XZ;:Xir :.riSrS;Xi27a;; . . X:r22 , : , :,X,8SriraZ:X;X;SiS2Z., i i.i.i.;.i : :.2ZM8BZ8;r:X;X;X;X,M2XXBSS.. . , , . ii27800;i.7:: ;22:a20XX . , : # 7i ,:W,;,XX8aZi; : , : : 7;272ii.7,;XB,, : : , ri@iX:r20;7;X;X;X70X; , i i i : : rXWaZ;Xr7:XiX;S;XiX;MBZXX.. ,.: i i : : . :,7;Z2Z:, Sa8XZ;i . , , : . # BXr.iZZX0Sa:: , i i i.i : , i:X72S8XXi07, : i : ,7B:XirXWSXiX;X;S;ZaZ;; , , ,.77B807XiXiX;X;XiX;2S8a8X7 . .:X i.i i : i i : , . ;iXXMWa.. , , , : : : # .S8ZX877 . , : : : i i i :.i : , iiSXZ70Z7 . : i .7X,S;7iZZ0rXi;.7;SSBZ0XaX8aBa8XXiXrS;X;X;S7820XS,i . : ,rZ.i.i.: i.r,;.: , : : , :.aXSi7.: . : : : , # 8rSii . : : , i.;.i , i i a8i i.i : , ri20Mi, , : ,r; ;:7:XXWZZi; :.riXXZSZXa;XiX;SrSrSiS2Baa;; . : : : iSS i.;.i;2;XiSr27a;7.: : : , ,.riS7arX,: , : # ,. . , , :,XraX27ZXZrr.i i.WWi i.i.i : , :r8XarS:i :7X . : i.2Z@2X.: i.riX;Sr2rSrSr2r2rZZX,: : i : i.;,2BZri.;.i,X.;.;.i.;,Xra72ir,; : i : :.riXr2;X:, # : :.riX7arS:; , , :.X;S:i.: ZZX.: i i.i.i , i,ri2X2 ,i2;; . , :i080:, ;.i.;:Xr2727272iSai i i : i,7;aSB0a,i i.;.i riXr27a7Si;.;:7iXrSii.i.i.i : :.;iSi # ,7a7Sir , ;iXrSi7,i : ;.; i ir8XX.: : i.i.i.i.i :XZ , rraii : . iXWSr i.;.i.i,r:7i7.;S; i i,7iX;aa@aai: :.;.;.;.;.i i.;,r:7:r:; : i.;.i.;.;.i.i.i i , # i i , , r;aX2;7,i i i i ;.i.;.: 7X0SS:r,;.;.i.;.;.:2X i :.SXS,: : . 2ZZ:i i.;.i.i i ;a7 :.X;XrZ2Baa:i i.;.;.;.;.;.;.;.i.i i i i.i.i.i.i.;.;.i.i.i.;.; # .. i,r;SrX:; i : i i i : :.;.;.; :.S2W2arSrSir.i.;.iZ; i i i:2XS.:.i :iZ2ai; i.i.i Xar i:2X0ZWaa:: i.;.;,r.;.;.i i i.;.;.;.;.;.;.;.;.;.;.;.;.;.;,;.;,i # ; r:r:;.: i i.;.i XSS;r:r,i i.;.;.; :,ZaB2Z7272:i.;.7Br :.;.i irZr; :.: ;;ZS8XS;r:8Si i;BZ8XX,: i.;,;.;.i i i.i ;:7:;.r,;.;,i i.i i : i.i.;.;.;.;.;,; # .,.i : : i.i.;.i.i,08WZ2i7;X:i i.;.;.i i:SXB2Sra:i,r S0X,i ;.;.: XXZ:i i : i,7iX2W;: ;r@Sr : ;.;,;.i i.r:7:7:XXWZ0X2Si,;,r,;iS;aXZr2rX:r.i.;,;.;.;.;:i # i i i,r,i i.;.;,;.i 2@M@MaSiXi7:; i.;.;.i :.SZara:i,; Z0Si; ;.i.; :iaXai; : , 7S2 i r7M;:.;,r,;.i.;:X;S;X;aaM@MWM8aZS.;,r,;,7ir,r:ri7;Sr277.;,r,;,;,r. # 7Xr27Sr2Xa,;.;,;.;,i 2@MWMWM2SiX;Si;.i.;.;,; ;8Zra:;,r aZ2;X,i.i.;.i iiaXZ7XrZXr i.7XMi:.r,r.i,7;S;S;XrZZMWMWMWMWMS; ;,;,;.;.i,7iX;S;X:r,;,;,;,r,r,r:i # ; i i.i :i7.;.;.;,;.i ;8MWMWMWMSXiXrS;7,;,r:;.;Z0r2.;:r 7ZZ;2ir.i.;.;.i i,rXM,i.;,Sa@ii,r,;.r;arXi22@WM@MWMWMWMX7 ,.r,;,;,;,;,;,;.;,r:r,;,r,r,;,r,r,r # :;;SrXir.i.;,;,r,r,;.i .;@@MWMWMWMSSiS72;;.r,r.i2@7S,r,r.;88iSrX:;.;.;,;,; 0,;,;:Z0B,i:r:r.77a;2aMWM@MWM@MaS,: . i.;,;.;.;,r,;,r,;,;,;,;,r,;,r,r,;,r,i # 7.r,i.;.;,;,;,;,;,;,;,;., :;@WM@M@MWW;7rZr;.r,r,:r@2X,r:7.iZZiXr2rXir.i.; X2i:;,0Ba ;:7ir.XXSiB@MWMWMZ2,: , :.;.;.i.i.;.i i.;,r:r,r,r,r,;,;,r,;,r,r,r. # ,.i.;,;,;,;.;.i.;,r,r,r,; , ;X@[email protected]:7:i:WaS,r:r.;@07X;Sr272;7,iX8.;:@87.r:7:;,SXSXMWMWMWB . i.;,;,;.;,r:XiXiX7Z;Sr;,r:r,r:r,r:r:r,r,r:r:r:; # ; ;,;,r,;.i.;.i i.i ;,r:r:r,; , X8MWMWMWai2XX,r:7:;.082,r:r,WX@8aiX;S7272iW2::@2i,7:r:;:arSZM@MBMWX i,r:r,;.riSrS;X;aSBZ@a8X7,r:r:r,r,r,r:r:r:r:r:r:7.| # :i,;,;,;,;72XWZ077:7.; ;,r,r,;,; ,:MWMWMWWr2XX.r:7:r.Z0S,7:;0S;88BXXiS;SrXaZ,W;;:7i7,r;a70WM@M@MWi r:7:r,riS72r22BBMWM@MrBS;:7,r,r:r:r:r:r:r,r,7,r:r:;| # 7 r,;,r,r.S72rXXMWZ;X;7:;.;.r:r:r,: 8WM@MWMSSXS,r:7i7 007:7.07S;XXW807X;2;Z00i;:7ir:XXZ2MWM@M@M0: 7ir:;,7rZ722M@MWM@MWMW0;i,7:7:r:r:r,;,;,r,;,;,r:7:7.| # :i,;,r,r,;:WaSiMWMWMZarS;S;Xir,r:7:r 7WMWMWM0a72:ri7ir:M7riiZ2i2rSraa@80XXXM:r;XiriaX8WM@MWMWMS:,7i7,r;ZX2r0WMWMWMWMWB7i ;:7i7:7i7:r,r:X;Sr27S;X:r,r:;| # ''' x = input();n = int(input()) if n > len(x):print("impossible") else:x = set(x);print(abs(n - len(x))) ```
0
424
A
Squats
PROGRAMMING
900
[ "implementation" ]
null
null
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting.
In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
[ "4\nxxXx\n", "2\nXX\n", "6\nxXXxXx\n" ]
[ "1\nXxXx\n", "1\nxX\n", "0\nxXXxXx\n" ]
none
500
[ { "input": "4\nxxXx", "output": "1\nXxXx" }, { "input": "2\nXX", "output": "1\nxX" }, { "input": "6\nxXXxXx", "output": "0\nxXXxXx" }, { "input": "4\nxXXX", "output": "1\nxxXX" }, { "input": "2\nXx", "output": "0\nXx" }, { "input": "22\nXXxXXxxXxXxXXXX...
1,594,553,388
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
20,172,800
n = int(input())//2 l1 = list(input()) const = l1.count("x")-l1.count("X") if const<0: const=-const const-=1 while const: const-=1 l1[l1.index("X")]="x" elif const>0: const-=1 while const: const-=1 l1[l1.index("x")]="X" print("".join(l1))
Title: Squats Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. Output Specification: In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Demo Input: ['4\nxxXx\n', '2\nXX\n', '6\nxXXxXx\n'] Demo Output: ['1\nXxXx\n', '1\nxX\n', '0\nxXXxXx\n'] Note: none
```python n = int(input())//2 l1 = list(input()) const = l1.count("x")-l1.count("X") if const<0: const=-const const-=1 while const: const-=1 l1[l1.index("X")]="x" elif const>0: const-=1 while const: const-=1 l1[l1.index("x")]="X" print("".join(l1)) ```
0
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, ...
1,595,591,650
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
6,656,000
s,v1,v2,t1,t2=input().split() time_1=int(t1)+int(s)*int(v1)+int(t1) time_2=int(t2)++int(s)*int(v2)+int(t2) if(time_1<time_2): print("FIRST") elif(time_2<time_1): print("SECOND") else: print("FRIENDSHIP")
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python s,v1,v2,t1,t2=input().split() time_1=int(t1)+int(s)*int(v1)+int(t1) time_2=int(t2)++int(s)*int(v2)+int(t2) if(time_1<time_2): print("FIRST") elif(time_2<time_1): print("SECOND") else: print("FRIENDSHIP") ```
0
401
A
Vanya and Cards
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*.
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value.
Print a single number — the answer to the problem.
[ "3 2\n-1 1 2\n", "2 3\n-2 -2\n" ]
[ "1\n", "2\n" ]
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
500
[ { "input": "3 2\n-1 1 2", "output": "1" }, { "input": "2 3\n-2 -2", "output": "2" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "2 2\n-1 -1", "output": "1" }, { "input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2", "output": "4" }, { "...
1,621,851,844
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
n,x = map(int,input().split()) l = list(map(int,input().split())) s = sum(l) if(s in range(-x,x+1)): print(1) else: count = 0 while(s<0): s+=x count+=1 while(s>0 and s>x): s-=x count+=1 print(count)
Title: Vanya and Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*. Input Specification: The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value. Output Specification: Print a single number — the answer to the problem. Demo Input: ['3 2\n-1 1 2\n', '2 3\n-2 -2\n'] Demo Output: ['1\n', '2\n'] Note: In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
```python n,x = map(int,input().split()) l = list(map(int,input().split())) s = sum(l) if(s in range(-x,x+1)): print(1) else: count = 0 while(s<0): s+=x count+=1 while(s>0 and s>x): s-=x count+=1 print(count) ```
0
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 switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
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,661,157,611
2,147,483,647
PyPy 3-64
OK
TESTS
33
77
0
a=input() a=a.split() a=list(map(int,a)) b=input() b=b.split() b=list(map(int,b)) c=input() c=c.split() c=list(map(int,c)) aa='' bb='' cc='' if (a[0]+b[0]+a[1])%2==0: aa+='1' else: aa+='0' if (a[0]+b[1]+a[1]+a[2])%2==0: aa+='1' else: aa+='0' if (a[2]+b[2]+a[1])%2==0: aa+='1' else: aa+='0' if (a[0]+b[0]+c[0]+b[1])%2==0: bb+='1' else: bb+='0' if (a[1]+b[0]+c[1]+b[1]+b[2])%2==0: bb+='1' else: bb+='0' if (a[2]+b[2]+c[2]+b[1])%2==0: bb+='1' else: bb+='0' if (c[0]+b[0]+c[1])%2==0: cc+='1' else: cc+='0' if (c[0]+b[1]+c[1]+c[2])%2==0: cc+='1' else: cc+='0' if (c[2]+b[2]+c[1])%2==0: cc+='1' else: cc+='0' print(aa) print(bb) print(cc)
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 lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. Input Specification: 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. Output Specification: 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". Demo Input: ['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n'] Demo Output: ['001\n010\n100\n', '010\n011\n100\n'] Note: none
```python a=input() a=a.split() a=list(map(int,a)) b=input() b=b.split() b=list(map(int,b)) c=input() c=c.split() c=list(map(int,c)) aa='' bb='' cc='' if (a[0]+b[0]+a[1])%2==0: aa+='1' else: aa+='0' if (a[0]+b[1]+a[1]+a[2])%2==0: aa+='1' else: aa+='0' if (a[2]+b[2]+a[1])%2==0: aa+='1' else: aa+='0' if (a[0]+b[0]+c[0]+b[1])%2==0: bb+='1' else: bb+='0' if (a[1]+b[0]+c[1]+b[1]+b[2])%2==0: bb+='1' else: bb+='0' if (a[2]+b[2]+c[2]+b[1])%2==0: bb+='1' else: bb+='0' if (c[0]+b[0]+c[1])%2==0: cc+='1' else: cc+='0' if (c[0]+b[1]+c[1]+c[2])%2==0: cc+='1' else: cc+='0' if (c[2]+b[2]+c[1])%2==0: cc+='1' else: cc+='0' print(aa) print(bb) print(cc) ```
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,689,054,805
2,147,483,647
Python 3
OK
TESTS
34
46
307,200
from collections import deque n = int(input()) a = deque([int(i) for i in input().split()]) sereza = 0 dima = 0 turns = 1 while len(a) > 0: if turns % 2 == 1: if a[0] > a[-1]: sereza += a[0] a.popleft() else: sereza += a[-1] a.pop() else: if a[0] > a[-1]: dima += a[0] a.popleft() else: dima += a[-1] a.pop() turns += 1 print(sereza, dima)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python from collections import deque n = int(input()) a = deque([int(i) for i in input().split()]) sereza = 0 dima = 0 turns = 1 while len(a) > 0: if turns % 2 == 1: if a[0] > a[-1]: sereza += a[0] a.popleft() else: sereza += a[-1] a.pop() else: if a[0] > a[-1]: dima += a[0] a.popleft() else: dima += a[-1] a.pop() turns += 1 print(sereza, dima) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
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,647,238,852
2,147,483,647
Python 3
OK
TESTS
35
92
0
first_multiple_input = input().rstrip().split() n = int(first_multiple_input[0]) k = int(first_multiple_input[1]) print(n*k//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 possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python first_multiple_input = input().rstrip().split() n = int(first_multiple_input[0]) k = int(first_multiple_input[1]) print(n*k//2) ```
3.977
999
A
Mishka and Contest
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list. Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list. How many problems can Mishka solve?
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Print one integer — the maximum number of problems Mishka can solve.
[ "8 4\n4 2 3 1 5 1 6 4\n", "5 2\n3 1 2 1 3\n", "5 100\n12 34 55 43 21\n" ]
[ "5\n", "0\n", "5\n" ]
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$. In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
0
[ { "input": "8 4\n4 2 3 1 5 1 6 4", "output": "5" }, { "input": "5 2\n3 1 2 1 3", "output": "0" }, { "input": "5 100\n12 34 55 43 21", "output": "5" }, { "input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1...
1,608,764,202
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
108
307,200
n,k=input().split(" ") n=int(n) k=int(k) #recieve list of elements which they length is n # if number of element bigger than n ignore the additional value c=input (). split(" ",n) c=list(map(int,c)) #Now we will divide alist into to lists m = int (n/2) #we will but the last elements from the median to end and we will reverse ther s=c[m:n] s.reverse() #llooping over two lists and increase h by one if k>=element in list #it will fo out from the loop if he met element >k h=0 for i in c[0:m]: if (k>i or k==i ):h+=1; else :break; for i in s: if (k>i or k==i ):h+=1; else :break; #printing output print(h)
Title: Mishka and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list. Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list. How many problems can Mishka solve? Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list. Output Specification: Print one integer — the maximum number of problems Mishka can solve. Demo Input: ['8 4\n4 2 3 1 5 1 6 4\n', '5 2\n3 1 2 1 3\n', '5 100\n12 34 55 43 21\n'] Demo Output: ['5\n', '0\n', '5\n'] Note: In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$. In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
```python n,k=input().split(" ") n=int(n) k=int(k) #recieve list of elements which they length is n # if number of element bigger than n ignore the additional value c=input (). split(" ",n) c=list(map(int,c)) #Now we will divide alist into to lists m = int (n/2) #we will but the last elements from the median to end and we will reverse ther s=c[m:n] s.reverse() #llooping over two lists and increase h by one if k>=element in list #it will fo out from the loop if he met element >k h=0 for i in c[0:m]: if (k>i or k==i ):h+=1; else :break; for i in s: if (k>i or k==i ):h+=1; else :break; #printing output print(h) ```
0
102
A
Clothes
PROGRAMMING
1,200
[ "brute force" ]
A. Clothes
2
256
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells *n* clothing items, and exactly *m* pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.
The first input file line contains integers *n* and *m* — the total number of clothing items in the shop and the total number of matching pairs of clothing items (). Next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the prices of the clothing items in rubles. Next *m* lines each contain a pair of space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*). Each such pair of numbers means that the *u**i*-th and the *v**i*-th clothing items match each other. It is guaranteed that in each pair *u**i* and *v**i* are distinct and all the unordered pairs (*u**i*,<=*v**i*) are different.
Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).
[ "3 3\n1 2 3\n1 2\n2 3\n3 1\n", "3 2\n2 3 4\n2 3\n2 1\n", "4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1\n" ]
[ "6\n", "-1\n", "-1\n" ]
In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
500
[ { "input": "3 3\n1 2 3\n1 2\n2 3\n3 1", "output": "6" }, { "input": "3 2\n2 3 4\n2 3\n2 1", "output": "-1" }, { "input": "4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1", "output": "-1" }, { "input": "4 3\n10 10 5 1\n2 1\n3 1\n3 4", "output": "-1" }, { "input": "4 0\n9 8 2 10",...
1,665,087,800
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
import math def gcd(a,b): while a%b !=0: aux = b b = a%b a = aux return b def lcm(a,b): return (a/gcd(a,b))*b def solve(a): return ((a-3)//3)-1 for _ in range(int(input())): a = int(input()) print(solve(a))
Title: Clothes Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells *n* clothing items, and exactly *m* pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. Input Specification: The first input file line contains integers *n* and *m* — the total number of clothing items in the shop and the total number of matching pairs of clothing items (). Next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the prices of the clothing items in rubles. Next *m* lines each contain a pair of space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*). Each such pair of numbers means that the *u**i*-th and the *v**i*-th clothing items match each other. It is guaranteed that in each pair *u**i* and *v**i* are distinct and all the unordered pairs (*u**i*,<=*v**i*) are different. Output Specification: Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Demo Input: ['3 3\n1 2 3\n1 2\n2 3\n3 1\n', '3 2\n2 3 4\n2 3\n2 1\n', '4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1\n'] Demo Output: ['6\n', '-1\n', '-1\n'] Note: In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles. The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1. In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.
```python import math def gcd(a,b): while a%b !=0: aux = b b = a%b a = aux return b def lcm(a,b): return (a/gcd(a,b))*b def solve(a): return ((a-3)//3)-1 for _ in range(int(input())): a = int(input()) print(solve(a)) ```
-1
479
C
Exams
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=&lt;<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly.
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
[ "3\n5 2\n3 1\n4 2\n", "3\n6 1\n5 2\n4 3\n" ]
[ "2\n", "6\n" ]
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
1,500
[ { "input": "3\n5 2\n3 1\n4 2", "output": "2" }, { "input": "3\n6 1\n5 2\n4 3", "output": "6" }, { "input": "1\n1000000000 999999999", "output": "999999999" }, { "input": "1\n2 1", "output": "1" }, { "input": "2\n3 2\n3 2", "output": "2" }, { "input": "...
1,686,447,247
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
33
155
6,144,000
a = [list(map(int,input().split())) for i in range(int(input()))] b = sorted(a) c = [i[1] for i in b] if c == sorted(c): print(c[-1]) else: d = dict() for i,j in b: try: d[j] = min(i,d[j]) except KeyError: d[j] = i print(max(d.values()))
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=&lt;<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input Specification: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly. Output Specification: Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Demo Input: ['3\n5 2\n3 1\n4 2\n', '3\n6 1\n5 2\n4 3\n'] Demo Output: ['2\n', '6\n'] Note: In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
```python a = [list(map(int,input().split())) for i in range(int(input()))] b = sorted(a) c = [i[1] for i in b] if c == sorted(c): print(c[-1]) else: d = dict() for i,j in b: try: d[j] = min(i,d[j]) except KeyError: d[j] = i print(max(d.values())) ```
0
63
A
Sinking Ship
PROGRAMMING
900
[ "implementation", "sortings", "strings" ]
A. Sinking Ship
2
256
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
[ "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n" ]
[ "Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n" ]
none
500
[ { "input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack" }, { "input": "1\nA captain", "output": "A" }, { "input": "1\nAbcdefjhij captain", "output": "Abcdefjhij" }, { "input": "5\nA captain...
1,699,681,780
2,147,483,647
PyPy 3
OK
TESTS
26
216
1,843,200
from functools import cmp_to_key class Info: def __init__(self, _id: int, _name: str, _status: str): self.id = _id self.name = _name self.status = _status def __str__(self): return f'id: {self.id}, name: {self.name}, status: {self.status}' def customCompare(obj1:Info, obj2:Info) -> int: if obj1.status != "rat" and obj2.status == "rat": return 1 if obj1.status == "rat" and obj2.status != "rat": return -1 if (obj1.status != "woman" and obj1.status != "child") and (obj2.status == "woman" or obj2.status == "child"): return 1 if (obj1.status == "woman" or obj1.status == "child") and (obj2.status != "woman" and obj2.status != "child"): return -1 if obj1.status != "man" and obj2.status == "man": return 1 if obj1.status == "man" and obj2.status != "man": return -1 return obj1.id - obj2.id def output(cont:list): for obj in cont: print(obj) n = int(input()) cont = [] for i in range(n): _name, _status = input().split() obj = Info(i + 1, _name, _status) cont.append(obj) cont.sort(key=cmp_to_key(customCompare)) for obj in cont: print(obj.name)
Title: Sinking Ship Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. Input Specification: The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. Output Specification: Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. Demo Input: ['6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n'] Demo Output: ['Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n'] Note: none
```python from functools import cmp_to_key class Info: def __init__(self, _id: int, _name: str, _status: str): self.id = _id self.name = _name self.status = _status def __str__(self): return f'id: {self.id}, name: {self.name}, status: {self.status}' def customCompare(obj1:Info, obj2:Info) -> int: if obj1.status != "rat" and obj2.status == "rat": return 1 if obj1.status == "rat" and obj2.status != "rat": return -1 if (obj1.status != "woman" and obj1.status != "child") and (obj2.status == "woman" or obj2.status == "child"): return 1 if (obj1.status == "woman" or obj1.status == "child") and (obj2.status != "woman" and obj2.status != "child"): return -1 if obj1.status != "man" and obj2.status == "man": return 1 if obj1.status == "man" and obj2.status != "man": return -1 return obj1.id - obj2.id def output(cont:list): for obj in cont: print(obj) n = int(input()) cont = [] for i in range(n): _name, _status = input().split() obj = Info(i + 1, _name, _status) cont.append(obj) cont.sort(key=cmp_to_key(customCompare)) for obj in cont: print(obj.name) ```
3.942567
638
A
Home Numbers
PROGRAMMING
1,100
[ "*special", "constructive algorithms", "math" ]
null
null
The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to *n* in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house *n*, house 3 is opposite house *n*<=-<=2, house 5 is opposite house *n*<=-<=4 and so on. Vasya needs to get to house number *a* as quickly as possible. He starts driving from the beginning of the street and drives his car to house *a*. To get from the beginning of the street to houses number 1 and *n*, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same. Your task is: find the minimum time Vasya needs to reach house *a*.
The first line of the input contains two integers, *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100<=000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even.
Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house *a*.
[ "4 2\n", "8 5\n" ]
[ "2\n", "3\n" ]
In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right. The second sample corresponds to picture with *n* = 8. House 5 is the one before last at Vasya's left.
500
[ { "input": "4 2", "output": "2" }, { "input": "8 5", "output": "3" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "10 1", "output": "1" }, { "input": "10 10", "output": "1" }, { "input": "100000 100000",...
1,458,487,878
12,678
PyPy 3
OK
TESTS
69
109
23,244,800
n, a = [int(x) for x in input().split()] ans = 1 if a % 2 == 0: while n != a: n -= 2 ans += 1 else: t = 1 while t != a: t += 2 ans += 1 print(ans)
Title: Home Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to *n* in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house *n*, house 3 is opposite house *n*<=-<=2, house 5 is opposite house *n*<=-<=4 and so on. Vasya needs to get to house number *a* as quickly as possible. He starts driving from the beginning of the street and drives his car to house *a*. To get from the beginning of the street to houses number 1 and *n*, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same. Your task is: find the minimum time Vasya needs to reach house *a*. Input Specification: The first line of the input contains two integers, *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100<=000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even. Output Specification: Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house *a*. Demo Input: ['4 2\n', '8 5\n'] Demo Output: ['2\n', '3\n'] Note: In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right. The second sample corresponds to picture with *n* = 8. House 5 is the one before last at Vasya's left.
```python n, a = [int(x) for x in input().split()] ans = 1 if a % 2 == 0: while n != a: n -= 2 ans += 1 else: t = 1 while t != a: t += 2 ans += 1 print(ans) ```
3
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 is the minimum number of operations that she needs to sort the sequence?
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,608,389,276
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
7,065,600
n=int(input()) l=list(map(int,input().split())) x=True for i in range(n-1): if l[i]>l[i+1]: a=l[0:i+1:1] b=l[i+1::] c=a[::] d=b[::] c.sort() d.sort() if a==c and b==d and c[0]>d[0]: print(len(b)) x=False else: print(-1) x=False if x: print(0)
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. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? Input Specification: 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). Output Specification: If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. Demo Input: ['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['1\n', '-1\n', '0\n'] Note: none
```python n=int(input()) l=list(map(int,input().split())) x=True for i in range(n-1): if l[i]>l[i+1]: a=l[0:i+1:1] b=l[i+1::] c=a[::] d=b[::] c.sort() d.sort() if a==c and b==d and c[0]>d[0]: print(len(b)) x=False else: print(-1) x=False if x: print(0) ```
0
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 have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*.
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,643,952,081
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
156
0
n,k=map(int,input().split()) ans=0 if(k//n==2): ans+=n ans-=k%n print(ans)
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 too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. Input Specification: 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*. Output Specification: 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*. Demo Input: ['4 8\n', '4 10\n', '1 3\n'] Demo Output: ['4\n', '2\n', '0\n'] Note: 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.
```python n,k=map(int,input().split()) ans=0 if(k//n==2): ans+=n ans-=k%n print(ans) ```
0
36
A
Extra-terrestrial Intelligence
PROGRAMMING
1,300
[ "implementation" ]
A. Extra-terrestrial Intelligence
2
64
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s.
If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO.
[ "8\n00111000\n", "7\n1001011\n", "7\n1010100\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "8\n00111000", "output": "YES" }, { "input": "7\n1001011", "output": "NO" }, { "input": "7\n1010100", "output": "YES" }, { "input": "5\n10101", "output": "YES" }, { "input": "3\n111", "output": "YES" }, { "input": "10\n0011111011", "outp...
1,574,636,727
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
434
2,150,400
fin = open('input.txt') fout = open('output.txt') n = int(fin.readline()) s = str(fin.readline()) a = set() p = 0 d = 0 first_met = False for i in range(n): if s[i] == '1': if not first_met: first_met = True else: a.add(i - d) d = i if len(a) == 1: print("YES", file=fout) else: print("NO", file=fout) fin.close() fout.close()
Title: Extra-terrestrial Intelligence Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. Output Specification: If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. Demo Input: ['8\n00111000\n', '7\n1001011\n', '7\n1010100\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python fin = open('input.txt') fout = open('output.txt') n = int(fin.readline()) s = str(fin.readline()) a = set() p = 0 d = 0 first_met = False for i in range(n): if s[i] == '1': if not first_met: first_met = True else: a.add(i - d) d = i if len(a) == 1: print("YES", file=fout) else: print("NO", file=fout) fin.close() fout.close() ```
-1
254
A
Cards with Numbers
PROGRAMMING
1,200
[ "constructive algorithms", "sortings" ]
null
null
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs. Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
[ "3\n20 30 10 30 20 10\n", "1\n1 2\n" ]
[ "4 2\n1 5\n6 3\n", "-1" ]
none
500
[ { "input": "3\n20 30 10 30 20 10", "output": "4 2\n1 5\n6 3" }, { "input": "1\n1 2", "output": "-1" }, { "input": "5\n2 2 2 2 2 1 2 2 1 2", "output": "2 1\n3 4\n7 5\n6 9\n10 8" }, { "input": "5\n2 1 2 2 1 1 1 1 1 2", "output": "3 1\n2 5\n7 6\n8 9\n10 4" }, { "inpu...
1,586,875,999
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
78
307,200
n = int(input()) s = list(map(int, input().split())) if len(set(s)) != len(s)//2: print(-1) else: ans = [] m = list(set(s)) for i in range(2*n): if s[i] in m: for j in range(2*n): if s[i] == s[j] and i != j: ans.append((i+1, j+1)) m.remove(s[i]) for x in ans: print(x[0], x[1])
Title: Cards with Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. Output Specification: If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs. Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them. Demo Input: ['3\n20 30 10 30 20 10\n', '1\n1 2\n'] Demo Output: ['4 2\n1 5\n6 3\n', '-1'] Note: none
```python n = int(input()) s = list(map(int, input().split())) if len(set(s)) != len(s)//2: print(-1) else: ans = [] m = list(set(s)) for i in range(2*n): if s[i] in m: for j in range(2*n): if s[i] == s[j] and i != j: ans.append((i+1, j+1)) m.remove(s[i]) for x in ans: print(x[0], x[1]) ```
-1
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get.
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, {...
1,698,611,854
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
77
0
a,b,c=int(input()),int(input()),int(input());print(max((a+b)*c,(a*b)+c,a*(b+c),a+(b*c),(a+c)*b,(a*c)+b,a*b*c)) # Colin Deiaa
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get. Input Specification: The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). Output Specification: Print the maximum value of the expression that you can obtain. Demo Input: ['1\n2\n3\n', '2\n10\n3\n'] Demo Output: ['9\n', '60\n'] Note: none
```python a,b,c=int(input()),int(input()),int(input());print(max((a+b)*c,(a*b)+c,a*(b+c),a+(b*c),(a+c)*b,(a*c)+b,a*b*c)) # Colin Deiaa ```
0
747
C
Servers
PROGRAMMING
1,300
[ "implementation" ]
null
null
There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*. It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of servers needed to perform it, and *d**i* — the time needed to perform this task in seconds. All *t**i* are distinct. To perform the *i*-th task you need *k**i* servers which are unoccupied in the second *t**i*. After the servers begin to perform the task, each of them will be busy over the next *d**i* seconds. Thus, they will be busy in seconds *t**i*,<=*t**i*<=+<=1,<=...,<=*t**i*<=+<=*d**i*<=-<=1. For performing the task, *k**i* servers with the smallest ids will be chosen from all the unoccupied servers. If in the second *t**i* there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored.
The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks. Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000) — the moment in seconds in which the *i*-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.
Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.
[ "4 3\n1 3 2\n2 2 1\n3 4 3\n", "3 2\n3 2 3\n5 1 2\n", "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n" ]
[ "6\n-1\n10\n", "3\n3\n", "6\n9\n30\n-1\n15\n36\n" ]
In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
1,500
[ { "input": "4 3\n1 3 2\n2 2 1\n3 4 3", "output": "6\n-1\n10" }, { "input": "3 2\n3 2 3\n5 1 2", "output": "3\n3" }, { "input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8", "output": "6\n9\n30\n-1\n15\n36" }, { "input": "4 1\n6 1 1", "output": "1" }, { "inp...
1,638,271,750
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
0
n,q = [int(x) for x in input().split()] lis = [i+1 for i in range(n)] arr = [0 for i in range(n)] t1 = 0 for qq in range(q): t,k,d = [int(x) for x in input().split()] count = 0 for i in range(n): arr[i] = min(arr[i]+t-t1,0) # print('before op arr', *arr) t1 = t j = 0 res = [] while(count < k and j <n): if arr[j]>=0: count += 1 res.append(j+1) j += 1 if count >= k : print(sum(res)) for item in res: arr[item-1] -= d else: print(-1) # print(*arr) # print(*res) # arr[j] -= d # ans += lis[j]
Title: Servers Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*. It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of servers needed to perform it, and *d**i* — the time needed to perform this task in seconds. All *t**i* are distinct. To perform the *i*-th task you need *k**i* servers which are unoccupied in the second *t**i*. After the servers begin to perform the task, each of them will be busy over the next *d**i* seconds. Thus, they will be busy in seconds *t**i*,<=*t**i*<=+<=1,<=...,<=*t**i*<=+<=*d**i*<=-<=1. For performing the task, *k**i* servers with the smallest ids will be chosen from all the unoccupied servers. If in the second *t**i* there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input Specification: The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks. Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000) — the moment in seconds in which the *i*-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Specification: Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Demo Input: ['4 3\n1 3 2\n2 2 1\n3 4 3\n', '3 2\n3 2 3\n5 1 2\n', '8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n'] Demo Output: ['6\n-1\n10\n', '3\n3\n', '6\n9\n30\n-1\n15\n36\n'] Note: In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
```python n,q = [int(x) for x in input().split()] lis = [i+1 for i in range(n)] arr = [0 for i in range(n)] t1 = 0 for qq in range(q): t,k,d = [int(x) for x in input().split()] count = 0 for i in range(n): arr[i] = min(arr[i]+t-t1,0) # print('before op arr', *arr) t1 = t j = 0 res = [] while(count < k and j <n): if arr[j]>=0: count += 1 res.append(j+1) j += 1 if count >= k : print(sum(res)) for item in res: arr[item-1] -= d else: print(-1) # print(*arr) # print(*res) # arr[j] -= d # ans += lis[j] ```
0
99
A
Help Far Away Kingdom
PROGRAMMING
800
[ "strings" ]
A. Help Far Away Kingdom
2
256
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?
The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.
If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).
[ "0.0\n", "1.49\n", "1.50\n", "2.71828182845904523536\n", "3.14159265358979323846\n", "12345678901234567890.1\n", "123456789123456789.999\n" ]
[ "0", "1", "2", "3", "3", "12345678901234567890", "GOTO Vasilisa." ]
none
500
[ { "input": "0.0", "output": "0" }, { "input": "1.49", "output": "1" }, { "input": "1.50", "output": "2" }, { "input": "2.71828182845904523536", "output": "3" }, { "input": "3.14159265358979323846", "output": "3" }, { "input": "12345678901234567890.1", ...
1,691,776,154
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
# Read the number as a string number = input() # Split the number into integer and fractional parts integer_part, fractional_part = number.split(".") # Check if the last digit of the integer part is not 9 if integer_part[-1] != "9": # Check if the fractional part is less than 0.5 if int(fractional_part) < 5: rounded_number = integer_part else: rounded_number = str(int(integer_part) + 1) print(rounded_number) else: print("GOTO Vasilisa.")
Title: Help Far Away Kingdom Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order? Input Specification: The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data. Output Specification: If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). Demo Input: ['0.0\n', '1.49\n', '1.50\n', '2.71828182845904523536\n', '3.14159265358979323846\n', '12345678901234567890.1\n', '123456789123456789.999\n'] Demo Output: ['0', '1', '2', '3', '3', '12345678901234567890', 'GOTO Vasilisa.'] Note: none
```python # Read the number as a string number = input() # Split the number into integer and fractional parts integer_part, fractional_part = number.split(".") # Check if the last digit of the integer part is not 9 if integer_part[-1] != "9": # Check if the fractional part is less than 0.5 if int(fractional_part) < 5: rounded_number = integer_part else: rounded_number = str(int(integer_part) + 1) print(rounded_number) else: print("GOTO Vasilisa.") ```
0
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him?
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input":...
1,687,523,565
2,147,483,647
Python 3
OK
TESTS
30
46
0
socks = list(map(int, input().split(' '))) first = 0 second = 0 while socks[0] != 0 and socks[1] != 0: socks[0] -= 1 socks[1] -= 1 first += 1 if socks[0] == 0: socks = socks[1] elif socks[1] == 0: socks = socks[0] while socks != 1 and socks != 0: socks -= 2 second += 1 print(first, second)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input Specification: The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. Output Specification: Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Demo Input: ['3 1\n', '2 3\n', '7 3\n'] Demo Output: ['1 1\n', '2 0\n', '3 2\n'] Note: In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
```python socks = list(map(int, input().split(' '))) first = 0 second = 0 while socks[0] != 0 and socks[1] != 0: socks[0] -= 1 socks[1] -= 1 first += 1 if socks[0] == 0: socks = socks[1] elif socks[1] == 0: socks = socks[0] while socks != 1 and socks != 0: socks -= 2 second += 1 print(first, second) ```
3
888
A
Local Extrema
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=&gt;<=*a**i*<=-<=1 and *a**i*<=&gt;<=*a**i*<=+<=1). Since *a*1 and *a**n* have only one neighbour each, they are neither local minima nor local maxima. An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*.
Print the number of local extrema in the given array.
[ "3\n1 2 3\n", "4\n1 5 2 5\n" ]
[ "0\n", "2\n" ]
none
0
[ { "input": "3\n1 2 3", "output": "0" }, { "input": "4\n1 5 2 5", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "1\n548", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n3 2 3", "output": "1" }, { "inp...
1,656,443,702
2,147,483,647
Python 3
OK
TESTS
14
46
0
a = int(input()) local = list(map(int, input().split())) ans = 0 for i in range(1, a - 1): if local[i] > local[i - 1] and local[i] > local[i + 1]: ans += 1 if local[i] < local[i - 1] and local[i] < local[i + 1]: ans += 1 print(ans)
Title: Local Extrema Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=&gt;<=*a**i*<=-<=1 and *a**i*<=&gt;<=*a**i*<=+<=1). Since *a*1 and *a**n* have only one neighbour each, they are neither local minima nor local maxima. An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*. Output Specification: Print the number of local extrema in the given array. Demo Input: ['3\n1 2 3\n', '4\n1 5 2 5\n'] Demo Output: ['0\n', '2\n'] Note: none
```python a = int(input()) local = list(map(int, input().split())) ans = 0 for i in range(1, a - 1): if local[i] > local[i - 1] and local[i] > local[i + 1]: ans += 1 if local[i] < local[i - 1] and local[i] < local[i + 1]: ans += 1 print(ans) ```
3