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
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "output": "11 13" }, { "input": "17", "output": "8 9" }, { "input": "10", "output": "3 7" }, { "input": "69", "output": "34 35" }, { "input": "100", "output": "49 51" }, { "input": "57", "output": "28 29" }, { "input": "1000", "output": "499 501" }, { "input": "999", "output": "499 500" }, { "input": "998", "output": "497 501" }, { "input": "997", "output": "498 499" }, { "input": "996", "output": "497 499" }, { "input": "995", "output": "497 498" }, { "input": "994", "output": "495 499" }, { "input": "5", "output": "2 3" }, { "input": "6", "output": "1 5" }, { "input": "8", "output": "3 5" }, { "input": "9", "output": "4 5" }, { "input": "423", "output": "211 212" }, { "input": "876", "output": "437 439" }, { "input": "29", "output": "14 15" } ]
1,641,895,837
2,147,483,647
PyPy 3-64
OK
TESTS
26
93
0
import math n=int(input()) for i in range(n,(n//2)-1,-1): if math.gcd( (i-1)//2 , n-(i-1)//2 )==1: print((i-1)//2,(n-(i-1)//2)) break
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. Input Specification: In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. Output Specification: Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. Demo Input: ['3\n', '4\n', '12\n'] Demo Output: ['1 2\n', '1 3\n', '5 7\n'] Note: none
```python import math n=int(input()) for i in range(n,(n//2)-1,-1): if math.gcd( (i-1)//2 , n-(i-1)//2 )==1: print((i-1)//2,(n-(i-1)//2)) break ```
3
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\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth", "output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO" }, { "input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv", "output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES" }, { "input": "1\nz", "output": "NO" }, { "input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf", "output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO" }, { "input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr", "output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO" }, { "input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES" }, { "input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES" }, { "input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "NO\nNO\nNO" }, { "input": "2\nab\nba", "output": "NO\nNO" }, { "input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", "output": "NO\nYES" }, { "input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na", "output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" } ]
1,661,834,122
2,147,483,647
PyPy 3
OK
TESTS
55
77
0
n = int (input()) dt = {} for i in range (n): s = input() if s in dt: print ("YES") else: print ("NO") dt[s] = True
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 n = int (input()) dt = {} for i in range (n): s = input() if s in dt: print ("YES") else: print ("NO") dt[s] = True ```
3
946
B
Weird Subtraction Process
PROGRAMMING
1,100
[ "math", "number theory" ]
null
null
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables: 1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process. Initially the values of *a* and *b* are positive integers, and so the process will be finite. You have to determine the values of *a* and *b* after the process ends.
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*.
Print two integers — the values of *a* and *b* after the end of the process.
[ "12 5\n", "31 12\n" ]
[ "0 1\n", "7 12\n" ]
Explanations to the samples: 1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12.
0
[ { "input": "12 5", "output": "0 1" }, { "input": "31 12", "output": "7 12" }, { "input": "1000000000000000000 7", "output": "8 7" }, { "input": "31960284556200 8515664064180", "output": "14928956427840 8515664064180" }, { "input": "1000000000000000000 1000000000000000000", "output": "1000000000000000000 1000000000000000000" }, { "input": "1 1000", "output": "1 0" }, { "input": "1 1000000", "output": "1 0" }, { "input": "1 1000000000000000", "output": "1 0" }, { "input": "1 99999999999999999", "output": "1 1" }, { "input": "1 4", "output": "1 0" }, { "input": "1000000000000001 500000000000000", "output": "1 0" }, { "input": "1 1000000000000000000", "output": "1 0" }, { "input": "2 4", "output": "2 0" }, { "input": "2 1", "output": "0 1" }, { "input": "6 19", "output": "6 7" }, { "input": "22 5", "output": "0 1" }, { "input": "10000000000000000 100000000000000001", "output": "0 1" }, { "input": "1 1000000000000", "output": "1 0" }, { "input": "2 1000000000000000", "output": "2 0" }, { "input": "2 10", "output": "2 2" }, { "input": "51 100", "output": "51 100" }, { "input": "3 1000000000000000000", "output": "3 4" }, { "input": "1000000000000000000 3", "output": "4 3" }, { "input": "1 10000000000000000", "output": "1 0" }, { "input": "8796203 7556", "output": "1019 1442" }, { "input": "5 22", "output": "1 0" }, { "input": "1000000000000000000 1", "output": "0 1" }, { "input": "1 100000000000", "output": "1 0" }, { "input": "2 1000000000000", "output": "2 0" }, { "input": "5 4567865432345678", "output": "5 8" }, { "input": "576460752303423487 288230376151711743", "output": "1 1" }, { "input": "499999999999999999 1000000000000000000", "output": "3 2" }, { "input": "1 9999999999999", "output": "1 1" }, { "input": "103 1000000000000000000", "output": "103 196" }, { "input": "7 1", "output": "1 1" }, { "input": "100000000000000001 10000000000000000", "output": "1 0" }, { "input": "5 10", "output": "5 0" }, { "input": "7 11", "output": "7 11" }, { "input": "1 123456789123456", "output": "1 0" }, { "input": "5000000000000 100000000000001", "output": "0 1" }, { "input": "1000000000000000 1", "output": "0 1" }, { "input": "1000000000000000000 499999999999999999", "output": "2 3" }, { "input": "10 5", "output": "0 5" }, { "input": "9 18917827189272", "output": "9 0" }, { "input": "179 100000000000497000", "output": "179 270" }, { "input": "5 100000000000001", "output": "1 1" }, { "input": "5 20", "output": "5 0" }, { "input": "100000001 50000000", "output": "1 0" }, { "input": "345869461223138161 835002744095575440", "output": "1 0" }, { "input": "8589934592 4294967296", "output": "0 4294967296" }, { "input": "4 8", "output": "4 0" }, { "input": "1 100000000000000000", "output": "1 0" }, { "input": "1000000000000000000 333333333333333", "output": "1000 1333" }, { "input": "25 12", "output": "1 0" }, { "input": "24 54", "output": "0 6" }, { "input": "6 12", "output": "6 0" }, { "input": "129200000000305 547300000001292", "output": "1 0" }, { "input": "1000000000000000000 49999999999999999", "output": "20 39" }, { "input": "1 2", "output": "1 0" }, { "input": "1 123456789876", "output": "1 0" }, { "input": "2 3", "output": "2 3" }, { "input": "1 3", "output": "1 1" }, { "input": "1 1", "output": "1 1" }, { "input": "19 46", "output": "3 2" }, { "input": "3 6", "output": "3 0" }, { "input": "129 1000000000000000000", "output": "1 0" }, { "input": "12 29", "output": "0 1" }, { "input": "8589934592 2147483648", "output": "0 2147483648" }, { "input": "2147483648 8589934592", "output": "2147483648 0" }, { "input": "5 6", "output": "5 6" }, { "input": "1000000000000000000 2", "output": "0 2" }, { "input": "2 7", "output": "2 3" }, { "input": "17174219820754872 61797504734333370", "output": "17174219820754872 27449065092823626" }, { "input": "49 100", "output": "1 0" }, { "input": "7 17", "output": "1 1" }, { "input": "1000000000000000000 10000001", "output": "0 1" }, { "input": "49999999999999999 2", "output": "3 2" }, { "input": "49999999999999999 1", "output": "1 1" }, { "input": "576460752303423487 2", "output": "3 2" }, { "input": "19395 19395", "output": "19395 19395" }, { "input": "19394 19394", "output": "19394 19394" } ]
1,554,913,232
2,147,483,647
Python 3
OK
TESTS
81
124
0
x, y = map(int, input().split()) ans = [] k = 0 while True: if x >= 2 * y: x %= 2 * y else: y %= 2 * x if x == 0 or y == 0: break if ans == [x, y]: k += 1 else: ans = [x, y] k = 0 if k == 5: break print(x, y)
Title: Weird Subtraction Process Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables: 1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process. Initially the values of *a* and *b* are positive integers, and so the process will be finite. You have to determine the values of *a* and *b* after the process ends. Input Specification: The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. Output Specification: Print two integers — the values of *a* and *b* after the end of the process. Demo Input: ['12 5\n', '31 12\n'] Demo Output: ['0 1\n', '7 12\n'] Note: Explanations to the samples: 1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12.
```python x, y = map(int, input().split()) ans = [] k = 0 while True: if x >= 2 * y: x %= 2 * y else: y %= 2 * x if x == 0 or y == 0: break if ans == [x, y]: k += 1 else: ans = [x, y] k = 0 if k == 5: break print(x, y) ```
3
0
none
none
none
0
[ "none" ]
null
null
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to. The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109).
Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments.
[ "5 2\n1 2 3 4 5\n", "5 1\n-4 -5 -3 -2 -1\n" ]
[ "5\n", "-5\n" ]
A subsegment [*l*,  *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>,  *a*<sub class="lower-index">*l* + 1</sub>,  ...,  *a*<sub class="lower-index">*r*</sub>. Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub>], [*l*<sub class="lower-index">2</sub>, *r*<sub class="lower-index">2</sub>], ..., [*l*<sub class="lower-index">*k*</sub>, *r*<sub class="lower-index">*k*</sub>] (*l*<sub class="lower-index">1</sub> = 1, *r*<sub class="lower-index">*k*</sub> = *n*, *l*<sub class="lower-index">*i*</sub> = *r*<sub class="lower-index">*i* - 1</sub> + 1 for all *i* &gt; 1) is *k* sequences (*a*<sub class="lower-index">*l*<sub class="lower-index">1</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">1</sub></sub>), ..., (*a*<sub class="lower-index">*l*<sub class="lower-index">*k*</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">*k*</sub></sub>). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are *min*(1, 2, 3, 4) = 1 and *min*(5) = 5. The resulting maximum is *max*(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4,  - 5,  - 3,  - 2,  - 1). The only minimum is *min*( - 4,  - 5,  - 3,  - 2,  - 1) =  - 5. The resulting maximum is  - 5.
0
[ { "input": "5 2\n1 2 3 4 5", "output": "5" }, { "input": "5 1\n-4 -5 -3 -2 -1", "output": "-5" }, { "input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5", "output": "10" }, { "input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9", "output": "9" }, { "input": "1 1\n504262064", "output": "504262064" }, { "input": "3 3\n-54481850 -878017339 -486296116", "output": "-54481850" }, { "input": "2 2\n-333653905 224013643", "output": "224013643" }, { "input": "14 2\n-14 84 44 46 -75 -75 77 -49 44 -82 -74 -51 -9 -50", "output": "-14" }, { "input": "88 71\n-497 -488 182 104 40 183 201 282 -384 44 -29 494 224 -80 -491 -197 157 130 -52 233 -426 252 -61 -51 203 -50 195 -442 -38 385 232 -243 -49 163 340 -200 406 -254 -29 227 -194 193 487 -325 230 146 421 158 20 447 -97 479 493 -130 164 -471 -198 -330 -152 359 -554 319 544 -444 235 281 -467 337 -385 227 -366 -210 266 69 -261 525 526 -234 -355 177 109 275 -301 7 -41 553 -284 540", "output": "553" }, { "input": "39 1\n676941771 -923780377 -163050076 -230110947 -208029500 329620771 13954060 158950156 -252501602 926390671 -678745080 -921892226 -100127643 610420285 602175224 -839193819 471391946 910035173 777969600 -736144413 -489685522 60986249 830784148 278642552 -375298304 197973611 -354482364 187294011 636628282 25350767 636184407 -550869740 53830680 -42049274 -451383278 900048257 93225803 877923341 -279506435", "output": "-923780377" }, { "input": "3 2\n1 5 3", "output": "3" }, { "input": "5 2\n1 2 5 4 3", "output": "3" }, { "input": "3 2\n1 3 2", "output": "2" }, { "input": "3 2\n1 3 1", "output": "1" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "-2" }, { "input": "5 2\n1 2 3 5 4", "output": "4" }, { "input": "5 2\n1 1 11 1 1", "output": "1" }, { "input": "3 3\n3 8 4", "output": "8" }, { "input": "6 3\n4 3 1 5 6 2", "output": "6" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "5 2\n2 5 4 3 1", "output": "2" }, { "input": "5 2\n-1 1 5 4 3", "output": "3" }, { "input": "5 2\n5 2 1 9 3", "output": "5" }, { "input": "2 1\n1000000000 1000000000", "output": "1000000000" }, { "input": "1 1\n1000000000", "output": "1000000000" }, { "input": "5 2\n1 5 3 4 1", "output": "1" }, { "input": "3 2\n-1000000000 -1000000000 -1000000000", "output": "-1000000000" }, { "input": "2 2\n5 2", "output": "5" }, { "input": "7 3\n1 1 1 10 1 1 1", "output": "10" }, { "input": "9 3\n1 2 1 1 5 1 1 1 2", "output": "5" }, { "input": "9 3\n2 2 2 2 9 2 2 2 2", "output": "9" }, { "input": "3 3\n-1000000000 -1000000000 -1000000000", "output": "-1000000000" } ]
1,508,055,568
868
Python 3
WRONG_ANSWER
PRETESTS
4
62
5,529,600
a=input() k=int(a.split(' ')[1]) d=list(map(lambda x: int(x),input().split(' '))) res=0 if k>=3: res=max(d) if k==1: res=min(d) else: res=max(d[0],d[-1]) print(res)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to. The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). Output Specification: Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. Demo Input: ['5 2\n1 2 3 4 5\n', '5 1\n-4 -5 -3 -2 -1\n'] Demo Output: ['5\n', '-5\n'] Note: A subsegment [*l*,  *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>,  *a*<sub class="lower-index">*l* + 1</sub>,  ...,  *a*<sub class="lower-index">*r*</sub>. Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub>], [*l*<sub class="lower-index">2</sub>, *r*<sub class="lower-index">2</sub>], ..., [*l*<sub class="lower-index">*k*</sub>, *r*<sub class="lower-index">*k*</sub>] (*l*<sub class="lower-index">1</sub> = 1, *r*<sub class="lower-index">*k*</sub> = *n*, *l*<sub class="lower-index">*i*</sub> = *r*<sub class="lower-index">*i* - 1</sub> + 1 for all *i* &gt; 1) is *k* sequences (*a*<sub class="lower-index">*l*<sub class="lower-index">1</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">1</sub></sub>), ..., (*a*<sub class="lower-index">*l*<sub class="lower-index">*k*</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">*k*</sub></sub>). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are *min*(1, 2, 3, 4) = 1 and *min*(5) = 5. The resulting maximum is *max*(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4,  - 5,  - 3,  - 2,  - 1). The only minimum is *min*( - 4,  - 5,  - 3,  - 2,  - 1) =  - 5. The resulting maximum is  - 5.
```python a=input() k=int(a.split(' ')[1]) d=list(map(lambda x: int(x),input().split(' '))) res=0 if k>=3: res=max(d) if k==1: res=min(d) else: res=max(d[0],d[-1]) print(res) ```
0
262
A
Roma and Lucky Numbers
PROGRAMMING
800
[ "implementation" ]
null
null
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
[ "3 4\n1 2 4\n", "3 2\n447 44 77\n" ]
[ "3\n", "2\n" ]
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
500
[ { "input": "3 4\n1 2 4", "output": "3" }, { "input": "3 2\n447 44 77", "output": "2" }, { "input": "2 2\n507978501 180480073", "output": "2" }, { "input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "output": "9" }, { "input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227", "output": "6" }, { "input": "4 2\n194041605 706221269 69909135 257655784", "output": "3" }, { "input": "4 2\n9581849 67346651 530497 272158241", "output": "4" }, { "input": "3 47\n378261451 163985731 230342101", "output": "3" }, { "input": "2 3\n247776868 480572137", "output": "1" }, { "input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796", "output": "7" }, { "input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085", "output": "40" }, { "input": "1 8\n55521105", "output": "1" }, { "input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843", "output": "44" }, { "input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601", "output": "22" }, { "input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105", "output": "20" }, { "input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629", "output": "44" }, { "input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191", "output": "8" }, { "input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529", "output": "38" }, { "input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547", "output": "18" }, { "input": "1 1\n44", "output": "0" }, { "input": "1 1\n4", "output": "1" }, { "input": "10 3\n444 447 774 777 7777 4447 4 7 7 4", "output": "8" } ]
1,687,325,404
2,147,483,647
Python 3
OK
TESTS
34
92
0
n,k = map(int,input().split()) nums = list(map(str,input().split())) cnt= 0 for i in nums : total = i.count("7")+i.count("4") if total<=k: cnt+=1 print(cnt)
Title: Roma and Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. Input Specification: The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has. The numbers in the lines are separated by single spaces. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['3 4\n1 2 4\n', '3 2\n447 44 77\n'] Demo Output: ['3\n', '2\n'] Note: In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
```python n,k = map(int,input().split()) nums = list(map(str,input().split())) cnt= 0 for i in nums : total = i.count("7")+i.count("4") if total<=k: cnt+=1 print(cnt) ```
3
169
B
Replacing Digits
PROGRAMMING
1,100
[ "greedy" ]
null
null
You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≤<=*i*<=≤<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. Each element in the sequence *s* can participate in no more than one replacing operation. Your task is to perform such sequence of replacements, that the given number *a* gets maximum value. You are allowed to use not all elements from *s*.
The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators. The given number *a* doesn't contain leading zeroes.
Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes.
[ "1024\n010\n", "987\n1234567\n" ]
[ "1124\n", "987\n" ]
none
1,000
[ { "input": "1024\n010", "output": "1124" }, { "input": "987\n1234567", "output": "987" }, { "input": "10\n1", "output": "11" }, { "input": "11\n1", "output": "11" }, { "input": "12\n2", "output": "22" }, { "input": "1\n0", "output": "1" }, { "input": "123456\n9999", "output": "999956" }, { "input": "909090\n000111", "output": "919191" }, { "input": "588\n24", "output": "588" }, { "input": "25206\n88", "output": "88206" }, { "input": "9776247464\n8629", "output": "9986647464" }, { "input": "3666566898\n3001", "output": "3666566898" }, { "input": "3338860467\n5848", "output": "8858864467" }, { "input": "9768757689\n1010", "output": "9768757689" }, { "input": "6669490269\n6240849376", "output": "9879696469" }, { "input": "1794210278\n50931901955213461294", "output": "9999965578" }, { "input": "6997854871\n15113453341706470344", "output": "7997876875" }, { "input": "8947769539\n22900332144661023400", "output": "9967769649" }, { "input": "9885783638\n20241242140301231211", "output": "9885784648" }, { "input": "1\n2", "output": "2" }, { "input": "1\n1234567890", "output": "9" }, { "input": "123\n987987", "output": "998" }, { "input": "1000\n32119", "output": "9321" }, { "input": "31\n4", "output": "41" }, { "input": "504\n91111", "output": "914" }, { "input": "100001\n23", "output": "320001" }, { "input": "87\n9", "output": "97" }, { "input": "786796787566545376\n00101", "output": "786796787566545376" }, { "input": "123456789012345678905764345\n00001", "output": "123456789112345678905764345" }, { "input": "111\n2222222299999999", "output": "999" }, { "input": "111\n789", "output": "987" }, { "input": "1\n99", "output": "9" }, { "input": "1099\n9", "output": "9099" }, { "input": "123\n456", "output": "654" } ]
1,679,517,109
2,147,483,647
Python 3
OK
TESTS
75
404
1,945,600
s = list(input()) a = sorted(input(), reverse = True) i = 0 # индексы по s j = 0 # индексы по a while i < len(s) and j < len(a): if a[j]>s[i]: s[i] = a[j] j+=1 i+=1 print(*s, sep = "")
Title: Replacing Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≤<=*i*<=≤<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. Each element in the sequence *s* can participate in no more than one replacing operation. Your task is to perform such sequence of replacements, that the given number *a* gets maximum value. You are allowed to use not all elements from *s*. Input Specification: The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators. The given number *a* doesn't contain leading zeroes. Output Specification: Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes. Demo Input: ['1024\n010\n', '987\n1234567\n'] Demo Output: ['1124\n', '987\n'] Note: none
```python s = list(input()) a = sorted(input(), reverse = True) i = 0 # индексы по s j = 0 # индексы по a while i < len(s) and j < len(a): if a[j]>s[i]: s[i] = a[j] j+=1 i+=1 print(*s, sep = "") ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,660,831,526
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
154
2,764,800
y=int(input()) w=int(input()) maximum = 0 if y>w: maximum=y else: maximum=w from fractions import * print (Fraction((7-maximum)/6))
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python y=int(input()) w=int(input()) maximum = 0 if y>w: maximum=y else: maximum=w from fractions import * print (Fraction((7-maximum)/6)) ```
-1
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", "output": "37 37" }, { "input": "40 10\n1 2 3 4 5 6 7 10 10 10", "output": "223 158" }, { "input": "1 1\n6", "output": "6 6" }, { "input": "1 2\n10 9", "output": "10 9" }, { "input": "2 1\n7", "output": "13 13" }, { "input": "2 2\n7 2", "output": "13 3" }, { "input": "3 2\n4 7", "output": "18 9" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "10 10\n3 1 2 2 1 1 2 1 2 3", "output": "20 13" }, { "input": "10 2\n7 3", "output": "34 34" }, { "input": "10 1\n19", "output": "145 145" }, { "input": "100 3\n29 36 35", "output": "1731 1731" }, { "input": "100 5\n3 38 36 35 2", "output": "2019 1941" }, { "input": "510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62", "output": "50279 5479" }, { "input": "510 123\n5 2 3 2 5 7 2 3 1 3 6 6 3 1 5 3 5 6 2 2 1 5 5 5 2 2 3 1 6 3 5 8 4 6 1 5 4 5 1 6 5 5 3 6 4 1 6 1 3 5 2 7 5 2 4 4 5 6 5 5 4 3 4 6 5 4 4 3 5 8 5 5 6 3 1 7 4 4 3 3 5 3 6 3 3 6 2 5 3 2 4 5 4 5 2 2 4 4 4 7 3 4 6 5 3 6 4 7 1 6 5 7 6 5 7 3 7 4 4 1 6 6 4", "output": "1501 1501" }, { "input": "610 33\n15 44 8 8 17 11 39 39 38 25 17 36 17 25 21 37 10 11 34 30 29 50 29 50 4 20 32 13 41 14 2 11 2", "output": "12204 8871" } ]
1,570,536,622
2,147,483,647
Python 3
OK
TESTS
33
280
0
n,m = map(int,input().split()) l = list(map(int,input().split())) min =0 max =0 temp = sorted(l) for i in range(n): if len(l) >0: l.sort(reverse = True) max += l[0] l[0] -= 1 if 0 in l: l.remove(0) min += temp[0] temp[0] -= 1 if 0 in temp: temp.remove(0) temp.sort() print(max,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())) min =0 max =0 temp = sorted(l) for i in range(n): if len(l) >0: l.sort(reverse = True) max += l[0] l[0] -= 1 if 0 in l: l.remove(0) min += temp[0] temp[0] -= 1 if 0 in temp: temp.remove(0) temp.sort() print(max,min) ```
3
839
C
Journey
PROGRAMMING
1,500
[ "dfs and similar", "dp", "graphs", "probabilities", "trees" ]
null
null
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities. Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value).
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities. Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road. It is guaranteed that one can reach any city from any other by the roads.
Print a number — the expected length of their journey. The journey starts in the city 1. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
[ "4\n1 2\n1 3\n2 4\n", "5\n1 2\n1 3\n3 4\n2 5\n" ]
[ "1.500000000000000\n", "2.000000000000000\n" ]
In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5. In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2.
1,500
[ { "input": "4\n1 2\n1 3\n2 4", "output": "1.500000000000000" }, { "input": "5\n1 2\n1 3\n3 4\n2 5", "output": "2.000000000000000" }, { "input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n54 1\n1 51\n1 43\n29 1\n56 1\n1 39\n32 1\n1 15\n1 17\n1 19\n1 40\n36 1\n48 1\n63 1\n1 7\n1 47\n1 13\n1 46\n60 1\n1 6\n23 1\n20 1\n1 52\n2 1\n26 1\n1 59\n1 66\n10 1\n1 62\n1 68\n1 55\n50 1\n33 1\n44 1\n1 34\n1 35\n1 61\n14 1\n67 1\n49 1", "output": "1.000000000000000" }, { "input": "10\n8 6\n9 10\n8 7\n1 4\n1 8\n9 5\n9 8\n2 5\n3 1", "output": "1.500000000000000" }, { "input": "1", "output": "0.000000000000000" } ]
1,630,129,639
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
61
7,168,000
from collections import defaultdict import sys inp = sys.stdin.readlines() print(inp) g = defaultdict(list) def add_edge(g, a, b): g[a].append(b) num_lines = int(inp.pop(0)) for line in inp: a = int(line.split()[0]) b = int(line.split()[1]) add_edge(g, a, b) def dfs(g, node): visited = [] stack = [node] leaves = 0.0 dist = 0.0 while(len(stack) != 0): s = stack.pop() if s not in visited: visited.append(s) if s not in g: leaves += 1.0 continue for neighbor in g[s]: stack.append(neighbor) dist += 1 return (dist/leaves) print(dfs(g, 1))
Title: Journey Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities. Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value). Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities. Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road. It is guaranteed that one can reach any city from any other by the roads. Output Specification: Print a number — the expected length of their journey. The journey starts in the city 1. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . Demo Input: ['4\n1 2\n1 3\n2 4\n', '5\n1 2\n1 3\n3 4\n2 5\n'] Demo Output: ['1.500000000000000\n', '2.000000000000000\n'] Note: In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5. In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2.
```python from collections import defaultdict import sys inp = sys.stdin.readlines() print(inp) g = defaultdict(list) def add_edge(g, a, b): g[a].append(b) num_lines = int(inp.pop(0)) for line in inp: a = int(line.split()[0]) b = int(line.split()[1]) add_edge(g, a, b) def dfs(g, node): visited = [] stack = [node] leaves = 0.0 dist = 0.0 while(len(stack) != 0): s = stack.pop() if s not in visited: visited.append(s) if s not in g: leaves += 1.0 continue for neighbor in g[s]: stack.append(neighbor) dist += 1 return (dist/leaves) print(dfs(g, 1)) ```
0
1,004
C
Sonya and Robots
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position. Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position. Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot. Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$. Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row.
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.
[ "5\n1 5 4 1 3\n", "7\n1 2 1 1 1 3 2\n" ]
[ "9\n", "7\n" ]
In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
1,500
[ { "input": "5\n1 5 4 1 3", "output": "9" }, { "input": "7\n1 2 1 1 1 3 2", "output": "7" }, { "input": "10\n2 2 4 4 3 1 1 2 3 2", "output": "14" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4", "output": "20" }, { "input": "1\n1", "output": "0" } ]
1,530,811,955
3,455
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
5
1,000
6,758,400
import os def sonya_and_robots() : cou = 0 unique = [] for i in range(len(arr) - 1) : ele = arr[i] if ele not in unique : unique.append(arr[i]) cou += len(set(arr[i + 1 :])) return cou size = input() arr = list(map(int, input().split())) print(sonya_and_robots())
Title: Sonya and Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position. Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position. Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot. Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$. Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet. Input Specification: The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. Output Specification: Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. Demo Input: ['5\n1 5 4 1 3\n', '7\n1 2 1 1 1 3 2\n'] Demo Output: ['9\n', '7\n'] Note: In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
```python import os def sonya_and_robots() : cou = 0 unique = [] for i in range(len(arr) - 1) : ele = arr[i] if ele not in unique : unique.append(arr[i]) cou += len(set(arr[i + 1 :])) return cou size = input() arr = list(map(int, input().split())) print(sonya_and_robots()) ```
0
353
B
Two Heaps
PROGRAMMING
1,900
[ "combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings" ]
null
null
Valera has 2·*n* cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses *n* cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap. Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
The first line contains integer *n* (1<=≤<=*n*<=≤<=100). The second line contains 2·*n* space-separated integers *a**i* (10<=≤<=*a**i*<=≤<=99), denoting the numbers on the cubes.
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·*n* numbers *b**i* (1<=≤<=*b**i*<=≤<=2). The numbers mean: the *i*-th cube belongs to the *b**i*-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
[ "1\n10 99\n", "2\n13 24 13 45\n" ]
[ "1\n2 1 \n", "4\n1 2 2 1 \n" ]
In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one. In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
1,500
[ { "input": "1\n10 99", "output": "1\n2 1 " }, { "input": "2\n13 24 13 45", "output": "4\n1 2 2 1 " }, { "input": "5\n21 60 18 21 17 39 58 74 62 34", "output": "25\n1 1 1 2 2 1 2 1 2 2 " }, { "input": "10\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98", "output": "100\n1 2 1 2 2 2 2 1 2 2 1 1 1 2 1 1 1 2 2 1 " }, { "input": "20\n80 56 58 61 75 60 25 49 59 15 43 39 21 73 67 13 75 31 18 87 32 44 53 15 53 76 79 94 85 80 27 25 48 78 32 18 20 78 46 37", "output": "400\n1 2 1 2 1 1 1 1 2 1 1 2 2 2 1 2 2 2 1 2 1 2 1 2 2 1 2 1 1 2 1 2 2 1 2 2 1 2 1 1 " }, { "input": "50\n49 13 81 20 73 62 19 49 65 95 32 84 24 96 51 57 53 83 40 44 26 65 78 80 92 87 87 95 56 46 22 44 69 80 41 61 97 92 58 53 42 78 53 19 47 36 25 77 65 81 14 61 38 99 27 58 67 37 67 80 77 51 32 43 31 48 19 79 31 91 46 97 91 71 27 63 22 84 73 73 89 44 34 84 70 23 45 31 56 73 83 38 68 45 99 33 83 86 87 80", "output": "1936\n1 2 1 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 1 1 2 1 2 1 2 1 2 1 1 1 1 1 2 1 2 1 1 1 2 1 2 2 1 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 1 2 2 2 2 2 2 2 2 1 2 1 2 2 " }, { "input": "2\n10 10 10 11", "output": "2\n1 2 1 2 " } ]
1,591,213,067
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
280
0
n=int(input()) arr=list(map(int,input().split())) r=[] a={} b={} la=0 lb=0 for i in arr: if i not in a and la<n: a[i]=1 r.append("1") la+=1 elif i not in b and lb<n: b[i]=1 lb+=1 r.append("2") elif lb<n: b[i]+=1 lb+=1 r.append("2") else: a[i]+=1 la+=1 r.append("1") print(len(a)*len(b)) print(" ".join(r))
Title: Two Heaps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has 2·*n* cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses *n* cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap. Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100). The second line contains 2·*n* space-separated integers *a**i* (10<=≤<=*a**i*<=≤<=99), denoting the numbers on the cubes. Output Specification: In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·*n* numbers *b**i* (1<=≤<=*b**i*<=≤<=2). The numbers mean: the *i*-th cube belongs to the *b**i*-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them. Demo Input: ['1\n10 99\n', '2\n13 24 13 45\n'] Demo Output: ['1\n2 1 \n', '4\n1 2 2 1 \n'] Note: In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one. In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
```python n=int(input()) arr=list(map(int,input().split())) r=[] a={} b={} la=0 lb=0 for i in arr: if i not in a and la<n: a[i]=1 r.append("1") la+=1 elif i not in b and lb<n: b[i]=1 lb+=1 r.append("2") elif lb<n: b[i]+=1 lb+=1 r.append("2") else: a[i]+=1 la+=1 r.append("1") print(len(a)*len(b)) print(" ".join(r)) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,570,997,420
2,147,483,647
Python 3
OK
TESTS
32
218
0
import time def identifyOddness(numArr): qeven = 0 qodd = 0 for x in numArr: if x % 2 == 0: qeven += 1 else: qodd +=1 if qeven == 1: for i, num in enumerate(numArr): if num % 2 == 0: return i elif qodd == 1: for i, num in enumerate(numArr): if num % 2 != 0: return i nums = input() aNums = [int(x) for x in input().split()] start_time = time.time() p = identifyOddness(aNums) print(p + 1) # print("%fs" % (time.time() - start_time))
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python import time def identifyOddness(numArr): qeven = 0 qodd = 0 for x in numArr: if x % 2 == 0: qeven += 1 else: qodd +=1 if qeven == 1: for i, num in enumerate(numArr): if num % 2 == 0: return i elif qodd == 1: for i, num in enumerate(numArr): if num % 2 != 0: return i nums = input() aNums = [int(x) for x in input().split()] start_time = time.time() p = identifyOddness(aNums) print(p + 1) # print("%fs" % (time.time() - start_time)) ```
3.9455
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" }, { "input": "4\n5 4 5 4", "output": "-1" }, { "input": "7\n3 4 5 5 5 1 2", "output": "2" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "5\n5 4 1 2 3", "output": "-1" }, { "input": "4\n6 1 2 7", "output": "-1" }, { "input": "5\n4 5 6 2 3", "output": "2" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 2 2 1", "output": "1" }, { "input": "9\n4 5 6 7 1 2 3 4 10", "output": "-1" }, { "input": "7\n2 3 4 1 2 3 4", "output": "-1" }, { "input": "6\n1 2 1 2 1 2", "output": "-1" }, { "input": "3\n3 2 1", "output": "-1" }, { "input": "4\n1 4 4 1", "output": "1" }, { "input": "5\n1 2 1 1 1", "output": "3" }, { "input": "5\n4 6 7 3 5", "output": "-1" }, { "input": "4\n2 3 1 4", "output": "-1" }, { "input": "5\n5 4 3 2 1", "output": "-1" }, { "input": "4\n2 4 1 4", "output": "-1" }, { "input": "6\n4 5 6 1 2 7", "output": "-1" }, { "input": "6\n1 2 3 1 1 1", "output": "3" }, { "input": "5\n1 3 3 3 1", "output": "1" }, { "input": "6\n5 6 7 5 5 5", "output": "3" }, { "input": "5\n3 4 2 1 2", "output": "-1" }, { "input": "3\n3 4 2", "output": "1" }, { "input": "6\n1 1 2 2 1 1", "output": "2" }, { "input": "4\n2 3 4 2", "output": "1" }, { "input": "5\n3 5 7 7 3", "output": "1" }, { "input": "4\n1 1 4 1", "output": "1" }, { "input": "7\n1 5 6 1 1 1 1", "output": "4" }, { "input": "5\n7 8 6 7 8", "output": "-1" }, { "input": "4\n2 4 1 3", "output": "-1" } ]
1,661,897,091
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
93
12,492,800
from collections import deque q = deque() n = int(input()) a = [int(x) for x in input().split()] for i in a:q.append(i) ans = 0 while 1: if q[-1]<=q[0]: ans+=1 q.appendleft(q.pop()) else: break if ans>n:break a.sort() print(ans if a==list(q) else -1)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. 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 from collections import deque q = deque() n = int(input()) a = [int(x) for x in input().split()] for i in a:q.append(i) ans = 0 while 1: if q[-1]<=q[0]: ans+=1 q.appendleft(q.pop()) else: break if ans>n:break a.sort() print(ans if a==list(q) else -1) ```
0
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 7", "output": "5" }, { "input": "14 5 5", "output": "6" }, { "input": "16 6 9", "output": "10" }, { "input": "20 13 17", "output": "7" }, { "input": "22 4 8", "output": "9" }, { "input": "23 8 14", "output": "15" }, { "input": "26 18 22", "output": "8" }, { "input": "28 6 1", "output": "2" }, { "input": "29 5 23", "output": "24" }, { "input": "32 27 15", "output": "5" }, { "input": "33 11 5", "output": "6" }, { "input": "37 21 15", "output": "16" }, { "input": "39 34 33", "output": "5" }, { "input": "41 27 11", "output": "12" }, { "input": "42 25 16", "output": "17" }, { "input": "45 7 43", "output": "38" }, { "input": "47 16 17", "output": "18" }, { "input": "49 11 37", "output": "38" }, { "input": "51 38 39", "output": "13" }, { "input": "52 29 7", "output": "8" }, { "input": "56 43 12", "output": "13" }, { "input": "58 57 28", "output": "1" }, { "input": "59 12 39", "output": "40" }, { "input": "62 9 52", "output": "53" }, { "input": "63 29 44", "output": "34" }, { "input": "65 30 22", "output": "23" }, { "input": "66 27 38", "output": "39" }, { "input": "71 33 53", "output": "38" }, { "input": "73 14 12", "output": "13" }, { "input": "73 37 35", "output": "36" }, { "input": "76 69 44", "output": "7" }, { "input": "79 25 20", "output": "21" }, { "input": "81 60 20", "output": "21" }, { "input": "81 79 14", "output": "2" }, { "input": "84 0 42", "output": "43" }, { "input": "88 79 8", "output": "9" }, { "input": "90 76 59", "output": "14" }, { "input": "92 2 22", "output": "23" }, { "input": "94 5 88", "output": "89" }, { "input": "94 62 48", "output": "32" }, { "input": "96 22 72", "output": "73" }, { "input": "100 11 88", "output": "89" }, { "input": "100 81 91", "output": "19" }, { "input": "1 0 0", "output": "1" } ]
1,685,656,578
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
204,800
import _py_abc n = print(523+0) x = print(100+211) y = print (323+200) new_var = ("n ≤ 323,  100 <211, 0 ≤ 100") new_var("323 ≤ 200,  211<100, 0 ≤ 523") x =int ("b: 100") n =int ("b: 211") print ('a + b =', 100 + 211) print('a + b =', 523 + 0)
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. Input Specification: The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100). Output Specification: Print the single number — the number of the sought positions. Demo Input: ['3 1 1\n', '5 2 3\n'] Demo Output: ['2\n', '3\n'] Note: The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
```python import _py_abc n = print(523+0) x = print(100+211) y = print (323+200) new_var = ("n ≤ 323,  100 <211, 0 ≤ 100") new_var("323 ≤ 200,  211<100, 0 ≤ 523") x =int ("b: 100") n =int ("b: 211") print ('a + b =', 100 + 211) print('a + b =', 523 + 0) ```
-1
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4", "output": "-1" }, { "input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4", "output": "-1" }, { "input": "1\n2 4", "output": "0" }, { "input": "1\n1 1", "output": "-1" }, { "input": "1\n1 2", "output": "-1" }, { "input": "2\n1 1\n3 3", "output": "0" }, { "input": "2\n1 1\n2 2", "output": "-1" }, { "input": "2\n1 1\n1 2", "output": "-1" }, { "input": "5\n1 2\n6 6\n1 1\n3 3\n6 1", "output": "1" }, { "input": "5\n5 4\n2 6\n6 2\n1 4\n6 2", "output": "0" }, { "input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1", "output": "0" }, { "input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5", "output": "-1" }, { "input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1", "output": "1" }, { "input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4", "output": "-1" }, { "input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2", "output": "0" }, { "input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5", "output": "-1" }, { "input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4", "output": "-1" }, { "input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4", "output": "-1" }, { "input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6", "output": "1" }, { "input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5", "output": "1" }, { "input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3", "output": "1" }, { "input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5", "output": "1" }, { "input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5", "output": "-1" }, { "input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6", "output": "-1" }, { "input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1", "output": "-1" }, { "input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6", "output": "-1" }, { "input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4", "output": "1" }, { "input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6", "output": "-1" }, { "input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2", "output": "0" }, { "input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3", "output": "-1" }, { "input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3", "output": "-1" }, { "input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4", "output": "-1" }, { "input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5", "output": "1" }, { "input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1", "output": "1" }, { "input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5", "output": "-1" }, { "input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2", "output": "0" }, { "input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1", "output": "0" }, { "input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2", "output": "1" }, { "input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2", "output": "0" }, { "input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2", "output": "-1" }, { "input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5", "output": "0" }, { "input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1", "output": "-1" }, { "input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5", "output": "-1" }, { "input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3", "output": "-1" }, { "input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5", "output": "0" }, { "input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4", "output": "-1" }, { "input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2", "output": "-1" }, { "input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2", "output": "1" }, { "input": "1\n2 2", "output": "0" }, { "input": "3\n2 4\n6 6\n3 3", "output": "-1" }, { "input": "2\n3 6\n4 1", "output": "1" }, { "input": "3\n1 1\n1 1\n3 3", "output": "-1" }, { "input": "3\n2 3\n1 1\n2 3", "output": "1" }, { "input": "3\n2 2\n2 1\n1 2", "output": "1" }, { "input": "3\n1 1\n1 1\n1 1", "output": "-1" } ]
1,626,631,946
2,147,483,647
PyPy 3
OK
TESTS
59
216
20,172,800
n = int(input()) a=[] b=[] for i in range(n): t, p = map(int,input().split()) a.append(t) b.append(p) sum1 = sum(a) sum2 = sum(b) if(sum2%2==0 and sum1%2==0): print(0) elif(sum2%2==1 and sum1%2==0): print(-1) elif(sum2%2==0 and sum1%2==1): print(-1) else: flag=0 for i in range(n): if(a[i]%2!=b[i]%2): flag=1 break if(flag==1): print(1) else: print(-1)
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. Output Specification: Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. Demo Input: ['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
```python n = int(input()) a=[] b=[] for i in range(n): t, p = map(int,input().split()) a.append(t) b.append(p) sum1 = sum(a) sum2 = sum(b) if(sum2%2==0 and sum1%2==0): print(0) elif(sum2%2==1 and sum1%2==0): print(-1) elif(sum2%2==0 and sum1%2==1): print(-1) else: flag=0 for i in range(n): if(a[i]%2!=b[i]%2): flag=1 break if(flag==1): print(1) else: print(-1) ```
3
288
C
Polo the Penguin and XOR operation
PROGRAMMING
1,700
[ "implementation", "math" ]
null
null
Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to *n*, inclusive. For permutation *p*<==<=*p*0,<=*p*1,<=...,<=*p**n*, Polo has defined its beauty — number . Expression means applying the operation of bitwise excluding "OR" to numbers *x* and *y*. This operation exists in all modern programming languages, for example, in language C++ and Java it is represented as "^" and in Pascal — as "xor". Help him find among all permutations of integers from 0 to *n* the permutation with the maximum beauty.
The single line contains a positive integer *n* (1<=≤<=*n*<=≤<=106).
In the first line print integer *m* the maximum possible beauty. In the second line print any permutation of integers from 0 to *n* with the beauty equal to *m*. If there are several suitable permutations, you are allowed to print any of them.
[ "4\n" ]
[ "20\n0 2 1 4 3\n" ]
none
1,500
[ { "input": "4", "output": "20\n0 2 1 4 3" }, { "input": "7", "output": "56\n7 6 5 4 3 2 1 0" }, { "input": "1", "output": "2\n1 0" }, { "input": "2", "output": "6\n0 2 1" }, { "input": "3", "output": "12\n3 2 1 0" }, { "input": "8", "output": "72\n0 6 5 4 3 2 1 8 7" }, { "input": "10", "output": "110\n0 2 1 4 3 10 9 8 7 6 5" }, { "input": "47", "output": "2256\n15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16" }, { "input": "74", "output": "5550\n0 2 1 4 3 10 9 8 7 6 5 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53" }, { "input": "99", "output": "9900\n3 2 1 0 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28" }, { "input": "128", "output": "16512\n0 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 128 127" }, { "input": "257", "output": "66306\n1 0 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 ..." }, { "input": "1000000", "output": "1000001000000\n0 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 64 63 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369..." }, { "input": "77845", "output": "6059921870\n1 0 5 4 3 2 9 8 7 6 21 20 19 18 17 16 15 14 13 12 11 10 4073 4072 4071 4070 4069 4068 4067 4066 4065 4064 4063 4062 4061 4060 4059 4058 4057 4056 4055 4054 4053 4052 4051 4050 4049 4048 4047 4046 4045 4044 4043 4042 4041 4040 4039 4038 4037 4036 4035 4034 4033 4032 4031 4030 4029 4028 4027 4026 4025 4024 4023 4022 4021 4020 4019 4018 4017 4016 4015 4014 4013 4012 4011 4010 4009 4008 4007 4006 4005 4004 4003 4002 4001 4000 3999 3998 3997 3996 3995 3994 3993 3992 3991 3990 3989 3988 3987 3986 398..." }, { "input": "100000", "output": "10000100000\n0 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 31 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105..." }, { "input": "100001", "output": "10000300002\n1 0 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 33 32 31 30 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 10..." }, { "input": "999999", "output": "999999000000\n63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369..." }, { "input": "777777", "output": "604937839506\n1 0 13 12 11 10 9 8 7 6 5 4 3 2 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 3..." }, { "input": "687500", "output": "472656937500\n0 2 1 12 11 10 9 8 7 6 5 4 3 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 360..." }, { "input": "17", "output": "306\n1 0 13 12 11 10 9 8 7 6 5 4 3 2 17 16 15 14" }, { "input": "18", "output": "342\n0 2 1 12 11 10 9 8 7 6 5 4 3 18 17 16 15 14 13" }, { "input": "19", "output": "380\n3 2 1 0 11 10 9 8 7 6 5 4 19 18 17 16 15 14 13 12" }, { "input": "20", "output": "420\n0 2 1 4 3 10 9 8 7 6 5 20 19 18 17 16 15 14 13 12 11" }, { "input": "4587", "output": "21045156\n3 2 1 0 11 10 9 8 7 6 5 4 19 18 17 16 15 14 13 12 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 475 474 473 472 471 470 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379..." }, { "input": "15475", "output": "239491100\n3 2 1 0 11 10 9 8 7 6 5 4 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 907 906 905 904 903 902 901 900 899 898 897 896 895 894 893 892 891 890 889 888 887 886 885 884 883 882 881 880 879 878 877 876 875 874 873 872 87..." }, { "input": "68450", "output": "4685470950\n0 2 1 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 ..." }, { "input": "6100", "output": "37216100\n0 2 1 4 3 10 9 8 7 6 5 20 19 18 17 16 15 14 13 12 11 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 2004 2003 2002 2001 2000 1999 1998 1997 1996 1995 1994 1993 1992 1991 1990 1989 1988 1987 1986 1985 1984 1983 1982 1981 1980 1979 1978 1977 1976 1975 1974 1973 1972 1971 1970 1969 1968 1967 1966 1965 1964 1963 1962 1961 1960 1959 1958 1957 1956 1955 1954 1953 1952 1951 1950 1949 1948 1947 1946 1945 1944 1943 1942 1941 1940 1939 1938 1937 1936 1935 1934 1933 1932 1931 1930 1929 19..." }, { "input": "1047", "output": "1097256\n7 6 5 4 3 2 1 0 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 899 898 897 896 895 894 893 892 891 890 ..." }, { "input": "670041", "output": "448955611722\n1 0 5 4 3 2 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 37 36 35 34 33 32 31 30 29 28 27 26 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 1..." }, { "input": "875495", "output": "766492370520\n7 6 5 4 3 2 1 0 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901 900 899 898 897 896 895 894 893 892 891..." }, { "input": "687548", "output": "472722939852\n0 2 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 66 65 64 63 62 61 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 36..." }, { "input": "154781", "output": "23957312742\n1 0 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 10..." }, { "input": "684501", "output": "468542303502\n1 0 5 4 3 2 9 8 7 6 21 20 19 18 17 16 15 14 13 12 11 10 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 469 468 467 466 465 464 463 462 461 460 459 458 457 456 455 454 453 452 451 450 449 448 447 446 445 444 443 442 441 440 439 438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 3..." }, { "input": "754810", "output": "569738890910\n0 2 1 4 3 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 900 899 898 897 896 895 894 893 892 891 890 889 888 887 886 885 884 883 882 881 880 879 878 877 876 875 874 873 872..." }, { "input": "987548", "output": "975252039852\n0 2 1 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 36..." }, { "input": "348754", "output": "121629701270\n0 2 1 12 11 10 9 8 7 6 5 4 3 18 17 16 15 14 13 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 36..." }, { "input": "20", "output": "420\n0 2 1 4 3 10 9 8 7 6 5 20 19 18 17 16 15 14 13 12 11" }, { "input": "11", "output": "132\n3 2 1 0 11 10 9 8 7 6 5 4" }, { "input": "12", "output": "156\n0 2 1 12 11 10 9 8 7 6 5 4 3" }, { "input": "13", "output": "182\n1 0 13 12 11 10 9 8 7 6 5 4 3 2" }, { "input": "14", "output": "210\n0 14 13 12 11 10 9 8 7 6 5 4 3 2 1" }, { "input": "15", "output": "240\n15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0" } ]
1,689,488,417
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
0
from itertools import permutations n = int(input()) maxi = 0 ans = None for i in permutations([i for i in range(n+1)]): curr = 0 for j in range(len(i)): curr+=i[j]^j if curr>maxi: maxi = curr ans = i print(maxi) for i in ans : print(i,end=" ")
Title: Polo the Penguin and XOR operation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to *n*, inclusive. For permutation *p*<==<=*p*0,<=*p*1,<=...,<=*p**n*, Polo has defined its beauty — number . Expression means applying the operation of bitwise excluding "OR" to numbers *x* and *y*. This operation exists in all modern programming languages, for example, in language C++ and Java it is represented as "^" and in Pascal — as "xor". Help him find among all permutations of integers from 0 to *n* the permutation with the maximum beauty. Input Specification: The single line contains a positive integer *n* (1<=≤<=*n*<=≤<=106). Output Specification: In the first line print integer *m* the maximum possible beauty. In the second line print any permutation of integers from 0 to *n* with the beauty equal to *m*. If there are several suitable permutations, you are allowed to print any of them. Demo Input: ['4\n'] Demo Output: ['20\n0 2 1 4 3\n'] Note: none
```python from itertools import permutations n = int(input()) maxi = 0 ans = None for i in permutations([i for i in range(n+1)]): curr = 0 for j in range(len(i)): curr+=i[j]^j if curr>maxi: maxi = curr ans = i print(maxi) for i in ans : print(i,end=" ") ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,671,679,093
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
a = input() b = input() if len(a) != len(b): print("NO") else: for i in range(len(a)): if a[i] != b[len(a)-1-i]: break if i == len(a) -1: print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python a = input() b = input() if len(a) != len(b): print("NO") else: for i in range(len(a)): if a[i] != b[len(a)-1-i]: break if i == len(a) -1: print("YES") else: print("NO") ```
0
382
C
Arithmetic Progression
PROGRAMMING
1,700
[ "implementation", "sortings" ]
null
null
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills: For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not. Alexander has *n* cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting *n*<=+<=1 cards to make an arithmetic progression (Alexander has to use all of his cards). Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
[ "3\n4 1 7\n", "1\n10\n", "4\n1 3 5 9\n", "4\n4 3 4 5\n", "2\n2 4\n" ]
[ "2\n-2 10\n", "-1\n", "1\n7\n", "0\n", "3\n0 3 6\n" ]
none
1,500
[ { "input": "3\n4 1 7", "output": "2\n-2 10" }, { "input": "1\n10", "output": "-1" }, { "input": "4\n1 3 5 9", "output": "1\n7" }, { "input": "4\n4 3 4 5", "output": "0" }, { "input": "2\n2 4", "output": "3\n0 3 6" }, { "input": "4\n1 3 4 5", "output": "1\n2" }, { "input": "2\n3 3", "output": "1\n3" }, { "input": "2\n13 2", "output": "2\n-9 24" }, { "input": "5\n2 2 2 2 2", "output": "1\n2" }, { "input": "6\n11 1 7 9 5 13", "output": "1\n3" }, { "input": "2\n100000000 1", "output": "2\n-99999998 199999999" }, { "input": "5\n2 3 1 4 6", "output": "1\n5" }, { "input": "5\n1 2 2 3 4", "output": "0" }, { "input": "3\n1 4 2", "output": "1\n3" }, { "input": "3\n8 8 8", "output": "1\n8" }, { "input": "5\n2 2 2 2 3", "output": "0" }, { "input": "1\n100000000", "output": "-1" }, { "input": "20\n27 6 3 18 54 33 9 15 39 12 57 48 21 51 60 30 24 36 42 45", "output": "2\n0 63" }, { "input": "40\n100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000", "output": "1\n100000000" }, { "input": "49\n81787 163451 104059 89211 96635 133755 148603 141179 159739 122619 123 144891 70651 11259 63227 3835 44667 37243 100347 26107 137467 18683 156027 59515 22395 40955 111483 52091 7547 85499 107771 178299 115195 152315 74363 126331 33531 130043 14971 48379 167163 182011 170875 78075 174587 55803 66939 29819 118907", "output": "1\n92923" }, { "input": "9\n1 2 3 3 4 4 5 5 6", "output": "0" }, { "input": "7\n1 1 2 3 4 5 6", "output": "0" }, { "input": "2\n4 1", "output": "2\n-2 7" }, { "input": "2\n2 100000000", "output": "3\n-99999996 50000001 199999998" }, { "input": "8\n1 2 3 4 11 12 13 14", "output": "0" }, { "input": "7\n5 40 45 50 55 60 65", "output": "0" }, { "input": "1\n1", "output": "-1" }, { "input": "2\n1 1", "output": "1\n1" }, { "input": "2\n100000000 2", "output": "3\n-99999996 50000001 199999998" }, { "input": "3\n2 2 3", "output": "0" }, { "input": "5\n1 3 5 9 13", "output": "0" }, { "input": "5\n1 2 4 8 16", "output": "0" }, { "input": "3\n2 2 5", "output": "0" }, { "input": "5\n1 2 3 4 8", "output": "0" }, { "input": "3\n1 3 4", "output": "1\n2" }, { "input": "5\n1 2 4 6 7", "output": "0" }, { "input": "4\n1 5 9 11", "output": "0" }, { "input": "4\n3 4 5 9", "output": "0" }, { "input": "4\n1 5 6 8", "output": "0" }, { "input": "4\n2 6 8 12", "output": "0" }, { "input": "5\n1 2 3 5 7", "output": "0" }, { "input": "6\n1 2 3 4 6 8", "output": "0" } ]
1,552,307,331
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
124
0
'''input 3 4 1 7 ''' from sys import stdin import math def check_for_ap(arr, n): diff = arr[1] - arr[0] for i in range(2, n): if arr[i] - arr[i - 1] != diff: return False return True def get_diff(arr): return arr[1] - arr[0] def get_difference(arr, n): difference = [] for i in range(1, n): difference.append(arr[i] - arr[i - 1]) return difference def insert_into(arr, n): difference = get_difference(arr, n) culprit = max(difference) for i in range(1, n): if arr[i] - arr[i - 1] == culprit: num = (arr[i] + arr[i - 1]) // 2 arr.insert(i, (arr[i] + arr[i - 1]) // 2) if check_for_ap(arr, n + 1): print(1) print(num) exit() else: print(0) exit() # main starts n = int(stdin.readline().strip()) arr = list(map(int, stdin.readline().split())) arr.sort() if len(arr) == 1: print(-1) exit() else: if check_for_ap(arr, n): if len(arr) == 2: if ((arr[1] - arr[0])% 2) == 0: diff = get_diff(arr) print(3) print(arr[0] - diff, (arr[0] + arr[1]) // 2 , arr[1] + diff) else: diff = arr[1] - arr[0] print(arr[0] - diff, arr[1] + diff) else: diff = get_diff(arr) print(2) print(arr[0] - diff, arr[-1] + diff) else: insert_into(arr, n)
Title: Arithmetic Progression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills: For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not. Alexander has *n* cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting *n*<=+<=1 cards to make an arithmetic progression (Alexander has to use all of his cards). Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108. Output Specification: If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples). Demo Input: ['3\n4 1 7\n', '1\n10\n', '4\n1 3 5 9\n', '4\n4 3 4 5\n', '2\n2 4\n'] Demo Output: ['2\n-2 10\n', '-1\n', '1\n7\n', '0\n', '3\n0 3 6\n'] Note: none
```python '''input 3 4 1 7 ''' from sys import stdin import math def check_for_ap(arr, n): diff = arr[1] - arr[0] for i in range(2, n): if arr[i] - arr[i - 1] != diff: return False return True def get_diff(arr): return arr[1] - arr[0] def get_difference(arr, n): difference = [] for i in range(1, n): difference.append(arr[i] - arr[i - 1]) return difference def insert_into(arr, n): difference = get_difference(arr, n) culprit = max(difference) for i in range(1, n): if arr[i] - arr[i - 1] == culprit: num = (arr[i] + arr[i - 1]) // 2 arr.insert(i, (arr[i] + arr[i - 1]) // 2) if check_for_ap(arr, n + 1): print(1) print(num) exit() else: print(0) exit() # main starts n = int(stdin.readline().strip()) arr = list(map(int, stdin.readline().split())) arr.sort() if len(arr) == 1: print(-1) exit() else: if check_for_ap(arr, n): if len(arr) == 2: if ((arr[1] - arr[0])% 2) == 0: diff = get_diff(arr) print(3) print(arr[0] - diff, (arr[0] + arr[1]) // 2 , arr[1] + diff) else: diff = arr[1] - arr[0] print(arr[0] - diff, arr[1] + diff) else: diff = get_diff(arr) print(2) print(arr[0] - diff, arr[-1] + diff) else: insert_into(arr, n) ```
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,698,261,493
2,147,483,647
Python 3
OK
TESTS
50
46
0
#A. Brain's Photos tam = [int(x) for x in input().split(' ')] r = tam[0] c = tam[1] matriz = [] lista = [] for i in range(r): lista = [x for x in input().split(' ')] matriz.append(lista) cont = 0 for i in range(r): for j in range(c): if matriz[i][j] == 'C' or matriz[i][j] == 'Y' or matriz[i][j] == 'M': cont += 1 if cont > 0: print('#Color') else: print('#Black&White')
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python #A. Brain's Photos tam = [int(x) for x in input().split(' ')] r = tam[0] c = tam[1] matriz = [] lista = [] for i in range(r): lista = [x for x in input().split(' ')] matriz.append(lista) cont = 0 for i in range(r): for j in range(c): if matriz[i][j] == 'C' or matriz[i][j] == 'Y' or matriz[i][j] == 'M': cont += 1 if cont > 0: print('#Color') else: print('#Black&White') ```
3
839
B
Game of the Rows
PROGRAMMING
1,900
[ "brute force", "greedy", "implementation" ]
null
null
Daenerys Targaryen has an army consisting of *k* groups of soldiers, the *i*-th group contains *a**i* soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has *n* rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1,<=2}, {3,<=4}, {4,<=5}, {5,<=6} or {7,<=8}. Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats. Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10000, 1<=≤<=*k*<=≤<=100) — the number of rows and the number of groups of soldiers, respectively. The second line contains *k* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=10000), where *a**i* denotes the number of soldiers in the *i*-th group. It is guaranteed that *a*1<=+<=*a*2<=+<=...<=+<=*a**k*<=≤<=8·*n*.
If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes). You can choose the case (lower or upper) for each letter arbitrary.
[ "2 2\n5 8\n", "1 2\n7 1\n", "1 2\n4 4\n", "1 4\n2 2 1 2\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n" ]
In the first sample, Daenerys can place the soldiers like in the figure below: In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group. In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats. In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).
1,000
[ { "input": "2 2\n5 8", "output": "YES" }, { "input": "1 2\n7 1", "output": "NO" }, { "input": "1 2\n4 4", "output": "YES" }, { "input": "1 4\n2 2 1 2", "output": "YES" }, { "input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9938", "output": "YES" }, { "input": "100 15\n165 26 83 64 235 48 36 51 3 18 5 10 9 6 5", "output": "YES" }, { "input": "1 4\n2 2 2 2", "output": "NO" }, { "input": "5691 91\n6573 1666 2158 2591 4636 886 263 4217 389 29 1513 1172 617 2012 1855 798 1588 979 152 37 890 375 1091 839 385 382 1 255 117 289 119 224 182 69 19 71 115 13 4 22 35 2 60 12 6 12 19 9 3 2 2 6 5 1 7 7 3 1 5 1 7 1 4 1 1 3 2 1 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5631", "output": "NO" }, { "input": "2000 50\n203 89 1359 3105 898 1381 248 365 108 766 961 630 265 819 838 125 1751 289 177 81 131 564 102 95 49 74 92 101 19 17 156 5 5 4 20 9 25 16 16 2 8 5 4 2 1 3 4 1 3 2", "output": "NO" }, { "input": "10000 100\n800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800", "output": "YES" }, { "input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 2050 1074 605 979 1724 1608 672 88 1243 129 718 544 3590 37 187 600 738 34 64 316 58 6 84 252 75 68 40 68 4 29 29 8 13 11 5 1 5 1 3 2 1 1 1 2 3 4 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 3", "output": "NO" }, { "input": "8459 91\n778 338 725 1297 115 540 1452 2708 193 1806 1496 1326 2648 176 199 93 342 3901 2393 2718 800 3434 657 4037 291 690 1957 3280 73 6011 2791 1987 440 455 444 155 261 234 829 1309 1164 616 34 627 107 213 52 110 323 81 98 8 7 73 20 12 56 3 40 12 8 7 69 1 14 3 6 2 6 8 3 5 4 4 3 1 1 4 2 1 1 1 8 2 2 2 1 1 1 2 8421", "output": "NO" }, { "input": "1 3\n2 3 2", "output": "YES" }, { "input": "10000 91\n2351 1402 1137 2629 4718 1138 1839 1339 2184 2387 165 370 918 1476 2717 879 1152 5367 3940 608 941 766 1256 656 2768 916 4176 489 1989 1633 2725 2329 2795 1970 667 340 1275 120 870 488 225 59 64 255 207 3 37 127 19 224 34 283 144 50 132 60 57 29 18 6 7 4 4 15 3 5 1 10 5 2 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 9948", "output": "YES" }, { "input": "10000 83\n64 612 2940 2274 1481 1713 860 1264 104 5616 2574 5292 4039 292 1416 854 3854 1140 4344 3904 1720 1968 442 884 2032 875 291 677 2780 3074 3043 2997 407 727 344 511 156 321 134 51 382 336 591 52 134 39 104 10 20 15 24 2 70 39 14 16 16 25 1 6 2 2 1 1 1 2 4 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 9968", "output": "YES" }, { "input": "4000 71\n940 1807 57 715 532 212 3842 2180 2283 744 1453 800 1945 380 2903 293 633 391 2866 256 102 46 228 1099 434 210 244 14 27 4 63 53 3 9 36 25 1 12 2 14 12 28 2 28 8 5 11 8 2 3 6 4 1 1 1 3 2 1 1 1 2 2 1 1 1 1 1 2 1 1 3966", "output": "YES" }, { "input": "3403 59\n1269 1612 453 795 1216 941 19 44 1796 324 2019 1397 651 382 841 2003 3013 638 1007 1001 351 95 394 149 125 13 116 183 20 78 208 19 152 10 151 177 16 23 17 22 8 1 3 2 6 1 5 3 13 1 8 4 3 4 4 4 2 2 3378", "output": "YES" }, { "input": "2393 33\n1381 2210 492 3394 912 2927 1189 269 66 102 104 969 395 385 369 354 251 28 203 334 20 10 156 29 61 13 30 4 1 32 2 2 2436", "output": "YES" }, { "input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9939", "output": "NO" }, { "input": "10000 89\n1001 1531 2489 457 1415 617 2057 2658 3030 789 2500 3420 1550 376 720 78 506 293 1978 383 3195 2036 891 1741 1817 486 2650 360 2250 2531 3250 1612 2759 603 5321 1319 791 1507 265 174 877 1861 572 172 580 536 777 165 169 11 125 31 186 113 78 27 25 37 8 21 48 24 4 33 35 13 15 1 3 2 2 8 3 5 1 1 6 1 1 2 1 1 2 2 1 1 2 1 9953", "output": "NO" }, { "input": "4 16\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "NO" }, { "input": "10000 71\n110 14 2362 260 423 881 1296 3904 1664 849 57 631 1922 917 4832 1339 3398 4578 59 2663 2223 698 4002 3013 747 699 1230 2750 239 1409 6291 2133 1172 5824 181 797 26 281 574 557 19 82 624 387 278 53 64 163 22 617 15 35 42 48 14 140 171 36 28 22 5 49 17 5 10 14 13 1 3 3 9979", "output": "NO" }, { "input": "3495 83\n2775 2523 1178 512 3171 1159 1382 2146 2192 1823 799 231 502 16 99 309 656 665 222 285 11 106 244 137 241 45 41 29 485 6 62 38 94 5 7 93 48 5 10 13 2 1 2 1 4 8 5 9 4 6 1 1 1 3 4 3 7 1 2 3 1 1 7 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3443", "output": "NO" }, { "input": "1000 40\n1701 1203 67 464 1884 761 11 559 29 115 405 133 174 63 147 93 41 19 1 15 41 8 33 4 4 1 4 1 1 2 1 2 1 1 2 1 1 2 1 4", "output": "NO" }, { "input": "347 20\n55 390 555 426 140 360 29 115 23 113 58 30 33 1 23 3 35 5 7 363", "output": "NO" }, { "input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9940", "output": "NO" }, { "input": "10000 93\n1388 119 711 23 4960 4002 2707 188 813 1831 334 543 338 3402 1808 3368 1428 971 985 220 1521 457 457 140 332 1503 1539 2095 1891 269 5223 226 1528 190 428 5061 410 1587 1149 1934 2275 1337 1828 275 181 85 499 29 585 808 751 401 635 461 181 164 274 36 401 255 38 60 76 16 6 35 79 46 1 39 11 2 8 2 4 14 3 1 1 1 1 1 2 1 3 1 1 1 1 2 1 1 9948", "output": "NO" }, { "input": "4981 51\n5364 2166 223 742 350 1309 15 229 4100 3988 227 1719 9 125 787 427 141 842 171 2519 32 2554 2253 721 775 88 720 9 397 513 100 291 111 32 238 42 152 108 5 58 96 53 7 19 11 2 5 5 6 2 4966", "output": "NO" }, { "input": "541 31\n607 204 308 298 398 213 1182 58 162 46 64 12 38 91 29 2 4 12 19 3 7 9 3 6 1 1 2 1 3 1 529", "output": "YES" }, { "input": "100 100\n6 129 61 6 87 104 45 28 3 35 2 14 1 37 2 4 24 4 3 1 6 4 2 1 1 3 1 2 2 9 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 22", "output": "NO" }, { "input": "1 4\n2 2 2 1", "output": "YES" }, { "input": "1 3\n2 2 2", "output": "YES" }, { "input": "2 5\n8 2 2 2 2", "output": "YES" }, { "input": "1 4\n1 1 2 2", "output": "YES" }, { "input": "1 3\n2 2 3", "output": "YES" }, { "input": "1 3\n4 2 2", "output": "YES" }, { "input": "1 4\n2 1 2 2", "output": "YES" }, { "input": "1 3\n3 2 2", "output": "YES" }, { "input": "2 8\n2 2 2 2 2 2 1 1", "output": "YES" }, { "input": "2 6\n2 2 2 2 2 2", "output": "YES" }, { "input": "1 4\n1 2 2 2", "output": "YES" }, { "input": "1 4\n1 1 1 1", "output": "YES" }, { "input": "2 7\n2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 8\n1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "3 7\n12 2 2 2 2 2 2", "output": "YES" }, { "input": "2 6\n4 1 3 1 1 3", "output": "NO" }, { "input": "1 3\n2 2 4", "output": "YES" }, { "input": "5 15\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 8\n2 2 2 2 1 1 1 1", "output": "YES" }, { "input": "1 2\n6 2", "output": "YES" }, { "input": "4 13\n2 2 2 2 2 2 2 2 2 2 2 2 4", "output": "YES" }, { "input": "2 7\n1 1 1 4 2 2 2", "output": "YES" }, { "input": "3 8\n8 2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 8\n1 1 1 1 2 2 2 2", "output": "YES" }, { "input": "2 8\n2 2 2 2 1 1 2 2", "output": "YES" }, { "input": "1 4\n2 2 1 1", "output": "YES" }, { "input": "3 9\n2 2 2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 6\n2 2 2 2 2 5", "output": "YES" }, { "input": "1 1\n6", "output": "YES" }, { "input": "2 1\n16", "output": "YES" }, { "input": "1 1\n2", "output": "YES" }, { "input": "2 8\n2 2 2 2 2 2 2 1", "output": "NO" }, { "input": "4 16\n1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2", "output": "YES" }, { "input": "2 7\n4 1 1 1 1 2 2", "output": "YES" }, { "input": "2 6\n2 2 2 5 2 2", "output": "YES" }, { "input": "3 1\n22", "output": "YES" }, { "input": "2 8\n2 2 2 2 1 1 1 3", "output": "NO" }, { "input": "3 12\n2 1 2 2 2 1 2 2 2 1 2 2", "output": "YES" }, { "input": "1 4\n2 2 3 1", "output": "NO" }, { "input": "2 6\n5 2 2 2 2 2", "output": "YES" }, { "input": "20 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "1 3\n2 2 1", "output": "YES" }, { "input": "1 2\n3 3", "output": "YES" }, { "input": "2 6\n2 3 2 2 3 2", "output": "YES" }, { "input": "2 8\n2 2 1 1 2 2 2 2", "output": "YES" }, { "input": "2 6\n3 3 2 2 2 2", "output": "YES" }, { "input": "3 12\n2 2 2 2 2 2 2 2 2 1 1 1", "output": "YES" }, { "input": "3 10\n2 2 2 2 2 2 2 2 2 3", "output": "YES" } ]
1,595,795,664
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
108
6,656,000
n = int(input()[0]) z = [int(s) for s in input().split()] a = sum(z) for x in z: if x % 2 != 0: a += 1 if a > (n * 8): print("NO") else: print("YES")
Title: Game of the Rows Time Limit: None seconds Memory Limit: None megabytes Problem Description: Daenerys Targaryen has an army consisting of *k* groups of soldiers, the *i*-th group contains *a**i* soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has *n* rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1,<=2}, {3,<=4}, {4,<=5}, {5,<=6} or {7,<=8}. Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats. Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10000, 1<=≤<=*k*<=≤<=100) — the number of rows and the number of groups of soldiers, respectively. The second line contains *k* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=10000), where *a**i* denotes the number of soldiers in the *i*-th group. It is guaranteed that *a*1<=+<=*a*2<=+<=...<=+<=*a**k*<=≤<=8·*n*. Output Specification: If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes). You can choose the case (lower or upper) for each letter arbitrary. Demo Input: ['2 2\n5 8\n', '1 2\n7 1\n', '1 2\n4 4\n', '1 4\n2 2 1 2\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'YES\n'] Note: In the first sample, Daenerys can place the soldiers like in the figure below: In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group. In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats. In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).
```python n = int(input()[0]) z = [int(s) for s in input().split()] a = sum(z) for x in z: if x % 2 != 0: a += 1 if a > (n * 8): print("NO") else: print("YES") ```
0
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task.
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": ".g.g.d.v.q" }, { "input": "pumesz", "output": ".p.m.s.z" }, { "input": "g", "output": ".g" }, { "input": "zjuotps", "output": ".z.j.t.p.s" }, { "input": "jzbwuehe", "output": ".j.z.b.w.h" }, { "input": "tnkgwuugu", "output": ".t.n.k.g.w.g" }, { "input": "kincenvizh", "output": ".k.n.c.n.v.z.h" }, { "input": "xattxjenual", "output": ".x.t.t.x.j.n.l" }, { "input": "ktajqhpqsvhw", "output": ".k.t.j.q.h.p.q.s.v.h.w" }, { "input": "xnhcigytnqcmy", "output": ".x.n.h.c.g.t.n.q.c.m" }, { "input": "jfmtbejyilxcec", "output": ".j.f.m.t.b.j.l.x.c.c" }, { "input": "D", "output": ".d" }, { "input": "ab", "output": ".b" }, { "input": "Ab", "output": ".b" }, { "input": "aB", "output": ".b" }, { "input": "AB", "output": ".b" }, { "input": "ba", "output": ".b" }, { "input": "bA", "output": ".b" }, { "input": "Ba", "output": ".b" }, { "input": "BA", "output": ".b" }, { "input": "aab", "output": ".b" }, { "input": "baa", "output": ".b" }, { "input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM", "output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m" }, { "input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN", "output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n" }, { "input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ", "output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j" }, { "input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea", "output": ".w.z.t.c.v.v.v.v.z.v" }, { "input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl", "output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l" }, { "input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg", "output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g" }, { "input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ", "output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q" }, { "input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg", "output": ".l.t.g.m.g" }, { "input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy", "output": ".k.z.d.x.f" }, { "input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ", "output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q" }, { "input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY", "output": ".m.r.c.g.p" }, { "input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx", "output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x" }, { "input": "YB", "output": ".b" }, { "input": "fly", "output": ".f.l" }, { "input": "YyyYYYyyYxdwdawdDAWDdaddYYYY", "output": ".x.d.w.d.w.d.d.w.d.d.d.d" } ]
1,694,235,134
2,147,483,647
Python 3
OK
TESTS
42
92
0
s = input().lower() t = '' alpha = 'aoyeui' for i in range(len(s)): if s[i] not in alpha: t += '.' + s[i] print(t)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task. Input Specification: The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. Output Specification: Print the resulting string. It is guaranteed that this string is not empty. Demo Input: ['tour\n', 'Codeforces\n', 'aBAcAba\n'] Demo Output: ['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n'] Note: none
```python s = input().lower() t = '' alpha = 'aoyeui' for i in range(len(s)): if s[i] not in alpha: t += '.' + s[i] print(t) ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, 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": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,595,318,241
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
6,656,000
s=input() h='hello' if h in s: 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=input() h='hello' if h in s: print("YES") else: print("NO") ```
0
743
A
Vladik and flights
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*. Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies. Print the minimum cost Vladik has to pay to get to the olympiad.
The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second.
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
[ "4 1 4\n1010\n", "5 5 2\n10110\n" ]
[ "1", "0" ]
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
500
[ { "input": "4 1 4\n1010", "output": "1" }, { "input": "5 5 2\n10110", "output": "0" }, { "input": "10 9 5\n1011111001", "output": "1" }, { "input": "7 3 7\n1110111", "output": "0" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 3 3\n1001011011", "output": "0" }, { "input": "1 1 1\n0", "output": "0" }, { "input": "10 5 8\n1000001110", "output": "1" }, { "input": "10 1 10\n0000011111", "output": "1" }, { "input": "4 1 4\n0011", "output": "1" }, { "input": "10 3 7\n0000011111", "output": "1" }, { "input": "5 1 5\n11010", "output": "1" }, { "input": "6 1 6\n111000", "output": "1" }, { "input": "2 1 2\n01", "output": "1" }, { "input": "10 10 1\n0000011111", "output": "1" }, { "input": "6 1 6\n000111", "output": "1" }, { "input": "10 2 10\n0000011111", "output": "1" }, { "input": "8 1 8\n11110000", "output": "1" }, { "input": "6 1 5\n100000", "output": "1" }, { "input": "16 4 12\n0000000011111111", "output": "1" }, { "input": "6 1 5\n111000", "output": "1" }, { "input": "8 2 7\n11110000", "output": "1" }, { "input": "6 2 5\n111000", "output": "1" }, { "input": "9 9 1\n111000000", "output": "1" }, { "input": "2 2 1\n01", "output": "1" }, { "input": "5 2 5\n00001", "output": "1" }, { "input": "5 1 5\n10000", "output": "1" }, { "input": "6 1 6\n011111", "output": "1" }, { "input": "5 5 1\n11110", "output": "1" }, { "input": "2 1 2\n10", "output": "1" }, { "input": "4 2 4\n0001", "output": "1" }, { "input": "10 1 10\n1111100000", "output": "1" }, { "input": "8 4 5\n00001111", "output": "1" }, { "input": "4 4 1\n0111", "output": "1" }, { "input": "8 1 8\n00101001", "output": "1" } ]
1,618,414,783
2,147,483,647
Python 3
OK
TESTS
56
77
716,800
n, a, b = map(int, input().split()) s = list(input()) if s[a - 1] == s[b - 1]: print(0) else: print(1)
Title: Vladik and flights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*. Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies. Print the minimum cost Vladik has to pay to get to the olympiad. Input Specification: The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second. Output Specification: Print single integer — the minimum cost Vladik has to pay to get to the olympiad. Demo Input: ['4 1 4\n1010\n', '5 5 2\n10110\n'] Demo Output: ['1', '0'] Note: In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
```python n, a, b = map(int, input().split()) s = list(input()) if s[a - 1] == s[b - 1]: print(0) else: print(1) ```
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" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,699,379,056
2,147,483,647
Python 3
OK
TESTS
48
46
0
s=0 lst=list(map(int,input().split())) lst.sort() cmd=lst[1] for i in lst: s+=abs(i-cmd) print(int(s))
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 s=0 lst=list(map(int,input().split())) lst.sort() cmd=lst[1] for i in lst: s+=abs(i-cmd) print(int(s)) ```
3
302
B
Eugeny and Play List
PROGRAMMING
1,200
[ "binary search", "implementation", "two pointers" ]
null
null
Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i* *c**i* times. Eugeny's play list is organized as follows: first song number 1 plays *c*1 times, then song number 2 plays *c*2 times, ..., in the end the song number *n* plays *c**n* times. Eugeny took a piece of paper and wrote out *m* moments of time when he liked a song. Now for each such moment he wants to know the number of the song that played at that moment. The moment *x* means that Eugeny wants to know which song was playing during the *x*-th minute of his listening to the play list. Help Eugeny and calculate the required numbers of songs.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *n* lines contain pairs of integers. The *i*-th line contains integers *c**i*,<=*t**i* (1<=≤<=*c**i*,<=*t**i*<=≤<=109) — the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 109 . The next line contains *m* positive integers *v*1,<=*v*2,<=...,<=*v**m*, that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time *v**i*, when the music doesn't play any longer. It is guaranteed that *v**i*<=&lt;<=*v**i*<=+<=1 (*i*<=&lt;<=*m*). The moment of time *v**i* means that Eugeny wants to know which song was playing during the *v**i*-th munite from the start of listening to the playlist.
Print *m* integers — the *i*-th number must equal the number of the song that was playing during the *v**i*-th minute after Eugeny started listening to the play list.
[ "1 2\n2 8\n1 16\n", "4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9\n" ]
[ "1\n1\n", "1\n1\n2\n2\n3\n4\n4\n4\n4\n" ]
none
1,000
[ { "input": "1 2\n2 8\n1 16", "output": "1\n1" }, { "input": "4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9", "output": "1\n1\n2\n2\n3\n4\n4\n4\n4" }, { "input": "3 3\n2 8\n5 1\n10 5\n13 16 62", "output": "1\n1\n3" }, { "input": "4 4\n2 8\n2 2\n6 3\n8 7\n13 23 29 85", "output": "1\n3\n3\n4" }, { "input": "5 5\n9 6\n8 7\n2 9\n10 3\n8 10\n69 95 146 162 177", "output": "2\n2\n4\n5\n5" }, { "input": "6 6\n4 9\n8 5\n3 8\n8 10\n4 2\n10 9\n15 45 97 197 231 265", "output": "1\n2\n3\n6\n6\n6" }, { "input": "7 7\n1 10\n1 1\n7 2\n4 9\n10 4\n5 5\n7 1\n48 71 86 87 110 113 127", "output": "4\n5\n5\n5\n6\n6\n7" }, { "input": "8 8\n4 6\n10 9\n5 1\n8 7\n4 7\n2 6\n5 3\n1 10\n21 91 93 142 145 157 181 206", "output": "1\n2\n2\n4\n4\n4\n5\n6" }, { "input": "9 9\n2 5\n7 1\n8 2\n8 8\n8 8\n4 4\n6 10\n10 9\n2 9\n1 10 36 48 76 151 229 276 310", "output": "1\n1\n4\n4\n4\n5\n7\n8\n8" }, { "input": "10 10\n3 1\n2 7\n5 1\n7 2\n9 10\n9 5\n2 5\n4 10\n9 9\n1 9\n26 34 37 141 146 201 239 245 296 299", "output": "4\n4\n5\n6\n6\n8\n9\n9\n9\n9" }, { "input": "2 3\n1 500000000\n1 500000000\n499999999 500000000 500000001", "output": "1\n1\n2" }, { "input": "2 3\n500000000 1\n1 500000000\n499999999 500000000 500000001", "output": "1\n1\n2" }, { "input": "2 3\n500000000 1\n500000000 1\n499999999 500000000 500000001", "output": "1\n1\n2" }, { "input": "3 1\n2 50\n1 50\n1 50\n160", "output": "3" } ]
1,579,109,317
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
18
2,000
13,209,600
import sys import math import bisect def main(): n, m = map(int, input().split()) A = [] for i in range(n): a, b = map(int, input().split()) A.append(a * b) #print(A) for i in range(1, n): A[i] += A[i-1] #print(A) Q = list(map(int, input().split())) #print(Q) for q in Q: p = bisect.bisect_left(A, q) print('%d\n' % (p + 1), end='') if __name__ == "__main__": main()
Title: Eugeny and Play List Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i* *c**i* times. Eugeny's play list is organized as follows: first song number 1 plays *c*1 times, then song number 2 plays *c*2 times, ..., in the end the song number *n* plays *c**n* times. Eugeny took a piece of paper and wrote out *m* moments of time when he liked a song. Now for each such moment he wants to know the number of the song that played at that moment. The moment *x* means that Eugeny wants to know which song was playing during the *x*-th minute of his listening to the play list. Help Eugeny and calculate the required numbers of songs. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *n* lines contain pairs of integers. The *i*-th line contains integers *c**i*,<=*t**i* (1<=≤<=*c**i*,<=*t**i*<=≤<=109) — the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 109 . The next line contains *m* positive integers *v*1,<=*v*2,<=...,<=*v**m*, that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time *v**i*, when the music doesn't play any longer. It is guaranteed that *v**i*<=&lt;<=*v**i*<=+<=1 (*i*<=&lt;<=*m*). The moment of time *v**i* means that Eugeny wants to know which song was playing during the *v**i*-th munite from the start of listening to the playlist. Output Specification: Print *m* integers — the *i*-th number must equal the number of the song that was playing during the *v**i*-th minute after Eugeny started listening to the play list. Demo Input: ['1 2\n2 8\n1 16\n', '4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9\n'] Demo Output: ['1\n1\n', '1\n1\n2\n2\n3\n4\n4\n4\n4\n'] Note: none
```python import sys import math import bisect def main(): n, m = map(int, input().split()) A = [] for i in range(n): a, b = map(int, input().split()) A.append(a * b) #print(A) for i in range(1, n): A[i] += A[i-1] #print(A) Q = list(map(int, input().split())) #print(Q) for q in Q: p = bisect.bisect_left(A, q) print('%d\n' % (p + 1), end='') if __name__ == "__main__": main() ```
0
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", "output": "1\n1" }, { "input": "10 8 1\nuTl9w4lcdo", "output": "10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no" }, { "input": "20 6 4\nfmFRpk2NrzSvnQC9gB61", "output": "5\nfmFR\npk2N\nrzSv\nnQC9\ngB61" }, { "input": "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6", "output": "5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6" }, { "input": "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde", "output": "6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde" }, { "input": "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu", "output": "8\nXCgVJUu4aMQ7HMxZ\njNxe3XARNiahK303\ng9y\n7NV\n8oN\n6tW\ndyX\nrlu" }, { "input": "60 52 8\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4hCKogONj", "output": "2\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4\nhCKogONj" }, { "input": "70 50 5\n1BH1ECq7hjzooQOZdbiYHTAgATcP5mxI7kLI9rqA9AriWc9kE5KoLa1zmuTDFsd2ClAPPY", "output": "14\n1BH1E\nCq7hj\nzooQO\nZdbiY\nHTAgA\nTcP5m\nxI7kL\nI9rqA\n9AriW\nc9kE5\nKoLa1\nzmuTD\nFsd2C\nlAPPY" }, { "input": "80 51 8\no2mpu1FCofuiLQb472qczCNHfVzz5TfJtVMrzgN3ff7FwlAY0fQ0ROhWmIX2bggodORNA76bHMjA5yyc", "output": "10\no2mpu1FC\nofuiLQb4\n72qczCNH\nfVzz5TfJ\ntVMrzgN3\nff7FwlAY\n0fQ0ROhW\nmIX2bggo\ndORNA76b\nHMjA5yyc" }, { "input": "90 12 7\nclcImtsw176FFOA6OHGFxtEfEyhFh5bH4iktV0Y8onIcn0soTwiiHUFRWC6Ow36tT5bsQjgrVSTcB8fAVoe7dJIWkE", "output": "10\nclcImtsw176F\nFOA6OHGFxtEf\nEyhFh5bH4ikt\nV0Y8onIcn0so\nTwiiHUF\nRWC6Ow3\n6tT5bsQ\njgrVSTc\nB8fAVoe\n7dJIWkE" }, { "input": "100 25 5\n2SRB9mRpXMRND5zQjeRxc4GhUBlEQSmLgnUtB9xTKoC5QM9uptc8dKwB88XRJy02r7edEtN2C6D60EjzK1EHPJcWNj6fbF8kECeB", "output": "20\n2SRB9\nmRpXM\nRND5z\nQjeRx\nc4GhU\nBlEQS\nmLgnU\ntB9xT\nKoC5Q\nM9upt\nc8dKw\nB88XR\nJy02r\n7edEt\nN2C6D\n60Ejz\nK1EHP\nJcWNj\n6fbF8\nkECeB" }, { "input": "100 97 74\nxL8yd8lENYnXZs28xleyci4SxqsjZqkYzkEbQXfLQ4l4gKf9QQ9xjBjeZ0f9xQySf5psDUDkJEtPLsa62n4CLc6lF6E2yEqvt4EJ", "output": "-1" }, { "input": "51 25 11\nwpk5wqrB6d3qE1slUrzJwMFafnnOu8aESlvTEb7Pp42FDG2iGQn", "output": "-1" }, { "input": "70 13 37\nfzL91QIJvNoZRP4A9aNRT2GTksd8jEb1713pnWFaCGKHQ1oYvlTHXIl95lqyZRKJ1UPYvT", "output": "-1" }, { "input": "10 3 1\nXQ2vXLPShy", "output": "10\nX\nQ\n2\nv\nX\nL\nP\nS\nh\ny" }, { "input": "4 2 3\naaaa", "output": "2\naa\naa" }, { "input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb" }, { "input": "99 2 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "11 2 3\nhavanahavan", "output": "4\nha\nvan\naha\nvan" }, { "input": "100 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "50\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa" }, { "input": "17 3 5\ngopstopmipodoshli", "output": "5\ngop\nsto\npmi\npod\noshli" }, { "input": "5 4 3\nfoyku", "output": "-1" }, { "input": "99 2 2\n123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", "output": "-1" }, { "input": "99 2 2\nrecursionishellrecursionishellrecursionishellrecursionishellrecursionishellrecursionishelldontuseit", "output": "-1" }, { "input": "11 2 3\nqibwnnvqqgo", "output": "4\nqi\nbwn\nnvq\nqgo" }, { "input": "4 4 3\nhhhh", "output": "1\nhhhh" }, { "input": "99 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "99 2 5\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", "output": "21\nhh\nhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh" }, { "input": "10 5 9\nCodeforces", "output": "2\nCodef\norces" }, { "input": "10 5 9\naaaaaaaaaa", "output": "2\naaaaa\naaaaa" }, { "input": "11 3 2\nmlmqpohwtsf", "output": "5\nmlm\nqp\noh\nwt\nsf" }, { "input": "3 3 2\nzyx", "output": "1\nzyx" }, { "input": "100 3 3\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "4 2 3\nzyxw", "output": "2\nzy\nxw" }, { "input": "3 2 3\nejt", "output": "1\nejt" }, { "input": "5 2 4\nzyxwv", "output": "-1" }, { "input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na" }, { "input": "100 5 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa" }, { "input": "3 2 2\nzyx", "output": "-1" }, { "input": "99 2 2\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", "output": "-1" }, { "input": "26 8 9\nabcabcabcabcabcabcabcabcab", "output": "3\nabcabcab\ncabcabcab\ncabcabcab" }, { "input": "6 3 5\naaaaaa", "output": "2\naaa\naaa" }, { "input": "3 2 3\nzyx", "output": "1\nzyx" }, { "input": "5 5 2\naaaaa", "output": "1\naaaaa" }, { "input": "4 3 2\nzyxw", "output": "2\nzy\nxw" }, { "input": "5 4 3\nzyxwv", "output": "-1" }, { "input": "95 3 29\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab", "output": "23\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabcabcabcabcabcabcabcabcabcab" }, { "input": "3 2 2\naaa", "output": "-1" }, { "input": "91 62 3\nfjzhkfwzoabaauvbkuzaahkozofaophaafhfpuhobufawkzbavaazwavwppfwapkapaofbfjwaavajojgjguahphofj", "output": "-1" }, { "input": "99 2 2\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc", "output": "-1" }, { "input": "56 13 5\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab", "output": "8\nabcabcabcabca\nbcabcabcabcab\ncabca\nbcabc\nabcab\ncabca\nbcabc\nabcab" }, { "input": "79 7 31\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca", "output": "-1" }, { "input": "92 79 6\nxlvplpckwnhmctoethhslkcyashqtsoeltriddglfwtgkfvkvgytygbcyohrvcxvosdioqvackxiuifmkgdngvbbudcb", "output": "-1" }, { "input": "48 16 13\nibhfinipihcbsqnvtgsbkobepmwymlyfmlfgblvhlfhyojsy", "output": "3\nibhfinipihcbsqnv\ntgsbkobepmwymlyf\nmlfgblvhlfhyojsy" }, { "input": "16 3 7\naaaaaaaaaaaaaaaa", "output": "4\naaa\naaa\naaa\naaaaaaa" }, { "input": "11 10 3\naaaaaaaaaaa", "output": "-1" }, { "input": "11 8 8\naaaaaaaaaaa", "output": "-1" }, { "input": "11 7 3\naaaaaaaaaaa", "output": "-1" }, { "input": "41 3 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcab", "output": "11\nabc\nabc\nabc\nabca\nbcab\ncabc\nabca\nbcab\ncabc\nabca\nbcab" }, { "input": "11 3 2\naaaaaaaaaaa", "output": "5\naaa\naa\naa\naa\naa" }, { "input": "14 9 4\nabcdefghijklmn", "output": "-1" }, { "input": "9 9 5\n123456789", "output": "1\n123456789" }, { "input": "92 10 41\nmeotryyfneonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlgeftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw", "output": "3\nmeotryyfne\nonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlg\neftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw" }, { "input": "17 16 3\ndxyhgtsxtuyljmclj", "output": "-1" }, { "input": "82 13 30\nfmtwumakkejtolxqxrnydhqoufwtdwldfxcfjrndauqcarhbwmdwxsxfbqjsfspuxobywhcrvlndsdmkqd", "output": "5\nfmtwumakkejto\nlxqxrnydhqouf\nwtdwldfxcfjrn\ndauqcarhbwmdw\nxsxfbqjsfspuxobywhcrvlndsdmkqd" }, { "input": "95 3 3\nihnfqcswushyoirjxlxxnwqtwtaowounkumxukwpacxwatimhhhoggqwkkspcplvyndfukbxickcixidgxkjtnpkoeiwlor", "output": "-1" }, { "input": "7 5 3\nzyxwvut", "output": "-1" }, { "input": "17 16 4\nctvfhkiakagcilrdw", "output": "-1" } ]
1,550,850,596
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
78
307,200
n,p,q = map(int,input().split(' ')) ch = input() l = list() l1 = list() j = 0 if (q<=p): while(n>p): l.append(ch[j:j+p]) j=j+p n=n-p while(n>0): l.append(ch[j:j+q]) j=j+q n=n-q elif (p<q): while(n>q): l1.append(ch[j:j+q]) j=j+q n=n-q while(n>0): l1.append(ch[j:j+p]) j=j+p n=n-p if (l != []): if ( len(l[-1])==q) or (len(l[-1])==p): print(len(l)) for i in range (len(l)): print(l[i]) elif (l1 !=[]): if ( len(l1[-1])==q) or (len(l1[-1])==p): print(len(l1)) for i in range (len(l1)): print(l1[i]) else: print(-1)
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 = map(int,input().split(' ')) ch = input() l = list() l1 = list() j = 0 if (q<=p): while(n>p): l.append(ch[j:j+p]) j=j+p n=n-p while(n>0): l.append(ch[j:j+q]) j=j+q n=n-q elif (p<q): while(n>q): l1.append(ch[j:j+q]) j=j+q n=n-q while(n>0): l1.append(ch[j:j+p]) j=j+p n=n-p if (l != []): if ( len(l[-1])==q) or (len(l[-1])==p): print(len(l)) for i in range (len(l)): print(l[i]) elif (l1 !=[]): if ( len(l1[-1])==q) or (len(l1[-1])==p): print(len(l1)) for i in range (len(l1)): print(l1[i]) else: print(-1) ```
0
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, { "input": "789 101112 131415", "output": "203802" }, { "input": "27485716 99999999 35182", "output": "55041796" }, { "input": "1 293548 5", "output": "12" }, { "input": "12059 259855 5874875", "output": "543828" }, { "input": "46981 105809 585858", "output": "305580" }, { "input": "9889 1221 2442", "output": "7326" }, { "input": "100500 200600 300700", "output": "601800" }, { "input": "318476 318476 318476", "output": "955428" }, { "input": "23985 3353 75633", "output": "54676" }, { "input": "120 1298 2222", "output": "2836" }, { "input": "98437 23487 666672", "output": "243848" }, { "input": "100000000 100000000 100000000", "output": "300000000" }, { "input": "2 5 2", "output": "8" }, { "input": "1 1000 1", "output": "4" }, { "input": "1 100000000 1", "output": "4" } ]
1,625,935,969
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
a = list(map(int, input().split())) if a[0] + a[1] <= a[2]: print((a[0] + a[1]) * 2) else: if a[0] + a[2] <= a[1]: print((a[0] + a[2]) * 2) elif a[1] + a[2] <= a[0]: print((a[1] + a[2]) * 2)
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python a = list(map(int, input().split())) if a[0] + a[1] <= a[2]: print((a[0] + a[1]) * 2) else: if a[0] + a[2] <= a[1]: print((a[0] + a[2]) * 2) elif a[1] + a[2] <= a[0]: print((a[1] + a[2]) * 2) ```
0
622
A
Infinite Sequence
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the *n*-th position of the sequence.
The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
[ "3\n", "5\n", "10\n", "55\n", "56\n" ]
[ "2\n", "2\n", "4\n", "10\n", "1\n" ]
none
0
[ { "input": "3", "output": "2" }, { "input": "5", "output": "2" }, { "input": "10", "output": "4" }, { "input": "55", "output": "10" }, { "input": "56", "output": "1" }, { "input": "1000000000000", "output": "88209" }, { "input": "847194127849", "output": "255708" }, { "input": "294719472984", "output": "593358" }, { "input": "999999911791", "output": "1414213" }, { "input": "999999911792", "output": "1" }, { "input": "100000000000000", "output": "1749820" }, { "input": "1", "output": "1" }, { "input": "99993", "output": "312" }, { "input": "99994", "output": "313" }, { "input": "99995", "output": "314" }, { "input": "99990", "output": "309" }, { "input": "2", "output": "1" }, { "input": "99991", "output": "310" }, { "input": "99992", "output": "311" }, { "input": "99996", "output": "315" }, { "input": "99997", "output": "316" }, { "input": "99998", "output": "317" }, { "input": "99999", "output": "318" }, { "input": "1021", "output": "31" }, { "input": "4", "output": "1" }, { "input": "23", "output": "2" }, { "input": "9994", "output": "124" }, { "input": "99939", "output": "258" }, { "input": "99999998250180", "output": "14142135" }, { "input": "6", "output": "3" }, { "input": "8", "output": "2" }, { "input": "35", "output": "7" }, { "input": "100", "output": "9" }, { "input": "10101010", "output": "745" }, { "input": "103", "output": "12" }, { "input": "102", "output": "11" }, { "input": "101", "output": "10" } ]
1,599,215,880
2,147,483,647
Python 3
OK
TESTS
37
108
0
from math import sqrt x=int(input()) n=(sqrt(8*x+1)-1)/2 if n==int(n): print(int(n)) else: n=int(n) k=n*(n+1)//2 print(x-k)
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the *n*-th position of the sequence. Input Specification: The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Specification: Print the element in the *n*-th position of the sequence (the elements are numerated from one). Demo Input: ['3\n', '5\n', '10\n', '55\n', '56\n'] Demo Output: ['2\n', '2\n', '4\n', '10\n', '1\n'] Note: none
```python from math import sqrt x=int(input()) n=(sqrt(8*x+1)-1)/2 if n==int(n): print(int(n)) else: n=int(n) k=n*(n+1)//2 print(x-k) ```
3
448
A
Rewards
PROGRAMMING
800
[ "implementation" ]
null
null
Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: - any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces.
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
[ "1 1 1\n1 1 1\n4\n", "1 1 3\n2 3 4\n2\n", "1 0 0\n1 0 0\n1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "1 1 1\n1 1 1\n4", "output": "YES" }, { "input": "1 1 3\n2 3 4\n2", "output": "YES" }, { "input": "1 0 0\n1 0 0\n1", "output": "NO" }, { "input": "0 0 0\n0 0 0\n1", "output": "YES" }, { "input": "100 100 100\n100 100 100\n100", "output": "YES" }, { "input": "100 100 100\n100 100 100\n1", "output": "NO" }, { "input": "1 10 100\n100 10 1\n20", "output": "NO" }, { "input": "1 1 1\n0 0 0\n1", "output": "YES" }, { "input": "0 0 0\n1 1 1\n1", "output": "YES" }, { "input": "5 5 5\n0 0 0\n2", "output": "NO" }, { "input": "0 0 0\n10 10 10\n2", "output": "NO" }, { "input": "21 61 39\n63 58 69\n44", "output": "YES" }, { "input": "18 95 4\n7 1 75\n46", "output": "YES" }, { "input": "64 27 81\n72 35 23\n48", "output": "YES" }, { "input": "6 6 6\n11 11 11\n7", "output": "NO" }, { "input": "1 2 3\n2 4 6\n3", "output": "NO" }, { "input": "1 2 3\n2 4 6\n4", "output": "YES" }, { "input": "99 99 99\n99 99 99\n89", "output": "NO" }, { "input": "5 0 0\n15 0 0\n2", "output": "NO" }, { "input": "10 10 10\n0 0 0\n1", "output": "NO" }, { "input": "1 1 1\n1 1 1\n15", "output": "YES" }, { "input": "2 3 5\n2 3 5\n2", "output": "NO" }, { "input": "2 2 2\n3 3 5\n3", "output": "NO" }, { "input": "1 2 2\n2 4 4\n1", "output": "NO" }, { "input": "1 2 3\n1 5 5\n2", "output": "NO" } ]
1,660,939,936
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
a1,a2,a3=map(int,input().split()) b1,b2,b3=map(int,input().split()) n=int(input()) if ((sum([a1,a2,a3])//5)+(sum([b1,b2,b3])//10))<=n: print("YES") else: print("NO")
Title: Rewards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: - any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled. Input Specification: The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces. Output Specification: Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). Demo Input: ['1 1 1\n1 1 1\n4\n', '1 1 3\n2 3 4\n2\n', '1 0 0\n1 0 0\n1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python a1,a2,a3=map(int,input().split()) b1,b2,b3=map(int,input().split()) n=int(input()) if ((sum([a1,a2,a3])//5)+(sum([b1,b2,b3])//10))<=n: print("YES") else: print("NO") ```
0
505
B
Mr. Kitayuta's Colorful Graph
PROGRAMMING
1,400
[ "dfs and similar", "dp", "dsu", "graphs" ]
null
null
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you to process the following *q* queries. In the *i*-th query, he gives you two integers — *u**i* and *v**i*. Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly.
The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively. The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*). The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries. Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*.
For each query, print the answer in a separate line.
[ "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n", "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n" ]
[ "2\n1\n0\n", "1\n1\n1\n1\n2\n" ]
Let's consider the first sample. - Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color.
1,000
[ { "input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0" }, { "input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2" }, { "input": "2 1\n1 2 1\n1\n1 2", "output": "1" }, { "input": "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2", "output": "3" }, { "input": "2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2", "output": "5" } ]
1,590,186,354
2,147,483,647
PyPy 3
OK
TESTS
29
170
2,355,200
from sys import stdin input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) def dfs(x,y,z): if x==y:return True g[x]=1 for p in cl[x]: if p[1]==z and g[p[0]]==0 and dfs(p[0],y,z):return True return False n,m=R() cl=[[] for i in range(n)] for i in range(m): a,b,c=R() cl[a-1].append([b-1,c-1]) cl[b-1].append([a-1,c-1]) q=I() s=[0]*q for i in range(q): u,v=R() for j in range(100): g=[0]*(n) if dfs(u-1,v-1,j):s[i]+=1 for i in s:print(i)
Title: Mr. Kitayuta's Colorful Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you to process the following *q* queries. In the *i*-th query, he gives you two integers — *u**i* and *v**i*. Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly. Input Specification: The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively. The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*). The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries. Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*. Output Specification: For each query, print the answer in a separate line. Demo Input: ['4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n', '5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n'] Demo Output: ['2\n1\n0\n', '1\n1\n1\n1\n2\n'] Note: Let's consider the first sample. - Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color.
```python from sys import stdin input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) def dfs(x,y,z): if x==y:return True g[x]=1 for p in cl[x]: if p[1]==z and g[p[0]]==0 and dfs(p[0],y,z):return True return False n,m=R() cl=[[] for i in range(n)] for i in range(m): a,b,c=R() cl[a-1].append([b-1,c-1]) cl[b-1].append([a-1,c-1]) q=I() s=[0]*q for i in range(q): u,v=R() for j in range(100): g=[0]*(n) if dfs(u-1,v-1,j):s[i]+=1 for i in s:print(i) ```
3
1,003
D
Coins and Queries
PROGRAMMING
1,600
[ "greedy" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the minimum number of coins that is necessary to obtain the value $b_j$ using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value $b_j$, the answer to the $j$-th query is -1. The queries are independent (the answer on the query doesn't affect Polycarp's coins).
The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). The next $q$ lines contain one integer each. The $j$-th line contains one integer $b_j$ — the value of the $j$-th query ($1 \le b_j \le 10^9$).
Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1.
[ "5 4\n2 4 8 2 4\n8\n5\n14\n10\n" ]
[ "1\n-1\n3\n2\n" ]
none
0
[ { "input": "5 4\n2 4 8 2 4\n8\n5\n14\n10", "output": "1\n-1\n3\n2" }, { "input": "3 3\n1 1 1\n1\n2\n3", "output": "1\n2\n3" }, { "input": "4 1\n2 4 16 32\n14", "output": "-1" }, { "input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\n-1\n-1" }, { "input": "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "-1\n-1\n-1\n1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "-1\n1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16", "output": "1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" } ]
1,685,225,817
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
420
23,347,200
import sys input = lambda: sys.stdin.readline().rstrip() from collections import Counter,defaultdict N,Q = map(int, input().split()) A = list(map(int, input().split())) cnt = [0]*32 for a in A: for i in range(32): if a&(1<<i): cnt[i]+=1 #print(cnt) for _ in range(Q): b = int(input()) ans = 0 cur = cnt[::] ok = True for i in range(32): if b&(1<<i)==0:continue #print(i,b) t = 1 find = False for j in range(i,-1,-1): #print('j',j,t) if cur[j]>=t: cur[j]-=t ans+=t find=True #print('find',j,t) break else: t -= cur[j] cur[j]=0 t*=2 if not find: ok = False if ok: print(ans) else: print(-1)
Title: Coins and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the minimum number of coins that is necessary to obtain the value $b_j$ using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value $b_j$, the answer to the $j$-th query is -1. The queries are independent (the answer on the query doesn't affect Polycarp's coins). Input Specification: The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$). The next $q$ lines contain one integer each. The $j$-th line contains one integer $b_j$ — the value of the $j$-th query ($1 \le b_j \le 10^9$). Output Specification: Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1. Demo Input: ['5 4\n2 4 8 2 4\n8\n5\n14\n10\n'] Demo Output: ['1\n-1\n3\n2\n'] Note: none
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import Counter,defaultdict N,Q = map(int, input().split()) A = list(map(int, input().split())) cnt = [0]*32 for a in A: for i in range(32): if a&(1<<i): cnt[i]+=1 #print(cnt) for _ in range(Q): b = int(input()) ans = 0 cur = cnt[::] ok = True for i in range(32): if b&(1<<i)==0:continue #print(i,b) t = 1 find = False for j in range(i,-1,-1): #print('j',j,t) if cur[j]>=t: cur[j]-=t ans+=t find=True #print('find',j,t) break else: t -= cur[j] cur[j]=0 t*=2 if not find: ok = False if ok: print(ans) else: print(-1) ```
0
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "output": "NO" } ]
1,695,258,554
2,147,483,647
Python 3
OK
TESTS
34
92
0
n = str(input()) l = 0 for i in range(len(n)): if n[i] == "4" or n[i] == "7": l += 1 j = True l = str(l) for i in range(len(l)): if l[i] != "4" and l[i] != "7": j = False break if j: print("YES") else: print("NO")
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Demo Input: ['40047\n', '7747774\n', '1000000000000000000\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
```python n = str(input()) l = 0 for i in range(len(n)): if n[i] == "4" or n[i] == "7": l += 1 j = True l = str(l) for i in range(len(l)): if l[i] != "4" and l[i] != "7": j = False break if j: print("YES") else: print("NO") ```
3.977
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,592,934,648
2,147,483,647
Python 3
OK
TESTS
32
216
6,963,200
import math def solve(arr, n): even = 0 odd = 0 for i in range(n): if arr[i] & 1: odd += 1 else: even += 1 if even == 1: for i in range(n): if arr[i] & 1 == 0: return i+1 else: for i in range(n): if arr[i] & 1: return i+1 return -1 n = int(input()) arr = list(map(int, input().strip().split())) result = solve(arr, n) print(result)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python import math def solve(arr, n): even = 0 odd = 0 for i in range(n): if arr[i] & 1: odd += 1 else: even += 1 if even == 1: for i in range(n): if arr[i] & 1 == 0: return i+1 else: for i in range(n): if arr[i] & 1: return i+1 return -1 n = int(input()) arr = list(map(int, input().strip().split())) result = solve(arr, n) print(result) ```
3.93303
680
B
Bear and Finding Criminals
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city. Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal. You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Print the number of criminals Limak will catch.
[ "6 3\n1 1 1 0 1 0\n", "5 2\n0 0 0 1 0\n" ]
[ "3\n", "1\n" ]
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total. In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
1,000
[ { "input": "6 3\n1 1 1 0 1 0", "output": "3" }, { "input": "5 2\n0 0 0 1 0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "9 3\n1 1 1 1 1 1 1 1 0", "output": "8" }, { "input": "9 5\n1 0 1 0 1 0 1 0 1", "output": "5" }, { "input": "20 17\n1 1 0 1 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0", "output": "10" }, { "input": "100 60\n1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 1 0 0", "output": "27" }, { "input": "8 1\n1 0 1 1 0 0 1 0", "output": "4" }, { "input": "11 11\n0 1 0 0 1 1 1 0 0 0 0", "output": "4" }, { "input": "19 10\n0 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1", "output": "4" }, { "input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "1" }, { "input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "3" }, { "input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "25" }, { "input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "24" }, { "input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "24" }, { "input": "98 70\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "41" }, { "input": "99 70\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "99 60\n0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1", "output": "34" }, { "input": "98 24\n0 0 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 1", "output": "39" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "2 1\n0 1", "output": "1" } ]
1,606,407,291
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
140
0
import math for _ in range(1) : n,k=map(int,input().split()) list1=list(map(int,input().split())) i=k-2 j=k c=0 while(i>0 or j<n): if i>=0: p=list1[i] else: p=0 if j<n: q=list1[j] else: q=0 if i>=0 and j<n: if p+q==2: c=c+2 else: if p+q==1: c=c+1 i=i-1 j=j+1 if list1[k-1]==1: c=c+1 print(c)
Title: Bear and Finding Criminals Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city. Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal. You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD. Input Specification: The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. Output Specification: Print the number of criminals Limak will catch. Demo Input: ['6 3\n1 1 1 0 1 0\n', '5 2\n0 0 0 1 0\n'] Demo Output: ['3\n', '1\n'] Note: In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total. In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
```python import math for _ in range(1) : n,k=map(int,input().split()) list1=list(map(int,input().split())) i=k-2 j=k c=0 while(i>0 or j<n): if i>=0: p=list1[i] else: p=0 if j<n: q=list1[j] else: q=0 if i>=0 and j<n: if p+q==2: c=c+2 else: if p+q==1: c=c+1 i=i-1 j=j+1 if list1[k-1]==1: c=c+1 print(c) ```
0
520
B
Two Buttons
PROGRAMMING
1,400
[ "dfs and similar", "graphs", "greedy", "implementation", "math", "shortest paths" ]
null
null
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*. Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result?
The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space .
Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*.
[ "4 6\n", "10 1\n" ]
[ "2\n", "9\n" ]
In the first example you need to push the blue button once, and then push the red button once. In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
1,000
[ { "input": "4 6", "output": "2" }, { "input": "10 1", "output": "9" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "1 3", "output": "3" }, { "input": "3 1", "output": "2" }, { "input": "2 10", "output": "5" }, { "input": "100 99", "output": "1" }, { "input": "99 100", "output": "50" }, { "input": "10 17", "output": "3" }, { "input": "666 6666", "output": "255" }, { "input": "6666 666", "output": "6000" }, { "input": "1 8192", "output": "13" }, { "input": "1 8193", "output": "27" }, { "input": "9999 10000", "output": "5000" }, { "input": "10000 9999", "output": "1" }, { "input": "10000 1", "output": "9999" }, { "input": "1234 5678", "output": "528" }, { "input": "9102 9103", "output": "4552" }, { "input": "8192 1", "output": "8191" }, { "input": "9912 1023", "output": "8889" }, { "input": "100 500", "output": "41" }, { "input": "9997 9999", "output": "4999" }, { "input": "5000 10000", "output": "1" }, { "input": "4000 7997", "output": "3" }, { "input": "1 10000", "output": "20" }, { "input": "1 8191", "output": "14" }, { "input": "9999 10000", "output": "5000" }, { "input": "9097 9998", "output": "4099" }, { "input": "886 9383", "output": "305" }, { "input": "1 9", "output": "7" }, { "input": "1918 10000", "output": "671" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "2" }, { "input": "2 10000", "output": "19" }, { "input": "3 10000", "output": "17" }, { "input": "4 10000", "output": "18" }, { "input": "9998 10000", "output": "4999" }, { "input": "5000 10000", "output": "1" }, { "input": "5001 10000", "output": "2" }, { "input": "10000 1", "output": "9999" }, { "input": "1 9999", "output": "21" }, { "input": "7777 9999", "output": "2779" }, { "input": "2 100", "output": "9" }, { "input": "10 8722", "output": "18" }, { "input": "848 4561", "output": "283" }, { "input": "9967 9973", "output": "4982" }, { "input": "5555 10000", "output": "556" }, { "input": "999 10000", "output": "378" }, { "input": "3 6", "output": "1" }, { "input": "9 38", "output": "8" } ]
1,695,802,500
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
5,632,000
import math def num_to_binary(n): ret = [] while n != 0: ret.append(n % 2) n //= 2 return list(reversed(ret)) def solve(start, target): if target <= start: p2 = 0 else: p2 = math.ceil(math.log2(target / start)) cur = start * 2**p2 count = p2 excess = cur - target count += excess >> p2 + sum(num_to_binary(excess % (2**p2))) return count def str_to_list_numbers(s): return [int(ds) for ds in s.split()] def main(): n, m = str_to_list_numbers(input()) print(solve(n, m)) if __name__ == '__main__': main()
Title: Two Buttons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*. Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result? Input Specification: The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space . Output Specification: Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*. Demo Input: ['4 6\n', '10 1\n'] Demo Output: ['2\n', '9\n'] Note: In the first example you need to push the blue button once, and then push the red button once. In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
```python import math def num_to_binary(n): ret = [] while n != 0: ret.append(n % 2) n //= 2 return list(reversed(ret)) def solve(start, target): if target <= start: p2 = 0 else: p2 = math.ceil(math.log2(target / start)) cur = start * 2**p2 count = p2 excess = cur - target count += excess >> p2 + sum(num_to_binary(excess % (2**p2))) return count def str_to_list_numbers(s): return [int(ds) for ds in s.split()] def main(): n, m = str_to_list_numbers(input()) print(solve(n, m)) if __name__ == '__main__': main() ```
0
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4 4 4 2" }, { "input": "1\n2000", "output": "1" }, { "input": "2\n2000 2000", "output": "1 1" }, { "input": "3\n500 501 502", "output": "3 2 1" }, { "input": "10\n105 106 1 1 1 11 1000 999 1000 999", "output": "6 5 8 8 8 7 1 3 1 3" }, { "input": "6\n1 2 3 4 5 6", "output": "6 5 4 3 2 1" }, { "input": "7\n6 5 4 3 2 1 1", "output": "1 2 3 4 5 6 6" }, { "input": "8\n153 100 87 14 10 8 6 5", "output": "1 2 3 4 5 6 7 8" }, { "input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10", "output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63" }, { "input": "5\n1 2000 1 1 2000", "output": "3 1 3 3 1" } ]
1,619,686,180
2,147,483,647
Python 3
OK
TESTS
36
77
307,200
n=int(input()) arr=[int(x) for x in input().split()] ar=sorted(arr,reverse=True) a=dict() c=1 for ele in ar: if ele in a: a[ele]=a[ele] c+=1 else: a[ele]=c c+=1 for ele in arr: print(a[ele],end=' ')
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). Output Specification: In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. Demo Input: ['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n'] Demo Output: ['3 1 1\n', '1\n', '4 1 4 3 1\n'] Note: In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
```python n=int(input()) arr=[int(x) for x in input().split()] ar=sorted(arr,reverse=True) a=dict() c=1 for ele in ar: if ele in a: a[ele]=a[ele] c+=1 else: a[ele]=c c+=1 for ele in arr: print(a[ele],end=' ') ```
3
198
A
About Bacteria
PROGRAMMING
1,700
[ "implementation", "math" ]
null
null
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into *k* bacteria. After that some abnormal effects create *b* more bacteria in the test tube. Thus, if at the beginning of some second the test tube had *x* bacteria, then at the end of the second it will have *kx*<=+<=*b* bacteria. The experiment showed that after *n* seconds there were exactly *z* bacteria and the experiment ended at this point. For the second experiment Qwerty is going to sterilize the test tube and put there *t* bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least *z* bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment. Help Qwerty and find the minimum number of seconds needed to get a tube with at least *z* bacteria in the second experiment.
The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.
Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube.
[ "3 1 3 5\n", "1 4 4 7\n", "2 2 4 100\n" ]
[ "2", "3", "0" ]
none
500
[ { "input": "3 1 3 5", "output": "2" }, { "input": "1 4 4 7", "output": "3" }, { "input": "2 2 4 100", "output": "0" }, { "input": "1 2 3 100", "output": "0" }, { "input": "10 10 10 123456", "output": "6" }, { "input": "847 374 283 485756", "output": "282" }, { "input": "37 1 283475 8347", "output": "283473" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 1 1 1000000", "output": "0" }, { "input": "1 1 1000000 1", "output": "1000000" }, { "input": "1 1 1000000 1000000", "output": "1" }, { "input": "1 1000000 1 1", "output": "1" }, { "input": "1 1000000 1 1000000", "output": "1" }, { "input": "1 1000000 1000000 1", "output": "1000000" }, { "input": "1 1000000 1000000 1000000", "output": "1000000" }, { "input": "1000000 1 1 1", "output": "1" }, { "input": "1000000 1 1 1000000", "output": "1" }, { "input": "1000000 1 1000000 1", "output": "1000000" }, { "input": "1000000 1 1000000 1000000", "output": "1000000" }, { "input": "1000000 1000000 1 1", "output": "1" }, { "input": "1000000 1000000 1 1000000", "output": "1" }, { "input": "1000000 1000000 1000000 1", "output": "1000000" }, { "input": "1000000 1000000 1000000 1000000", "output": "1000000" }, { "input": "1 160 748 108", "output": "748" }, { "input": "1 6099 4415 2783", "output": "4415" }, { "input": "1 1047 230 1199", "output": "229" }, { "input": "1 82435 53193 37909", "output": "53193" }, { "input": "1 96840 99008 63621", "output": "99008" }, { "input": "1 250685 823830 494528", "output": "823829" }, { "input": "1 421986 2348 320240", "output": "2348" }, { "input": "2 8 16 397208", "output": "1" }, { "input": "2 96 676 215286", "output": "665" }, { "input": "2 575 321 606104", "output": "311" }, { "input": "2 8048 37852 278843", "output": "37847" }, { "input": "2 46658 377071 909469", "output": "377067" }, { "input": "3 10 90 567680", "output": "80" }, { "input": "4 4 149 609208", "output": "141" }, { "input": "5 4 3204 986907", "output": "3196" }, { "input": "6 5 5832 885406", "output": "5825" }, { "input": "7 10 141725 219601", "output": "141720" }, { "input": "38 86 441826 91486", "output": "441824" }, { "input": "185 58 579474 889969", "output": "579472" }, { "input": "3901 18 41607 412558", "output": "41606" }, { "input": "9821 62 965712 703044", "output": "965711" }, { "input": "29487 60 3239 483550", "output": "3238" }, { "input": "78993 99 646044 456226", "output": "646043" }, { "input": "193877 3 362586 6779", "output": "362586" }, { "input": "702841 39 622448 218727", "output": "622448" }, { "input": "987899 74 490126 87643", "output": "490126" }, { "input": "1000000 69 296123 144040", "output": "296123" }, { "input": "2 5 501022 406855", "output": "501006" }, { "input": "2 2 420084 748919", "output": "420067" }, { "input": "2 3 822794 574631", "output": "822777" }, { "input": "2 2 968609 433047", "output": "968592" }, { "input": "2 1 371319 775111", "output": "371301" }, { "input": "3 2 942777 573452", "output": "942766" }, { "input": "3 2 312783 882812", "output": "312772" }, { "input": "3 4 715494 741228", "output": "715483" }, { "input": "3 1 410364 566940", "output": "410353" }, { "input": "3 2 780370 425356", "output": "780359" }, { "input": "1 5 71 551204", "output": "0" }, { "input": "1 10 29 409620", "output": "0" }, { "input": "2 1 14 637985", "output": "0" }, { "input": "2 6 73 947345", "output": "56" }, { "input": "3 8 66 951518", "output": "55" }, { "input": "3 3 24 293582", "output": "14" }, { "input": "4 9 10 489244", "output": "2" }, { "input": "4 6 16 831308", "output": "7" }, { "input": "5 6 62 835481", "output": "55" }, { "input": "5 2 68 144841", "output": "61" }, { "input": "1 1 1000000 500000", "output": "500001" }, { "input": "5 2 100 7", "output": "99" }, { "input": "3 1 3 4", "output": "2" }, { "input": "126480 295416 829274 421896", "output": "829273" }, { "input": "999991 5 1000000 999997", "output": "999999" }, { "input": "54772 1 1000000 1000000", "output": "999999" }, { "input": "5 5 2 10", "output": "1" }, { "input": "1 1 2 2", "output": "1" }, { "input": "100000 100000 10 1000000", "output": "9" }, { "input": "2 2 5 4", "output": "4" }, { "input": "999997 1 100000 1000000", "output": "99999" }, { "input": "5 2 100 38", "output": "98" }, { "input": "1 4 1 5", "output": "0" }, { "input": "1 2149 1000000 1000000", "output": "999535" }, { "input": "99999 99999 10 1000000", "output": "9" }, { "input": "999998 1 1000000 1000000", "output": "999999" }, { "input": "1 1 10 2", "output": "9" }, { "input": "1 1 100 1000", "output": "0" }, { "input": "1 1 1000000 553211", "output": "446790" }, { "input": "1 1 10 1", "output": "10" }, { "input": "3 1 3 1", "output": "3" }, { "input": "888888 2 4 999999", "output": "3" }, { "input": "3 5 10 29", "output": "8" }, { "input": "1 1 100 2", "output": "99" }, { "input": "5 5 2 1", "output": "2" }, { "input": "50000 42 1337 999999", "output": "1336" }, { "input": "2 345678 908765 987654", "output": "908764" }, { "input": "1 7 15 7", "output": "15" }, { "input": "842717 8581 19342 851297", "output": "19342" }, { "input": "5 4 1 4", "output": "1" }, { "input": "2 2 5 94", "output": "0" }, { "input": "2 100000 5 10", "output": "5" }, { "input": "722229 410423 118215 838505", "output": "118215" }, { "input": "3 1 3 13", "output": "1" }, { "input": "900000 1 100 1000000", "output": "99" }, { "input": "2 4 4 36", "output": "1" }, { "input": "999990 1 1000000 1000000", "output": "999999" }, { "input": "100000 100000 1000000 1000000", "output": "999999" }, { "input": "999998 1 5 1000000", "output": "4" }, { "input": "1 1 10 4", "output": "7" }, { "input": "2 3 4 5", "output": "3" }, { "input": "3 1 3 40", "output": "0" }, { "input": "1 10 10 100", "output": "1" }, { "input": "999987 123456 1000000 1", "output": "1000000" } ]
1,552,926,743
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
inputStr = "2 2 4 100" inputArray = inputStr.split() k = int(inputArray[0]) b = int(inputArray[1]) n = int(inputArray[2]) t = int(inputArray[3]) x = 1 for i in range(n): x = k*x+b z = x fakeT = t n2 = 0 while fakeT < z: fakeT = k*fakeT+b n2+=1 print(n2)
Title: About Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into *k* bacteria. After that some abnormal effects create *b* more bacteria in the test tube. Thus, if at the beginning of some second the test tube had *x* bacteria, then at the end of the second it will have *kx*<=+<=*b* bacteria. The experiment showed that after *n* seconds there were exactly *z* bacteria and the experiment ended at this point. For the second experiment Qwerty is going to sterilize the test tube and put there *t* bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least *z* bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment. Help Qwerty and find the minimum number of seconds needed to get a tube with at least *z* bacteria in the second experiment. Input Specification: The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly. Output Specification: Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube. Demo Input: ['3 1 3 5\n', '1 4 4 7\n', '2 2 4 100\n'] Demo Output: ['2', '3', '0'] Note: none
```python inputStr = "2 2 4 100" inputArray = inputStr.split() k = int(inputArray[0]) b = int(inputArray[1]) n = int(inputArray[2]) t = int(inputArray[3]) x = 1 for i in range(n): x = k*x+b z = x fakeT = t n2 = 0 while fakeT < z: fakeT = k*fakeT+b n2+=1 print(n2) ```
0
921
04
Labyrinth-4
PROGRAMMING
3,200
[]
null
null
See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
none
none
[]
[]
none
0
[]
1,517,511,261
10,461
Python 3
PARTIAL
TESTS
1
46
5,734,400
print(""" move-down move-down move-right move-down for-2 move-down end move-down move-up move-up move-right move-up for-2 move-up end move-up for-2 move-down end for-2 move-down end for-2 move-down end for-2 move-down end for-2 move-down end for-2 move-down end move-left move-left move-down move-right move-down move-down move-up move-up move-left move-down move-down move-right move-right move-left for-5 move-left end for-2 move-left end for-2 move-right end move-right for-2 move-right end move-right move-up move-up move-right for-2 move-left end for-3 move-left end for-2 move-right end for-3 move-down end for-2 move-down end for-2 move-down end for-3 move-left end move-right for-2 move-down end move-down for-2 move-down end move-down move-left move-right for-3 move-right end for-5 move-right end move-right for-2 move-left end move-up for-4 move-left end move-up for-2 move-right end move-right move-right move-right for-4 move-up end move-left move-right move-right for-2 move-right end for-2 move-down end move-down for-2 move-right end for-4 move-down end move-up move-up for-4 move-right end move-down move-up move-down move-left for-2 move-right end move-right move-right for-2 move-right end move-right move-right for-2 move-down end for-2 move-up end move-up for-2 move-up end for-2 move-left end move-up move-up move-down for-2 move-up end for-4 move-up end for-2 move-up end move-up for-5 move-up end for-3 move-right end for-4 move-down end move-left move-right for-2 move-down end for-2 move-down end for-2 move-down end move-right move-left move-up move-down move-down move-up move-left for-2 move-down end move-left move-left for-2 move-left end move-down for-3 move-down end move-down for-3 move-up end move-up move-right move-right for-2 move-left end move-right for-2 move-down end move-up move-up move-left move-left for-2 move-right end move-up move-up move-up for-2 move-up end for-3 move-down end for-2 move-right end move-up for-2 move-left end move-left move-up move-down move-up move-right move-right move-right for-2 move-right end move-right move-right move-left move-right move-down move-left for-3 move-right end for-2 move-down end move-down for-2 move-up end move-down move-up move-down for-2 move-down end move-down move-right move-left for-2 move-left end move-up move-up move-left move-left move-left for-2 move-down end move-down for-2 move-down end move-up move-down move-down move-down move-down move-left move-right move-right for-2 move-up end for-2 move-up end move-right move-right for-3 move-right end move-right for-2 move-left end move-right for-2 move-up end move-up move-right for-3 move-left end move-right move-up move-up move-up for-3 move-up end move-left move-left move-up move-up move-up for-2 move-left end move-left for-3 move-right end move-right move-down for-2 move-right end move-right move-down for-3 move-down end move-down move-left move-left for-2 move-left end move-left move-right move-left move-right move-down move-down move-up for-2 move-right end move-left for-2 move-right end move-right for-4 move-right end for-2 move-right end move-up move-up move-up move-left for-2 move-up end for-2 move-up end move-up for-4 move-right end move-up for-2 move-left end move-left for-2 move-down end move-left for-2 move-up end for-2 move-up end for-3 move-up end move-up for-2 move-up end for-2 move-up end move-left move-right for-2 move-up end move-up move-right move-right move-up move-up for-4 move-down end move-down for-6 move-right end for-2 move-down end for-4 move-up end move-up for-3 move-up end for-2 move-right end for-4 move-right end move-right move-right move-up for-2 move-down end move-down move-down for-2 move-down end for-3 move-left end move-left for-2 move-right end for-3 move-left end move-left move-left move-down move-down move-right move-right for-2 move-right end for-3 move-left end move-right for-2 move-left end for-2 move-left end move-right move-up move-right move-right move-right move-right move-down move-up for-3 move-left end for-2 move-left end for-2 move-up end for-2 move-up end for-3 move-right end move-up move-right move-right move-right move-right for-2 move-right end for-3 move-up end for-3 move-up end move-left move-left for-2 move-down end for-2 move-up end move-right move-up for-3 move-down end for-2 move-up end move-up move-up move-up move-up move-right move-down move-down move-down for-2 move-down end for-3 move-up end move-down for-2 move-down end for-2 move-up end move-left for-2 move-up end move-up move-right for-2 move-right end move-down move-down move-down move-down for-2 move-right end move-right move-left move-right for-2 move-left end move-left for-2 move-right end move-right move-right move-right move-right for-3 move-left end move-down move-right move-right for-2 move-right end move-right move-down move-down move-down for-3 move-down end for-2 move-down end for-4 move-up end for-5 move-down end for-3 move-down end move-down for-4 move-down end move-down for-2 move-up end for-6 move-up end for-2 move-up end move-left for-2 move-down end for-3 move-left end move-right move-left move-right move-up for-3 move-down end move-down move-left move-left move-left move-left move-down move-down for-5 move-down end move-right for-2 move-down end move-down for-2 move-right end move-left move-up for-2 move-left end for-6 move-up end for-2 move-down end move-up for-2 move-left end for-2 move-left end for-3 move-down end move-right for-2 move-left end move-right for-3 move-left end move-left for-2 move-down end move-down move-down move-up move-down move-left move-left move-left move-left move-left for-3 move-left end move-down for-2 move-left end move-up move-left for-3 move-left end move-up move-left move-left move-right for-2 move-right end for-3 move-down end move-down move-right move-up move-up move-right for-3 move-down end move-down move-up for-2 move-left end move-right move-right for-3 move-up end move-up for-2 move-up end for-3 move-down end move-down for-2 move-down end for-6 move-up end move-down move-down for-3 move-down end move-left move-right move-down for-2 move-down end for-3 move-down end move-up move-left for-2 move-right end for-3 move-left end move-right move-up move-right for-2 move-right end for-2 move-left end move-left for-2 move-right end for-2 move-down end move-right for-5 move-left end move-left for-4 move-right end move-up move-right for-2 move-right end for-2 move-right end move-right move-up move-left move-right move-right for-2 move-right end move-right move-up move-up for-3 move-left end move-left move-down for-2 move-down end for-3 move-down end move-up for-2 move-up end move-up for-2 move-up end move-left move-left move-up move-up move-up move-up for-3 move-up end for-2 move-down end move-left move-down for-2 move-down end for-2 move-right end move-right move-up for-3 move-left end move-right for-2 move-down end move-down move-down move-down for-4 move-down end move-up move-up move-up move-down move-left for-2 move-right end move-right move-right for-2 move-left end move-right for-2 move-left end move-right move-right move-left for-2 move-right end move-right move-down move-down move-right move-left for-2 move-left end move-right move-down move-down move-down for-3 move-down end move-left for-2 move-left end move-left move-down move-down for-3 move-down end for-4 move-down end move-left move-right move-up for-4 move-down end move-left move-left move-down move-down move-left for-2 move-left end for-2 move-down end move-up move-right move-up move-left for-4 move-down end for-2 move-left end move-right move-up for-2 move-right end for-4 move-right end move-left move-up for-2 move-down end move-down move-down for-2 move-down end for-3 move-up end move-right move-down move-down move-down move-down move-down move-down for-2 move-left end move-left move-left move-left for-2 move-up end move-up for-2 move-down end move-up for-2 move-up end for-3 move-left end for-3 move-up end move-up for-6 move-left end move-down move-down for-3 move-left end move-up for-4 move-down end for-2 move-down end move-down move-left move-up move-down move-left for-2 move-left end for-3 move-right end move-down move-down move-down for-4 move-down end for-2 move-down end move-down move-left for-2 move-left end for-4 move-left end for-4 move-down end move-up move-down move-left move-right move-up for-4 move-down end for-2 move-down end for-2 move-left end move-up move-up for-2 move-down end for-7 move-left end move-right move-down move-right for-2 move-right end for-2 move-right end for-2 move-up end move-up move-left move-right move-right move-up move-down move-down move-up for-2 move-left end move-up move-down move-down move-up for-3 move-up end for-4 move-up end for-2 move-up end move-down move-right move-right move-up move-left for-2 move-up end move-up move-down for-2 move-down end for-2 move-down end for-2 move-down end for-2 move-down end move-down for-4 move-left end move-down for-2 move-down end for-2 move-left end move-right move-up for-2 move-right end move-right move-down move-left move-down move-down move-down move-right for-3 move-right end move-down for-2 move-right end move-right move-right for-3 move-right end move-right move-right move-right move-up for-2 move-down end for-2 move-left end move-left move-down move-down move-down move-down for-2 move-up end for-5 move-up end for-2 move-right end for-3 move-up end for-4 move-up end move-up move-down for-3 move-down end move-down for-3 move-right end move-down move-right move-left move-up move-left for-2 move-down end move-left move-up move-up for-2 move-left end move-down for-4 move-right end for-2 move-down end move-right move-down for-2 move-down end for-2 move-down end move-down move-down for-3 move-down end move-up move-left move-up move-up move-down for-3 move-down end move-left move-down move-down move-down for-2 move-up end for-4 move-down end for-2 move-down end for-3 move-right end move-right for-2 move-left end move-down move-down for-2 move-left end for-4 move-right end move-up move-up move-right move-up for-2 move-down end move-right move-left for-2 move-down end move-down for-2 move-down end move-left for-2 move-left end for-4 move-up end move-up for-2 move-right end move-right for-4 move-right end move-up for-3 move-left end move-right move-up for-3 move-down end move-up move-right move-left for-2 move-down end move-down for-2 move-down end move-down move-down move-right move-left move-down for-3 move-down end move-left move-left move-down for-2 move-up end move-up for-2 move-left end move-up move-up for-2 move-up end for-2 move-right end move-right for-4 move-left end move-up for-4 move-up end move-left move-left move-left for-2 move-right end move-left move-down for-7 move-down end move-left move-left move-down move-right move-up move-down move-left for-2 move-down end for-3 move-down end for-2 move-down end move-down for-4 move-up end for-2 move-up end move-up for-3 move-up end move-right move-right move-up move-left move-right move-left move-down move-left move-down move-down move-down for-2 move-right end move-right for-4 move-right end move-right move-down move-left for-3 move-up end move-left move-up for-3 move-left end for-3 move-left end for-2 move-down end move-down move-up move-down move-right move-right move-right for-3 move-down end for-3 move-down end move-down for-2 move-down end move-down for-3 move-up end for-3 move-down end move-up move-right move-down move-down move-left move-left move-left move-left move-left move-down for-3 move-left end for-2 move-left end for-3 move-left end move-left move-down for-2 move-down end move-up for-3 move-down end move-right move-right move-down move-right for-2 move-left end for-2 move-left end for-4 move-left end move-down move-right for-3 move-left end move-right move-left for-2 move-left end for-2 move-up end move-left for-4 move-left end move-right move-right move-right for-2 move-right end move-right move-right for-2 move-down end for-3 move-down end move-down move-down move-left for-3 move-left end move-down for-2 move-left end move-left move-left move-up move-up move-up for-2 move-up end for-3 move-up end move-down for-3 move-left end move-down move-right move-up move-down move-left for-2 move-down end move-down move-down for-2 move-right end for-5 move-down end move-right for-2 move-right end move-up for-6 move-right end move-up move-down move-up move-down for-3 move-down end move-down move-down for-2 move-down end move-up for-2 move-left end for-5 move-down end for-2 move-down end move-up for-2 move-down end move-left move-down move-right move-up move-down move-up for-2 move-up end for-2 move-up end move-up for-2 move-right end move-up for-4 move-up end for-2 move-right end move-right for-3 move-right end move-up move-up for-6 move-right end for-2 move-right end move-left move-right move-left move-right move-down for-3 move-down end for-2 move-down end move-right move-right for-2 move-up end for-2 move-right end move-up for-2 move-up end move-down move-right for-3 move-right end move-right move-down move-down for-3 move-down end for-3 move-down end for-2 move-up end for-2 move-right end move-right move-up for-2 move-left end move-left move-left move-left for-2 move-left end for-2 move-down end for-3 move-down end for-3 move-down end move-right move-right for-2 move-down end move-up for-2 move-up end for-2 move-down end for-2 move-left end for-2 move-right end for-3 move-left end move-up move-up move-up for-2 move-down end move-down move-up move-right move-right move-left for-6 move-up end move-up for-2 move-down end move-left for-2 move-left end move-right move-up for-2 move-left end for-8 move-down end move-down move-left move-left for-2 move-left end for-2 move-down end move-right move-right move-left for-3 move-down end move-down move-up move-down for-4 move-right end move-down move-left for-2 move-right end move-left move-down move-down for-2 move-up end move-down for-2 move-up end move-up move-up move-up for-2 move-right end for-2 move-right end move-right for-2 move-up end for-2 move-left end move-left for-4 move-up end for-2 move-up end move-up move-up move-down for-3 move-down end move-left for-2 move-left end for-2 move-down end move-up move-left move-down move-left for-5 move-left end for-3 move-down end move-left move-left for-2 move-right end move-up for-2 move-up end move-down move-left move-down move-left move-left for-2 move-up end move-left for-2 move-left end move-left move-left for-2 move-left end move-up move-left move-left move-down move-up for-2 move-left end move-left move-down move-right move-left for-2 move-up end for-2 move-left end move-right move-up move-down move-up move-left move-left move-left for-2 move-up end move-up for-4 move-left end move-up move-left for-3 move-up end for-2 move-left end move-right move-right for-4 move-right end for-4 move-right end for-4 move-right end move-down move-right for-2 move-right end move-right move-down for-2 move-down end move-down for-4 move-right end for-2 move-right end move-down for-3 move-up end move-up move-up for-2 move-up end move-right move-right for-2 move-up end move-up for-4 move-up end move-up for-3 move-down end move-down move-left for-2 move-down end for-2 move-left end move-right move-up for-2 move-up end move-up move-up move-up move-up for-2 move-left end for-2 move-up end move-up move-left move-left move-down move-down for-2 move-up end for-2 move-down end for-3 move-left end move-up for-2 move-left end move-up for-3 move-right end for-2 move-down end move-up move-up move-right move-right for-4 move-right end move-right for-5 move-up end for-2 move-right end move-right for-4 move-left end move-left for-3 move-left end move-left move-up move-up move-down for-4 move-down end move-up move-right move-left for-2 move-left end for-2 move-left end for-2 move-left end move-right move-left move-right move-down for-2 move-up end move-down move-left for-2 move-right end for-3 move-up end move-right move-up move-right for-2 move-right end for-2 move-up end for-8 move-left end move-left for-2 move-right end for-2 move-left end move-left for-2 move-right end move-down move-left move-up for-2 move-up end move-left for-2 move-left end move-down for-2 move-up end move-left for-3 move-left end move-left move-left move-left for-2 move-left end for-2 move-left end for-3 move-left end move-down move-down move-down for-2 move-up end for-3 move-left end move-left for-3 move-left end move-left move-up for-3 move-right end move-left for-2 move-right end move-right move-left for-2 move-up end move-down move-down for-2 move-down end move-left move-left for-3 move-up end for-2 move-up end move-right move-left move-left move-down move-down for-2 move-left end for-2 move-up end move-up move-right move-left move-up for-2 move-left end move-right for-2 move-left end move-right move-up move-up move-left for-4 move-left end for-2 move-down end for-2 move-left end for-4 move-up end for-2 move-right end move-up for-3 move-down end move-up move-left move-left for-2 move-up end for-3 move-up end move-up for-3 move-up end for-6 move-left end for-2 move-up end for-3 move-left end move-right for-2 move-right end for-6 move-right end for-2 move-left end move-right move-right move-right for-4 move-up end for-2 move-left end move-right move-down move-down for-7 move-up end for-2 move-right end for-3 move-right end for-2 move-up end move-up for-6 move-left end move-up move-up move-up move-right for-4 move-up end for-2 move-up end move-right for-2 move-down end for-9 move-up end move-right for-2 move-up end for-2 move-right end move-right move-right for-2 move-right end for-2 move-right end move-up for-7 move-up end for-4 move-left end move-left for-2 move-left end for-2 move-left end for-3 move-down end for-2 move-up end move-left move-left move-left move-right move-up for-2 move-right end move-right move-right move-right for-2 move-up end for-2 move-up end move-up move-right move-down move-down move-down move-right move-right for-2 move-left end for-2 move-down end for-4 move-up end for-2 move-right end move-left move-right move-down move-right for-2 move-up end for-7 move-left end for-4 move-left end for-9 move-down end move-left move-up for-2 move-up end move-down for-2 move-left end for-2 move-left end for-2 move-left end move-down for-2 move-left end for-2 move-right end for-2 move-left end for-2 move-left end move-down move-left for-2 move-left end move-down move-down for-5 move-down end move-left for-2 move-left end move-right move-left for-3 move-left end for-2 move-up end move-right move-right for-2 move-right end move-right move-up for-2 move-up end move-up move-down move-down for-4 move-right end for-2 move-up end move-left move-up for-2 move-right end move-right move-up move-up move-up move-left move-up for-2 move-up end move-down for-2 move-right end move-up move-right move-right for-2 move-right end for-4 move-left end for-5 move-down end move-down for-2 move-up end move-down move-right for-3 move-left end for-2 move-left end move-left move-down move-down for-2 move-down end for-2 move-down end move-left move-up move-up move-right move-up move-up for-2 move-up end move-up for-2 move-up end for-2 move-up end for-2 move-down end for-2 move-up end move-left move-left move-left move-down move-down for-2 move-down end move-up move-up move-up for-3 move-up end for-3 move-up end move-left move-left move-up for-2 move-down end move-down for-3 move-up end for-2 move-left end move-left for-10 move-down end for-2 move-up end for-4 move-down end for-4 move-left end move-down move-down move-down for-3 move-down end move-down move-right move-right move-down move-down move-down move-down for-2 move-down end move-down move-up move-right for-3 move-left end for-2 move-down end move-left move-down move-left for-2 move-left end for-3 move-down end for-2 move-down end for-2 move-down end move-down move-right move-down move-right move-left move-left for-4 move-left end move-down for-2 move-down end move-up move-down for-2 move-left end move-left move-down move-down for-2 move-up end move-down move-left for-2 move-down end for-2 move-down end move-left move-left move-right for-2 move-left end move-left move-down move-down move-down move-up move-up for-2 move-up end move-up move-up move-up move-up move-left move-left for-2 move-left end for-2 move-left end for-2 move-right end move-right for-2 move-up end for-2 move-left end for-3 move-left end move-right move-down move-right for-3 move-right end move-down move-down move-down move-down for-3 move-down end move-right for-6 move-right end for-2 move-up end move-up for-2 move-down end for-2 move-left end move-down move-right move-right move-up for-3 move-up end for-2 move-left end move-left for-5 move-right end move-right for-3 move-right end move-down move-down move-right move-right for-3 move-right end move-right move-up move-up for-2 move-left end move-left move-down for-5 move-up end move-up for-2 move-left end for-2 move-left end for-2 move-left end move-up move-up move-up move-up move-up for-2 move-right end for-2 move-right end move-right move-up for-3 move-up end for-2 move-up end for-2 move-up end for-2 move-right end move-left move-left move-down for-2 move-up end move-up for-4 move-up end for-4 move-up end move-up move-down move-up move-up move-down move-up for-3 move-up end for-2 move-down end for-2 move-up end move-down move-up move-right move-left move-right for-4 move-up end for-3 move-up end for-2 move-up end for-2 move-up end for-2 move-up end for-2 move-up end move-down for-4 move-left end for-3 move-up end for-2 move-up end move-left move-right move-left for-4 move-up end move-up move-down for-2 move-up end for-2 move-left end move-left for-4 move-up end move-down move-left move-right move-right move-left move-left move-right move-up for-2 move-up end for-2 move-down end move-down move-down move-left for-2 move-down end move-right move-down for-4 move-down end move-left move-right for-2 move-right end move-up move-up for-2 move-down end for-4 move-left end move-left move-down move-right move-right move-right move-right move-left move-up for-7 move-up end for-2 move-down end move-up move-right move-up for-2 move-up end move-up for-3 move-left end move-left move-up move-up move-right move-right move-up move-left for-2 move-up end for-2 move-down end for-2 move-up end move-up move-up for-2 move-left end for-2 move-left end move-down for-6 move-right end for-3 move-right end for-4 move-right end move-left move-down move-down for-2 move-right end move-left for-2 move-right end move-right for-2 move-left end move-left for-2 move-right end move-right move-up for-3 move-right end for-2 move-down end move-down move-down for-2 move-down end move-down for-5 move-down end for-2 move-down end move-down for-2 move-up end move-up for-2 move-down end move-up for-3 move-right end move-right for-4 move-left end move-down move-right move-down move-left move-right move-right for-2 move-left end for-7 move-right end move-left move-up for-2 move-left end for-2 move-up end for-3 move-up end for-2 move-left end move-up move-left for-3 move-left end for-3 move-left end for-2 move-up end for-2 move-up end for-2 move-right end for-2 move-left end move-left for-2 move-left end move-left for-4 move-right end move-down move-down move-down for-5 move-right end for-2 move-down end move-right for-3 move-right end move-down move-down for-2 move-down end move-left move-left move-down for-4 move-right end for-4 move-right end move-down move-down move-down for-2 move-left end for-2 move-down end move-down move-down for-5 move-left end for-7 move-down end move-down for-2 move-left end for-2 move-right end for-2 move-down end move-down for-3 move-down end move-left move-left for-2 move-left end move-up move-left for-7 move-right end move-right for-2 move-right end move-up for-2 move-down end move-left move-down move-left for-2 move-down end move-left for-3 move-right end move-left move-right move-right for-4 move-right end move-up move-up move-right move-right for-5 move-left end for-2 move-left end for-3 move-left end move-left for-3 move-left end for-2 move-down end move-right move-left for-3 move-right end move-down move-right for-2 move-left end move-up move-down for-3 move-right end move-right move-left move-down move-right move-right for-7 move-left end move-down for-5 move-right end move-down for-2 move-down end for-2 move-down end move-down move-down for-2 move-down end for-2 move-up end for-2 move-up end move-right for-3 move-left end for-2 move-right end move-right for-2 move-down end for-2 move-up end move-left move-left for-2 move-up end for-5 move-right end move-up for-3 move-down end move-right for-4 move-up end move-right for-2 move-right end move-down move-right move-up move-up move-up for-2 move-up end move-right move-right for-2 move-right end move-right for-4 move-right end move-right for-2 move-right end for-2 move-right end move-up for-2 move-left end move-right move-up move-up move-left move-left move-up move-up move-left move-left move-up move-up move-up for-2 move-right end for-2 move-up end for-2 move-up end for-2 move-up end move-down move-left for-5 move-up end for-3 move-up end for-5 move-up end move-left move-left for-2 move-right end move-up move-left move-right for-2 move-down end for-3 move-left end move-right for-2 move-up end move-up move-right for-2 move-right end move-left for-2 move-right end for-2 move-right end for-2 move-right end move-down for-2 move-left end move-right for-3 move-left end move-left for-2 move-left end for-2 move-right end for-3 move-up end for-5 move-right end for-3 move-right end move-right move-right move-right for-2 move-left end for-2 move-right end move-left for-2 move-left end move-right for-3 move-right end move-right move-up move-right move-right move-down move-left move-down move-left move-right move-up move-right move-right move-right for-2 move-left end move-right for-2 move-up end move-up move-up move-left move-up move-left move-right move-up move-right move-right move-right move-up move-right for-2 move-left end move-left move-left move-up move-down move-left for-2 move-left end for-5 move-left end for-2 move-down end move-right move-right for-3 move-left end for-3 move-up end move-up for-2 move-left end for-4 move-right end for-3 move-right end for-3 move-up end move-up for-2 move-up end move-left for-2 move-right end for-2 move-left end move-left move-left for-2 move-up end move-left move-up move-left for-2 move-left end move-up move-up for-2 move-up end for-2 move-up end move-up move-up move-right move-right for-2 move-right end for-2 move-down end move-right for-5 move-down end move-down move-right for-3 move-left end move-left move-left move-left for-2 move-up end move-up for-2 move-up end for-3 move-up end move-left for-2 move-right end for-2 move-up end move-left move-left for-2 move-up end move-left for-3 move-left end move-down for-2 move-down end move-down for-2 move-up end for-5 move-up end for-3 move-up end move-right move-up for-3 move-right end for-2 move-up end for-4 move-up end move-right move-right for-2 move-left end move-left move-down for-4 move-down end move-up move-down move-right move-left move-left for-2 move-left end move-up for-2 move-down end move-right move-right move-right for-3 move-right end move-up for-2 move-down end move-down for-2 move-down end for-2 move-down end move-right move-up move-up move-up for-3 move-left end for-3 move-left end for-2 move-right end move-down for-3 move-right end move-right for-2 move-right end for-2 move-down end for-2 move-up end for-3 move-down end move-down for-4 move-down end for-4 move-down end move-left move-left for-4 move-down end for-5 move-right end move-down move-down move-left for-3 move-down end move-up move-down move-left for-3 move-down end for-2 move-down end move-right for-2 move-right end for-7 move-left end for-3 move-down end for-6 move-right end for-2 move-down end for-4 move-left end move-left for-3 move-left end move-down for-5 move-left end for-4 move-down end for-5 move-left end move-right move-left move-left move-right for-2 move-down end for-2 move-right end move-right move-down for-4 move-left end for-2 move-left end move-right for-2 move-up end for-3 move-up end move-up for-2 move-right end for-2 move-up end move-up move-right for-2 move-left end move-left for-2 move-left end move-left move-up for-2 move-left end move-left move-right for-2 move-up end move-up move-right move-right for-3 move-right end for-2 move-right end for-5 move-down end for-3 move-up end for-2 move-up end for-2 move-up end for-2 move-up end for-3 move-down end move-up move-down move-up move-down for-4 move-right end move-down move-right move-right for-2 move-down end move-right move-down move-down move-down move-down move-down for-3 move-up end for-2 move-up end for-3 move-up end move-up move-up move-up move-up for-4 move-right end move-left move-right for-2 move-up end move-up move-right move-left for-2 move-up end move-right move-right for-2 move-down end move-up for-3 move-right end for-3 move-down end for-2 move-left end move-left for-2 move-right end move-left move-down for-3 move-left end for-2 move-left end move-down move-right for-3 move-down end move-down move-down for-2 move-right end move-right move-right move-right for-3 move-left end move-down move-down for-2 move-up end for-2 move-right end move-up for-2 move-up end for-2 move-down end move-left move-down for-2 move-down end move-up move-right move-left move-right move-up for-4 move-down end move-down for-2 move-right end move-up move-down for-2 move-down end for-2 move-left end for-2 move-left end move-down move-left move-left move-up move-left move-left move-down for-3 move-up end move-down move-right move-left move-down move-down for-3 move-right end for-2 move-down end for-3 move-up end move-up for-3 move-down end move-up move-right move-right move-down for-2 move-up end move-up move-right move-right move-right for-2 move-up end for-3 move-up end move-up for-3 move-left end move-left move-left move-right move-up move-up move-right for-3 move-left end for-2 move-left end for-2 move-left end for-2 move-up end move-left for-3 move-left end for-3 move-up end for-2 move-right end for-5 move-down end for-4 move-down end move-down for-2 move-up end move-down for-2 move-right end for-2 move-up end move-left for-3 move-right end for-2 move-down end move-right move-up move-right move-right move-left move-right move-left move-up for-3 move-down end for-3 move-right end move-down for-3 move-left end move-left move-right move-left move-up move-left for-2 move-down end move-down move-down move-down move-down for-2 move-right end for-2 move-right end for-2 move-right end for-3 move-right end move-right move-left move-up move-down move-down for-3 move-down end for-2 move-down end move-up for-3 move-down end for-2 move-right end for-2 move-up end move-down move-right move-up for-4 move-up end for-2 move-right end for-4 move-right end for-6 move-right end move-down move-right move-right move-right for-5 move-left end move-down move-down for-2 move-left end for-2 move-up end move-down move-down move-left move-up move-up move-up move-up for-4 move-left end move-down move-down for-2 move-left end for-2 move-up end for-2 move-up end for-2 move-up end move-up move-right for-3 move-up end move-up move-left move-left move-right move-down move-down move-up for-2 move-left end move-left move-right for-2 move-right end move-right for-2 move-left end for-2 move-down end move-up move-right move-right for-2 move-left end for-2 move-right end move-up move-up move-up move-down move-left move-left for-5 move-right end for-2 move-down end move-up move-right move-down move-up for-3 move-right end move-down for-2 move-right end for-2 move-right end for-4 move-down end for-2 move-left end for-3 move-right end move-right move-down for-3 move-up end for-4 move-right end for-3 move-right end move-left move-right move-up move-right for-2 move-up end move-up move-right move-right move-up move-left for-3 move-right end move-up for-3 move-right end for-3 move-up end for-2 move-up end move-up move-up for-2 move-up end for-5 move-left end for-6 move-up end move-down for-2 move-left end move-left move-up for-2 move-up end move-right move-right for-5 move-left end move-up move-right for-2 move-up end move-left move-left move-up move-up for-4 move-up end move-up for-2 move-left end move-up move-left for-2 move-left end for-3 move-right end for-2 move-right end for-2 move-right end move-down move-down for-2 move-up end for-4 move-right end move-right move-right move-down for-3 move-down end move-down move-down move-left move-left for-2 move-left end move-left move-left for-2 move-down end for-3 move-down end move-up move-down for-2 move-up end move-right for-2 move-right end for-3 move-up end move-up for-3 move-down end move-up move-down move-down for-2 move-down end for-2 move-right end for-3 move-down end move-right move-right move-down for-3 move-right end for-3 move-right end for-3 move-left end move-left for-4 move-down end for-3 move-right end for-2 move-right end move-right for-3 move-left end move-left for-2 move-up end move-left move-down for-2 move-up end move-left for-2 move-left end for-2 move-right end move-right for-3 move-down end for-2 move-down end for-2 move-down end move-down move-left move-right move-left for-2 move-right end for-2 move-left end for-4 move-down end for-4 move-left end for-2 move-down end for-6 move-down end for-2 move-down end move-down for-2 move-down end move-right move-right move-down for-2 move-right end for-3 move-down end move-down move-left for-2 move-right end move-down move-down move-up move-up for-3 move-left end move-left for-2 move-up end move-left move-down move-down for-2 move-down end move-right move-right move-right for-2 move-down end move-down move-down move-up move-left for-5 move-right end for-2 move-left end move-left move-left move-down for-4 move-down end move-down move-down for-5 move-up end for-6 move-right end move-down for-3 move-up end for-2 move-up end move-up move-right for-2 move-down end for-2 move-down end for-3 move-down end move-down move-down for-2 move-down end move-left move-left for-4 move-down end for-2 move-left end for-3 move-right end move-right move-right move-up for-2 move-right end move-right for-5 move-left end for-3 move-down end for-3 move-down end move-down for-2 move-right end move-up move-left move-right move-up move-down for-2 move-down end move-left move-down for-5 move-up end for-3 move-left end move-up for-2 move-up end for-2 move-up end move-up move-up move-up for-3 move-up end for-5 move-left end move-up move-left move-right move-down move-right move-right move-left move-right move-left for-2 move-right end move-right for-3 move-left end move-left move-down for-3 move-down end move-up for-2 move-right end move-right move-right move-left move-right for-3 move-down end move-up move-up move-down move-left for-3 move-right end move-left for-3 move-left end move-right move-left move-down move-down for-2 move-up end for-5 move-right end for-3 move-right end for-3 move-up end for-4 move-up end move-right for-3 move-left end move-down move-down for-3 move-up end move-up move-right for-3 move-up end move-down move-down move-right move-down move-down move-down move-down for-3 move-left end for-3 move-up end move-down move-down for-2 move-down end for-2 move-left end for-3 move-down end move-down for-2 move-right end move-down for-2 move-down end move-left move-up move-left move-down for-2 move-up end move-right for-3 move-up end move-up for-2 move-down end for-5 move-down end for-3 move-right end move-down for-2 move-down end for-2 move-right end for-2 move-right end move-right for-3 move-right end move-right move-down for-2 move-down end for-3 move-up end move-down for-2 move-right end for-5 move-up end move-down move-up for-3 move-left end move-left move-up for-2 move-up end move-right move-up for-2 move-left end move-right for-2 move-left end move-right for-2 move-down end move-left move-right move-right for-2 move-left end for-3 move-right end for-2 move-down end for-4 move-right end move-right for-2 move-up end move-down for-3 move-up end for-6 move-left end for-2 move-left end for-3 move-left end for-2 move-left end for-2 move-left end move-left move-up move-up move-right move-up move-up move-left move-down move-down move-down move-left move-up move-up for-2 move-up end move-up move-up move-up move-left move-right move-down for-2 move-up end move-down move-right for-2 move-down end for-3 move-right end move-left move-right move-right for-2 move-right end move-right move-right move-right for-2 move-right end move-up for-4 move-down end for-3 move-down end move-down for-2 move-left end move-left for-2 move-right end for-3 move-down end """)
Title: Labyrinth-4 Time Limit: None seconds Memory Limit: None megabytes Problem Description: See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01). Input Specification: none Output Specification: none Note: none
```python print(""" move-down move-down move-right move-down for-2 move-down end move-down move-up move-up move-right move-up for-2 move-up end move-up for-2 move-down end for-2 move-down end for-2 move-down end for-2 move-down end for-2 move-down end for-2 move-down end move-left move-left move-down move-right move-down move-down move-up move-up move-left move-down move-down move-right move-right move-left for-5 move-left end for-2 move-left end for-2 move-right end move-right for-2 move-right end move-right move-up move-up move-right for-2 move-left end for-3 move-left end for-2 move-right end for-3 move-down end for-2 move-down end for-2 move-down end for-3 move-left end move-right for-2 move-down end move-down for-2 move-down end move-down move-left move-right for-3 move-right end for-5 move-right end move-right for-2 move-left end move-up for-4 move-left end move-up for-2 move-right end move-right move-right move-right for-4 move-up end move-left move-right move-right for-2 move-right end for-2 move-down end move-down for-2 move-right end for-4 move-down end move-up move-up for-4 move-right end move-down move-up move-down move-left for-2 move-right end move-right move-right for-2 move-right end move-right move-right for-2 move-down end for-2 move-up end move-up for-2 move-up end for-2 move-left end move-up move-up move-down for-2 move-up end for-4 move-up end for-2 move-up end move-up for-5 move-up end for-3 move-right end for-4 move-down end move-left move-right for-2 move-down end for-2 move-down end for-2 move-down end move-right move-left move-up move-down move-down move-up move-left for-2 move-down end move-left move-left for-2 move-left end move-down for-3 move-down end move-down for-3 move-up end move-up move-right move-right for-2 move-left end move-right for-2 move-down end move-up move-up move-left move-left for-2 move-right end move-up move-up move-up for-2 move-up end for-3 move-down end for-2 move-right end move-up for-2 move-left end move-left move-up move-down move-up move-right move-right move-right for-2 move-right end move-right move-right move-left move-right move-down move-left for-3 move-right end for-2 move-down end move-down for-2 move-up end move-down move-up move-down for-2 move-down end move-down move-right move-left for-2 move-left end move-up move-up move-left move-left move-left for-2 move-down end move-down for-2 move-down end move-up move-down move-down move-down move-down move-left move-right move-right for-2 move-up end for-2 move-up end move-right move-right for-3 move-right end move-right for-2 move-left end move-right for-2 move-up end move-up move-right for-3 move-left end move-right move-up move-up move-up for-3 move-up end move-left move-left move-up move-up move-up for-2 move-left end move-left for-3 move-right end move-right move-down for-2 move-right end move-right move-down for-3 move-down end move-down move-left move-left for-2 move-left end move-left move-right move-left move-right move-down move-down move-up for-2 move-right end move-left for-2 move-right end move-right for-4 move-right end for-2 move-right end move-up move-up move-up move-left for-2 move-up end for-2 move-up end move-up for-4 move-right end move-up for-2 move-left end move-left for-2 move-down end move-left for-2 move-up end for-2 move-up end for-3 move-up end move-up for-2 move-up end for-2 move-up end move-left move-right for-2 move-up end move-up move-right move-right move-up move-up for-4 move-down end move-down for-6 move-right end for-2 move-down end for-4 move-up end move-up for-3 move-up end for-2 move-right end for-4 move-right end move-right move-right move-up for-2 move-down end move-down move-down for-2 move-down end for-3 move-left end move-left for-2 move-right end for-3 move-left end move-left move-left move-down move-down move-right move-right for-2 move-right end for-3 move-left end move-right for-2 move-left end for-2 move-left end move-right move-up move-right move-right move-right move-right move-down move-up for-3 move-left end for-2 move-left end for-2 move-up end for-2 move-up end for-3 move-right end move-up move-right move-right move-right move-right for-2 move-right end for-3 move-up end for-3 move-up end move-left move-left for-2 move-down end for-2 move-up end move-right move-up for-3 move-down end for-2 move-up end move-up move-up move-up move-up move-right move-down move-down move-down for-2 move-down end for-3 move-up end move-down for-2 move-down end for-2 move-up end move-left for-2 move-up end move-up move-right for-2 move-right end move-down move-down move-down move-down for-2 move-right end move-right move-left move-right for-2 move-left end move-left for-2 move-right end move-right move-right move-right move-right for-3 move-left end move-down move-right move-right for-2 move-right end move-right move-down move-down move-down for-3 move-down end for-2 move-down end for-4 move-up end for-5 move-down end for-3 move-down end move-down for-4 move-down end move-down for-2 move-up end for-6 move-up end for-2 move-up end move-left for-2 move-down end for-3 move-left end move-right move-left move-right move-up for-3 move-down end move-down move-left move-left move-left move-left move-down move-down for-5 move-down end move-right for-2 move-down end move-down for-2 move-right end move-left move-up for-2 move-left end for-6 move-up end for-2 move-down end move-up for-2 move-left end for-2 move-left end for-3 move-down end move-right for-2 move-left end move-right for-3 move-left end move-left for-2 move-down end move-down move-down move-up move-down move-left move-left move-left move-left move-left for-3 move-left end move-down for-2 move-left end move-up move-left for-3 move-left end move-up move-left move-left move-right for-2 move-right end for-3 move-down end move-down move-right move-up move-up move-right for-3 move-down end move-down move-up for-2 move-left end move-right move-right for-3 move-up end move-up for-2 move-up end for-3 move-down end move-down for-2 move-down end for-6 move-up end move-down move-down for-3 move-down end move-left move-right move-down for-2 move-down end for-3 move-down end move-up move-left for-2 move-right end for-3 move-left end move-right move-up move-right for-2 move-right end for-2 move-left end move-left for-2 move-right end for-2 move-down end move-right for-5 move-left end move-left for-4 move-right end move-up move-right for-2 move-right end for-2 move-right end move-right move-up move-left move-right move-right for-2 move-right end move-right move-up move-up for-3 move-left end move-left move-down for-2 move-down end for-3 move-down end move-up for-2 move-up end move-up for-2 move-up end move-left move-left move-up move-up move-up move-up for-3 move-up end for-2 move-down end move-left move-down for-2 move-down end for-2 move-right end move-right move-up for-3 move-left end move-right for-2 move-down end move-down move-down move-down for-4 move-down end move-up move-up move-up move-down move-left for-2 move-right end move-right move-right for-2 move-left end move-right for-2 move-left end move-right move-right move-left for-2 move-right end move-right move-down move-down move-right move-left for-2 move-left end move-right move-down move-down move-down for-3 move-down end move-left for-2 move-left end move-left move-down move-down for-3 move-down end for-4 move-down end move-left move-right move-up for-4 move-down end move-left move-left move-down move-down move-left for-2 move-left end for-2 move-down end move-up move-right move-up move-left for-4 move-down end for-2 move-left end move-right move-up for-2 move-right end for-4 move-right end move-left move-up for-2 move-down end move-down move-down for-2 move-down end for-3 move-up end move-right move-down move-down move-down move-down move-down move-down for-2 move-left end move-left move-left move-left for-2 move-up end move-up for-2 move-down end move-up for-2 move-up end for-3 move-left end for-3 move-up end move-up for-6 move-left end move-down move-down for-3 move-left end move-up for-4 move-down end for-2 move-down end move-down move-left move-up move-down move-left for-2 move-left end for-3 move-right end move-down move-down move-down for-4 move-down end for-2 move-down end move-down move-left for-2 move-left end for-4 move-left end for-4 move-down end move-up move-down move-left move-right move-up for-4 move-down end for-2 move-down end for-2 move-left end move-up move-up for-2 move-down end for-7 move-left end move-right move-down move-right for-2 move-right end for-2 move-right end for-2 move-up end move-up move-left move-right move-right move-up move-down move-down move-up for-2 move-left end move-up move-down move-down move-up for-3 move-up end for-4 move-up end for-2 move-up end move-down move-right move-right move-up move-left for-2 move-up end move-up move-down for-2 move-down end for-2 move-down end for-2 move-down end for-2 move-down end move-down for-4 move-left end move-down for-2 move-down end for-2 move-left end move-right move-up for-2 move-right end move-right move-down move-left move-down move-down move-down move-right for-3 move-right end move-down for-2 move-right end move-right move-right for-3 move-right end move-right move-right move-right move-up for-2 move-down end for-2 move-left end move-left move-down move-down move-down move-down for-2 move-up end for-5 move-up end for-2 move-right end for-3 move-up end for-4 move-up end move-up move-down for-3 move-down end move-down for-3 move-right end move-down move-right move-left move-up move-left for-2 move-down end move-left move-up move-up for-2 move-left end move-down for-4 move-right end for-2 move-down end move-right move-down for-2 move-down end for-2 move-down end move-down move-down for-3 move-down end move-up move-left move-up move-up move-down for-3 move-down end move-left move-down move-down move-down for-2 move-up end for-4 move-down end for-2 move-down end for-3 move-right end move-right for-2 move-left end move-down move-down for-2 move-left end for-4 move-right end move-up move-up move-right move-up for-2 move-down end move-right move-left for-2 move-down end move-down for-2 move-down end move-left for-2 move-left end for-4 move-up end move-up for-2 move-right end move-right for-4 move-right end move-up for-3 move-left end move-right move-up for-3 move-down end move-up move-right move-left for-2 move-down end move-down for-2 move-down end move-down move-down move-right move-left move-down for-3 move-down end move-left move-left move-down for-2 move-up end move-up for-2 move-left end move-up move-up for-2 move-up end for-2 move-right end move-right for-4 move-left end move-up for-4 move-up end move-left move-left move-left for-2 move-right end move-left move-down for-7 move-down end move-left move-left move-down move-right move-up move-down move-left for-2 move-down end for-3 move-down end for-2 move-down end move-down for-4 move-up end for-2 move-up end move-up for-3 move-up end move-right move-right move-up move-left move-right move-left move-down move-left move-down move-down move-down for-2 move-right end move-right for-4 move-right end move-right move-down move-left for-3 move-up end move-left move-up for-3 move-left end for-3 move-left end for-2 move-down end move-down move-up move-down move-right move-right move-right for-3 move-down end for-3 move-down end move-down for-2 move-down end move-down for-3 move-up end for-3 move-down end move-up move-right move-down move-down move-left move-left move-left move-left move-left move-down for-3 move-left end for-2 move-left end for-3 move-left end move-left move-down for-2 move-down end move-up for-3 move-down end move-right move-right move-down move-right for-2 move-left end for-2 move-left end for-4 move-left end move-down move-right for-3 move-left end move-right move-left for-2 move-left end for-2 move-up end move-left for-4 move-left end move-right move-right move-right for-2 move-right end move-right move-right for-2 move-down end for-3 move-down end move-down move-down move-left for-3 move-left end move-down for-2 move-left end move-left move-left move-up move-up move-up for-2 move-up end for-3 move-up end move-down for-3 move-left end move-down move-right move-up move-down move-left for-2 move-down end move-down move-down for-2 move-right end for-5 move-down end move-right for-2 move-right end move-up for-6 move-right end move-up move-down move-up move-down for-3 move-down end move-down move-down for-2 move-down end move-up for-2 move-left end for-5 move-down end for-2 move-down end move-up for-2 move-down end move-left move-down move-right move-up move-down move-up for-2 move-up end for-2 move-up end move-up for-2 move-right end move-up for-4 move-up end for-2 move-right end move-right for-3 move-right end move-up move-up for-6 move-right end for-2 move-right end move-left move-right move-left move-right move-down for-3 move-down end for-2 move-down end move-right move-right for-2 move-up end for-2 move-right end move-up for-2 move-up end move-down move-right for-3 move-right end move-right move-down move-down for-3 move-down end for-3 move-down end for-2 move-up end for-2 move-right end move-right move-up for-2 move-left end move-left move-left move-left for-2 move-left end for-2 move-down end for-3 move-down end for-3 move-down end move-right move-right for-2 move-down end move-up for-2 move-up end for-2 move-down end for-2 move-left end for-2 move-right end for-3 move-left end move-up move-up move-up for-2 move-down end move-down move-up move-right move-right move-left for-6 move-up end move-up for-2 move-down end move-left for-2 move-left end move-right move-up for-2 move-left end for-8 move-down end move-down move-left move-left for-2 move-left end for-2 move-down end move-right move-right move-left for-3 move-down end move-down move-up move-down for-4 move-right end move-down move-left for-2 move-right end move-left move-down move-down for-2 move-up end move-down for-2 move-up end move-up move-up move-up for-2 move-right end for-2 move-right end move-right for-2 move-up end for-2 move-left end move-left for-4 move-up end for-2 move-up end move-up move-up move-down for-3 move-down end move-left for-2 move-left end for-2 move-down end move-up move-left move-down move-left for-5 move-left end for-3 move-down end move-left move-left for-2 move-right end move-up for-2 move-up end move-down move-left move-down move-left move-left for-2 move-up end move-left for-2 move-left end move-left move-left for-2 move-left end move-up move-left move-left move-down move-up for-2 move-left end move-left move-down move-right move-left for-2 move-up end for-2 move-left end move-right move-up move-down move-up move-left move-left move-left for-2 move-up end move-up for-4 move-left end move-up move-left for-3 move-up end for-2 move-left end move-right move-right for-4 move-right end for-4 move-right end for-4 move-right end move-down move-right for-2 move-right end move-right move-down for-2 move-down end move-down for-4 move-right end for-2 move-right end move-down for-3 move-up end move-up move-up for-2 move-up end move-right move-right for-2 move-up end move-up for-4 move-up end move-up for-3 move-down end move-down move-left for-2 move-down end for-2 move-left end move-right move-up for-2 move-up end move-up move-up move-up move-up for-2 move-left end for-2 move-up end move-up move-left move-left move-down move-down for-2 move-up end for-2 move-down end for-3 move-left end move-up for-2 move-left end move-up for-3 move-right end for-2 move-down end move-up move-up move-right move-right for-4 move-right end move-right for-5 move-up end for-2 move-right end move-right for-4 move-left end move-left for-3 move-left end move-left move-up move-up move-down for-4 move-down end move-up move-right move-left for-2 move-left end for-2 move-left end for-2 move-left end move-right move-left move-right move-down for-2 move-up end move-down move-left for-2 move-right end for-3 move-up end move-right move-up move-right for-2 move-right end for-2 move-up end for-8 move-left end move-left for-2 move-right end for-2 move-left end move-left for-2 move-right end move-down move-left move-up for-2 move-up end move-left for-2 move-left end move-down for-2 move-up end move-left for-3 move-left end move-left move-left move-left for-2 move-left end for-2 move-left end for-3 move-left end move-down move-down move-down for-2 move-up end for-3 move-left end move-left for-3 move-left end move-left move-up for-3 move-right end move-left for-2 move-right end move-right move-left for-2 move-up end move-down move-down for-2 move-down end move-left move-left for-3 move-up end for-2 move-up end move-right move-left move-left move-down move-down for-2 move-left end for-2 move-up end move-up move-right move-left move-up for-2 move-left end move-right for-2 move-left end move-right move-up move-up move-left for-4 move-left end for-2 move-down end for-2 move-left end for-4 move-up end for-2 move-right end move-up for-3 move-down end move-up move-left move-left for-2 move-up end for-3 move-up end move-up for-3 move-up end for-6 move-left end for-2 move-up end for-3 move-left end move-right for-2 move-right end for-6 move-right end for-2 move-left end move-right move-right move-right for-4 move-up end for-2 move-left end move-right move-down move-down for-7 move-up end for-2 move-right end for-3 move-right end for-2 move-up end move-up for-6 move-left end move-up move-up move-up move-right for-4 move-up end for-2 move-up end move-right for-2 move-down end for-9 move-up end move-right for-2 move-up end for-2 move-right end move-right move-right for-2 move-right end for-2 move-right end move-up for-7 move-up end for-4 move-left end move-left for-2 move-left end for-2 move-left end for-3 move-down end for-2 move-up end move-left move-left move-left move-right move-up for-2 move-right end move-right move-right move-right for-2 move-up end for-2 move-up end move-up move-right move-down move-down move-down move-right move-right for-2 move-left end for-2 move-down end for-4 move-up end for-2 move-right end move-left move-right move-down move-right for-2 move-up end for-7 move-left end for-4 move-left end for-9 move-down end move-left move-up for-2 move-up end move-down for-2 move-left end for-2 move-left end for-2 move-left end move-down for-2 move-left end for-2 move-right end for-2 move-left end for-2 move-left end move-down move-left for-2 move-left end move-down move-down for-5 move-down end move-left for-2 move-left end move-right move-left for-3 move-left end for-2 move-up end move-right move-right for-2 move-right end move-right move-up for-2 move-up end move-up move-down move-down for-4 move-right end for-2 move-up end move-left move-up for-2 move-right end move-right move-up move-up move-up move-left move-up for-2 move-up end move-down for-2 move-right end move-up move-right move-right for-2 move-right end for-4 move-left end for-5 move-down end move-down for-2 move-up end move-down move-right for-3 move-left end for-2 move-left end move-left move-down move-down for-2 move-down end for-2 move-down end move-left move-up move-up move-right move-up move-up for-2 move-up end move-up for-2 move-up end for-2 move-up end for-2 move-down end for-2 move-up end move-left move-left move-left move-down move-down for-2 move-down end move-up move-up move-up for-3 move-up end for-3 move-up end move-left move-left move-up for-2 move-down end move-down for-3 move-up end for-2 move-left end move-left for-10 move-down end for-2 move-up end for-4 move-down end for-4 move-left end move-down move-down move-down for-3 move-down end move-down move-right move-right move-down move-down move-down move-down for-2 move-down end move-down move-up move-right for-3 move-left end for-2 move-down end move-left move-down move-left for-2 move-left end for-3 move-down end for-2 move-down end for-2 move-down end move-down move-right move-down move-right move-left move-left for-4 move-left end move-down for-2 move-down end move-up move-down for-2 move-left end move-left move-down move-down for-2 move-up end move-down move-left for-2 move-down end for-2 move-down end move-left move-left move-right for-2 move-left end move-left move-down move-down move-down move-up move-up for-2 move-up end move-up move-up move-up move-up move-left move-left for-2 move-left end for-2 move-left end for-2 move-right end move-right for-2 move-up end for-2 move-left end for-3 move-left end move-right move-down move-right for-3 move-right end move-down move-down move-down move-down for-3 move-down end move-right for-6 move-right end for-2 move-up end move-up for-2 move-down end for-2 move-left end move-down move-right move-right move-up for-3 move-up end for-2 move-left end move-left for-5 move-right end move-right for-3 move-right end move-down move-down move-right move-right for-3 move-right end move-right move-up move-up for-2 move-left end move-left move-down for-5 move-up end move-up for-2 move-left end for-2 move-left end for-2 move-left end move-up move-up move-up move-up move-up for-2 move-right end for-2 move-right end move-right move-up for-3 move-up end for-2 move-up end for-2 move-up end for-2 move-right end move-left move-left move-down for-2 move-up end move-up for-4 move-up end for-4 move-up end move-up move-down move-up move-up move-down move-up for-3 move-up end for-2 move-down end for-2 move-up end move-down move-up move-right move-left move-right for-4 move-up end for-3 move-up end for-2 move-up end for-2 move-up end for-2 move-up end for-2 move-up end move-down for-4 move-left end for-3 move-up end for-2 move-up end move-left move-right move-left for-4 move-up end move-up move-down for-2 move-up end for-2 move-left end move-left for-4 move-up end move-down move-left move-right move-right move-left move-left move-right move-up for-2 move-up end for-2 move-down end move-down move-down move-left for-2 move-down end move-right move-down for-4 move-down end move-left move-right for-2 move-right end move-up move-up for-2 move-down end for-4 move-left end move-left move-down move-right move-right move-right move-right move-left move-up for-7 move-up end for-2 move-down end move-up move-right move-up for-2 move-up end move-up for-3 move-left end move-left move-up move-up move-right move-right move-up move-left for-2 move-up end for-2 move-down end for-2 move-up end move-up move-up for-2 move-left end for-2 move-left end move-down for-6 move-right end for-3 move-right end for-4 move-right end move-left move-down move-down for-2 move-right end move-left for-2 move-right end move-right for-2 move-left end move-left for-2 move-right end move-right move-up for-3 move-right end for-2 move-down end move-down move-down for-2 move-down end move-down for-5 move-down end for-2 move-down end move-down for-2 move-up end move-up for-2 move-down end move-up for-3 move-right end move-right for-4 move-left end move-down move-right move-down move-left move-right move-right for-2 move-left end for-7 move-right end move-left move-up for-2 move-left end for-2 move-up end for-3 move-up end for-2 move-left end move-up move-left for-3 move-left end for-3 move-left end for-2 move-up end for-2 move-up end for-2 move-right end for-2 move-left end move-left for-2 move-left end move-left for-4 move-right end move-down move-down move-down for-5 move-right end for-2 move-down end move-right for-3 move-right end move-down move-down for-2 move-down end move-left move-left move-down for-4 move-right end for-4 move-right end move-down move-down move-down for-2 move-left end for-2 move-down end move-down move-down for-5 move-left end for-7 move-down end move-down for-2 move-left end for-2 move-right end for-2 move-down end move-down for-3 move-down end move-left move-left for-2 move-left end move-up move-left for-7 move-right end move-right for-2 move-right end move-up for-2 move-down end move-left move-down move-left for-2 move-down end move-left for-3 move-right end move-left move-right move-right for-4 move-right end move-up move-up move-right move-right for-5 move-left end for-2 move-left end for-3 move-left end move-left for-3 move-left end for-2 move-down end move-right move-left for-3 move-right end move-down move-right for-2 move-left end move-up move-down for-3 move-right end move-right move-left move-down move-right move-right for-7 move-left end move-down for-5 move-right end move-down for-2 move-down end for-2 move-down end move-down move-down for-2 move-down end for-2 move-up end for-2 move-up end move-right for-3 move-left end for-2 move-right end move-right for-2 move-down end for-2 move-up end move-left move-left for-2 move-up end for-5 move-right end move-up for-3 move-down end move-right for-4 move-up end move-right for-2 move-right end move-down move-right move-up move-up move-up for-2 move-up end move-right move-right for-2 move-right end move-right for-4 move-right end move-right for-2 move-right end for-2 move-right end move-up for-2 move-left end move-right move-up move-up move-left move-left move-up move-up move-left move-left move-up move-up move-up for-2 move-right end for-2 move-up end for-2 move-up end for-2 move-up end move-down move-left for-5 move-up end for-3 move-up end for-5 move-up end move-left move-left for-2 move-right end move-up move-left move-right for-2 move-down end for-3 move-left end move-right for-2 move-up end move-up move-right for-2 move-right end move-left for-2 move-right end for-2 move-right end for-2 move-right end move-down for-2 move-left end move-right for-3 move-left end move-left for-2 move-left end for-2 move-right end for-3 move-up end for-5 move-right end for-3 move-right end move-right move-right move-right for-2 move-left end for-2 move-right end move-left for-2 move-left end move-right for-3 move-right end move-right move-up move-right move-right move-down move-left move-down move-left move-right move-up move-right move-right move-right for-2 move-left end move-right for-2 move-up end move-up move-up move-left move-up move-left move-right move-up move-right move-right move-right move-up move-right for-2 move-left end move-left move-left move-up move-down move-left for-2 move-left end for-5 move-left end for-2 move-down end move-right move-right for-3 move-left end for-3 move-up end move-up for-2 move-left end for-4 move-right end for-3 move-right end for-3 move-up end move-up for-2 move-up end move-left for-2 move-right end for-2 move-left end move-left move-left for-2 move-up end move-left move-up move-left for-2 move-left end move-up move-up for-2 move-up end for-2 move-up end move-up move-up move-right move-right for-2 move-right end for-2 move-down end move-right for-5 move-down end move-down move-right for-3 move-left end move-left move-left move-left for-2 move-up end move-up for-2 move-up end for-3 move-up end move-left for-2 move-right end for-2 move-up end move-left move-left for-2 move-up end move-left for-3 move-left end move-down for-2 move-down end move-down for-2 move-up end for-5 move-up end for-3 move-up end move-right move-up for-3 move-right end for-2 move-up end for-4 move-up end move-right move-right for-2 move-left end move-left move-down for-4 move-down end move-up move-down move-right move-left move-left for-2 move-left end move-up for-2 move-down end move-right move-right move-right for-3 move-right end move-up for-2 move-down end move-down for-2 move-down end for-2 move-down end move-right move-up move-up move-up for-3 move-left end for-3 move-left end for-2 move-right end move-down for-3 move-right end move-right for-2 move-right end for-2 move-down end for-2 move-up end for-3 move-down end move-down for-4 move-down end for-4 move-down end move-left move-left for-4 move-down end for-5 move-right end move-down move-down move-left for-3 move-down end move-up move-down move-left for-3 move-down end for-2 move-down end move-right for-2 move-right end for-7 move-left end for-3 move-down end for-6 move-right end for-2 move-down end for-4 move-left end move-left for-3 move-left end move-down for-5 move-left end for-4 move-down end for-5 move-left end move-right move-left move-left move-right for-2 move-down end for-2 move-right end move-right move-down for-4 move-left end for-2 move-left end move-right for-2 move-up end for-3 move-up end move-up for-2 move-right end for-2 move-up end move-up move-right for-2 move-left end move-left for-2 move-left end move-left move-up for-2 move-left end move-left move-right for-2 move-up end move-up move-right move-right for-3 move-right end for-2 move-right end for-5 move-down end for-3 move-up end for-2 move-up end for-2 move-up end for-2 move-up end for-3 move-down end move-up move-down move-up move-down for-4 move-right end move-down move-right move-right for-2 move-down end move-right move-down move-down move-down move-down move-down for-3 move-up end for-2 move-up end for-3 move-up end move-up move-up move-up move-up for-4 move-right end move-left move-right for-2 move-up end move-up move-right move-left for-2 move-up end move-right move-right for-2 move-down end move-up for-3 move-right end for-3 move-down end for-2 move-left end move-left for-2 move-right end move-left move-down for-3 move-left end for-2 move-left end move-down move-right for-3 move-down end move-down move-down for-2 move-right end move-right move-right move-right for-3 move-left end move-down move-down for-2 move-up end for-2 move-right end move-up for-2 move-up end for-2 move-down end move-left move-down for-2 move-down end move-up move-right move-left move-right move-up for-4 move-down end move-down for-2 move-right end move-up move-down for-2 move-down end for-2 move-left end for-2 move-left end move-down move-left move-left move-up move-left move-left move-down for-3 move-up end move-down move-right move-left move-down move-down for-3 move-right end for-2 move-down end for-3 move-up end move-up for-3 move-down end move-up move-right move-right move-down for-2 move-up end move-up move-right move-right move-right for-2 move-up end for-3 move-up end move-up for-3 move-left end move-left move-left move-right move-up move-up move-right for-3 move-left end for-2 move-left end for-2 move-left end for-2 move-up end move-left for-3 move-left end for-3 move-up end for-2 move-right end for-5 move-down end for-4 move-down end move-down for-2 move-up end move-down for-2 move-right end for-2 move-up end move-left for-3 move-right end for-2 move-down end move-right move-up move-right move-right move-left move-right move-left move-up for-3 move-down end for-3 move-right end move-down for-3 move-left end move-left move-right move-left move-up move-left for-2 move-down end move-down move-down move-down move-down for-2 move-right end for-2 move-right end for-2 move-right end for-3 move-right end move-right move-left move-up move-down move-down for-3 move-down end for-2 move-down end move-up for-3 move-down end for-2 move-right end for-2 move-up end move-down move-right move-up for-4 move-up end for-2 move-right end for-4 move-right end for-6 move-right end move-down move-right move-right move-right for-5 move-left end move-down move-down for-2 move-left end for-2 move-up end move-down move-down move-left move-up move-up move-up move-up for-4 move-left end move-down move-down for-2 move-left end for-2 move-up end for-2 move-up end for-2 move-up end move-up move-right for-3 move-up end move-up move-left move-left move-right move-down move-down move-up for-2 move-left end move-left move-right for-2 move-right end move-right for-2 move-left end for-2 move-down end move-up move-right move-right for-2 move-left end for-2 move-right end move-up move-up move-up move-down move-left move-left for-5 move-right end for-2 move-down end move-up move-right move-down move-up for-3 move-right end move-down for-2 move-right end for-2 move-right end for-4 move-down end for-2 move-left end for-3 move-right end move-right move-down for-3 move-up end for-4 move-right end for-3 move-right end move-left move-right move-up move-right for-2 move-up end move-up move-right move-right move-up move-left for-3 move-right end move-up for-3 move-right end for-3 move-up end for-2 move-up end move-up move-up for-2 move-up end for-5 move-left end for-6 move-up end move-down for-2 move-left end move-left move-up for-2 move-up end move-right move-right for-5 move-left end move-up move-right for-2 move-up end move-left move-left move-up move-up for-4 move-up end move-up for-2 move-left end move-up move-left for-2 move-left end for-3 move-right end for-2 move-right end for-2 move-right end move-down move-down for-2 move-up end for-4 move-right end move-right move-right move-down for-3 move-down end move-down move-down move-left move-left for-2 move-left end move-left move-left for-2 move-down end for-3 move-down end move-up move-down for-2 move-up end move-right for-2 move-right end for-3 move-up end move-up for-3 move-down end move-up move-down move-down for-2 move-down end for-2 move-right end for-3 move-down end move-right move-right move-down for-3 move-right end for-3 move-right end for-3 move-left end move-left for-4 move-down end for-3 move-right end for-2 move-right end move-right for-3 move-left end move-left for-2 move-up end move-left move-down for-2 move-up end move-left for-2 move-left end for-2 move-right end move-right for-3 move-down end for-2 move-down end for-2 move-down end move-down move-left move-right move-left for-2 move-right end for-2 move-left end for-4 move-down end for-4 move-left end for-2 move-down end for-6 move-down end for-2 move-down end move-down for-2 move-down end move-right move-right move-down for-2 move-right end for-3 move-down end move-down move-left for-2 move-right end move-down move-down move-up move-up for-3 move-left end move-left for-2 move-up end move-left move-down move-down for-2 move-down end move-right move-right move-right for-2 move-down end move-down move-down move-up move-left for-5 move-right end for-2 move-left end move-left move-left move-down for-4 move-down end move-down move-down for-5 move-up end for-6 move-right end move-down for-3 move-up end for-2 move-up end move-up move-right for-2 move-down end for-2 move-down end for-3 move-down end move-down move-down for-2 move-down end move-left move-left for-4 move-down end for-2 move-left end for-3 move-right end move-right move-right move-up for-2 move-right end move-right for-5 move-left end for-3 move-down end for-3 move-down end move-down for-2 move-right end move-up move-left move-right move-up move-down for-2 move-down end move-left move-down for-5 move-up end for-3 move-left end move-up for-2 move-up end for-2 move-up end move-up move-up move-up for-3 move-up end for-5 move-left end move-up move-left move-right move-down move-right move-right move-left move-right move-left for-2 move-right end move-right for-3 move-left end move-left move-down for-3 move-down end move-up for-2 move-right end move-right move-right move-left move-right for-3 move-down end move-up move-up move-down move-left for-3 move-right end move-left for-3 move-left end move-right move-left move-down move-down for-2 move-up end for-5 move-right end for-3 move-right end for-3 move-up end for-4 move-up end move-right for-3 move-left end move-down move-down for-3 move-up end move-up move-right for-3 move-up end move-down move-down move-right move-down move-down move-down move-down for-3 move-left end for-3 move-up end move-down move-down for-2 move-down end for-2 move-left end for-3 move-down end move-down for-2 move-right end move-down for-2 move-down end move-left move-up move-left move-down for-2 move-up end move-right for-3 move-up end move-up for-2 move-down end for-5 move-down end for-3 move-right end move-down for-2 move-down end for-2 move-right end for-2 move-right end move-right for-3 move-right end move-right move-down for-2 move-down end for-3 move-up end move-down for-2 move-right end for-5 move-up end move-down move-up for-3 move-left end move-left move-up for-2 move-up end move-right move-up for-2 move-left end move-right for-2 move-left end move-right for-2 move-down end move-left move-right move-right for-2 move-left end for-3 move-right end for-2 move-down end for-4 move-right end move-right for-2 move-up end move-down for-3 move-up end for-6 move-left end for-2 move-left end for-3 move-left end for-2 move-left end for-2 move-left end move-left move-up move-up move-right move-up move-up move-left move-down move-down move-down move-left move-up move-up for-2 move-up end move-up move-up move-up move-left move-right move-down for-2 move-up end move-down move-right for-2 move-down end for-3 move-right end move-left move-right move-right for-2 move-right end move-right move-right move-right for-2 move-right end move-up for-4 move-down end for-3 move-down end move-down for-2 move-left end move-left for-2 move-right end for-3 move-down end """) ```
2
362
B
Petya and Staircases
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order).
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "10 5\n2 4 8 3 6", "output": "NO" }, { "input": "10 5\n2 4 5 7 9", "output": "YES" }, { "input": "10 9\n2 3 4 5 6 7 8 9 10", "output": "NO" }, { "input": "5 2\n4 5", "output": "NO" }, { "input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "output": "YES" }, { "input": "10 10\n7 6 4 2 5 10 8 3 9 1", "output": "NO" }, { "input": "12312 0", "output": "YES" }, { "input": "9817239 1\n6323187", "output": "YES" }, { "input": "1 1\n1", "output": "NO" }, { "input": "5 4\n4 2 5 1", "output": "NO" }, { "input": "5 3\n4 3 5", "output": "NO" }, { "input": "500 3\n18 62 445", "output": "YES" }, { "input": "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 405 177 142 114 27 20 445 235 46 176 88 488 242 391 28 414 145 92 206 334 152 343 367 254 100 243 155 348 148 450 461 483 97 34 471 69 416 362", "output": "NO" }, { "input": "500 8\n365 313 338 410 482 417 325 384", "output": "YES" }, { "input": "1000000000 10\n2 3 5 6 8 9 123 874 1230 1000000000", "output": "NO" }, { "input": "1000000000 10\n1 2 3 5 6 8 9 123 874 1230", "output": "NO" }, { "input": "10 1\n1", "output": "NO" }, { "input": "10 4\n1 2 4 5", "output": "NO" }, { "input": "50 20\n22 33 17 23 27 5 26 31 41 20 8 24 6 3 4 29 40 25 13 16", "output": "NO" }, { "input": "50 40\n14 27 19 30 31 20 28 11 37 29 23 33 7 26 22 16 1 6 18 3 47 36 38 2 48 9 41 8 5 50 4 45 44 25 39 12 43 42 40 46", "output": "NO" }, { "input": "123 12\n35 95 47 99 79 122 58 94 31 57 18 10", "output": "YES" }, { "input": "10 5\n1 3 5 7 9", "output": "NO" }, { "input": "100 7\n2 3 5 6 8 9 100", "output": "NO" }, { "input": "100 3\n98 99 100", "output": "NO" }, { "input": "100 3\n97 98 99", "output": "NO" }, { "input": "100 3\n96 98 99", "output": "YES" }, { "input": "10 6\n2 3 5 6 8 9", "output": "YES" }, { "input": "1000000000 10\n2 4 10 18 40 42 49 58 59 60", "output": "NO" }, { "input": "10 3\n1 4 6", "output": "NO" }, { "input": "8 3\n2 3 4", "output": "NO" }, { "input": "100 3\n4 5 6", "output": "NO" }, { "input": "10 2\n10 1", "output": "NO" }, { "input": "10 1\n10", "output": "NO" }, { "input": "4 2\n2 3", "output": "YES" }, { "input": "2 1\n1", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "4 3\n2 3 4", "output": "NO" }, { "input": "5 3\n4 2 3", "output": "NO" } ]
1,671,877,609
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() z=[] d=1 for i in range(m-1): if(a[i+1]-a[i]>1): z.append(a[i]+1) z.append(a[i+1]-1) e=0 for i in range(len(z)): if(z[i]-d<=3): d=z[i] else: e=1 break if(e==1): print("NO") else: print("YES")
Title: Petya and Staircases Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order). Output Specification: Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". Demo Input: ['10 5\n2 4 8 3 6\n', '10 5\n2 4 5 7 9\n'] Demo Output: ['NO', 'YES'] Note: none
```python n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() z=[] d=1 for i in range(m-1): if(a[i+1]-a[i]>1): z.append(a[i]+1) z.append(a[i+1]-1) e=0 for i in range(len(z)): if(z[i]-d<=3): d=z[i] else: e=1 break if(e==1): print("NO") else: print("YES") ```
0
313
A
Ilya and Bank Account
PROGRAMMING
900
[ "implementation", "number theory" ]
null
null
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
In a single line print an integer — the maximum state of the bank account that Ilya can get.
[ "2230\n", "-10\n", "-100003\n" ]
[ "2230\n", "0\n", "-10000\n" ]
In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
500
[ { "input": "2230", "output": "2230" }, { "input": "-10", "output": "0" }, { "input": "-100003", "output": "-10000" }, { "input": "544883178", "output": "544883178" }, { "input": "-847251738", "output": "-84725173" }, { "input": "423654797", "output": "423654797" }, { "input": "-623563697", "output": "-62356367" }, { "input": "645894116", "output": "645894116" }, { "input": "-384381709", "output": "-38438170" }, { "input": "437587210", "output": "437587210" }, { "input": "-297534606", "output": "-29753460" }, { "input": "891773002", "output": "891773002" }, { "input": "-56712976", "output": "-5671296" }, { "input": "963662765", "output": "963662765" }, { "input": "-272656295", "output": "-27265625" }, { "input": "383441522", "output": "383441522" }, { "input": "-477665112", "output": "-47766511" }, { "input": "791725034", "output": "791725034" }, { "input": "-812168727", "output": "-81216872" }, { "input": "528894922", "output": "528894922" }, { "input": "-479977172", "output": "-47997712" }, { "input": "568044564", "output": "568044564" }, { "input": "-392784794", "output": "-39278474" }, { "input": "925596634", "output": "925596634" }, { "input": "-836078769", "output": "-83607876" }, { "input": "71036059", "output": "71036059" }, { "input": "-337396162", "output": "-33739612" }, { "input": "87129297", "output": "87129297" }, { "input": "-648171877", "output": "-64817187" }, { "input": "20218400", "output": "20218400" }, { "input": "10", "output": "10" }, { "input": "1000000000", "output": "1000000000" }, { "input": "-1000000000", "output": "-100000000" }, { "input": "-102", "output": "-10" }, { "input": "-120", "output": "-10" }, { "input": "-20", "output": "0" }, { "input": "-15", "output": "-1" }, { "input": "-5575533", "output": "-557553" }, { "input": "-50", "output": "0" }, { "input": "-31", "output": "-1" }, { "input": "-55", "output": "-5" }, { "input": "-81", "output": "-1" }, { "input": "-99", "output": "-9" }, { "input": "-23", "output": "-2" }, { "input": "-41", "output": "-1" }, { "input": "-24", "output": "-2" }, { "input": "46", "output": "46" } ]
1,693,602,699
2,147,483,647
PyPy 3-64
OK
TESTS
47
124
0
#https://codeforces.com/problemset/problem/313/A n = input() if(int(n) > 0): answer = n else: answer = n[:-2] + min(n[-1], n[-2]) print(int(answer))
Title: Ilya and Bank Account Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input Specification: The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. Output Specification: In a single line print an integer — the maximum state of the bank account that Ilya can get. Demo Input: ['2230\n', '-10\n', '-100003\n'] Demo Output: ['2230\n', '0\n', '-10000\n'] Note: In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
```python #https://codeforces.com/problemset/problem/313/A n = input() if(int(n) > 0): answer = n else: answer = n[:-2] + min(n[-1], n[-2]) print(int(answer)) ```
3
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "111010010111", "output": "11110010111" }, { "input": "11110111011100000000", "output": "1111111011100000000" }, { "input": "11110010010100001110110101110011110110100111101", "output": "1111010010100001110110101110011110110100111101" }, { "input": "1001011111010010100111111", "output": "101011111010010100111111" }, { "input": "1111111111", "output": "111111111" }, { "input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101", "output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101" }, { "input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100", "output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100" }, { "input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011", "output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011" }, { "input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011", "output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011" }, { "input": "11", "output": "1" }, { "input": "111", "output": "11" }, { "input": "111111", "output": "11111" }, { "input": "11111", "output": "1111" }, { "input": "1111", "output": "111" } ]
1,576,638,124
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
186
0
line = input() length = len(line) for i in range(length): if(line[i] == "0"): line = line[0: i] + line[i+1:length] break print(line)
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input Specification: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output Specification: In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Demo Input: ['101\n', '110010\n'] Demo Output: ['11\n', '11010\n'] Note: In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
```python line = input() length = len(line) for i in range(length): if(line[i] == "0"): line = line[0: i] + line[i+1:length] break print(line) ```
0
289
B
Polo the Penguin and Matrix
PROGRAMMING
1,400
[ "brute force", "dp", "implementation", "sortings", "ternary search" ]
null
null
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*. In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104).
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
[ "2 2 2\n2 4\n6 8\n", "1 2 7\n6 7\n" ]
[ "4\n", "-1\n" ]
none
1,000
[ { "input": "2 2 2\n2 4\n6 8", "output": "4" }, { "input": "1 2 7\n6 7", "output": "-1" }, { "input": "3 2 1\n5 7\n1 2\n5 100", "output": "104" }, { "input": "3 3 3\n5 8 5\n11 11 17\n14 5 2", "output": "12" }, { "input": "3 3 3\n5 8 5\n11 11 17\n14 5 3", "output": "-1" }, { "input": "2 2 4\n5 5\n5 5", "output": "0" }, { "input": "7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7", "output": "9" }, { "input": "7 7 47\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91", "output": "0" }, { "input": "7 7 47\n47 47 47 47 47 47 47\n47 47 47 47 77 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 127 47", "output": "-1" }, { "input": "7 5 47\n9583 1734 4601 5353 2110\n3802 5165 7985 6293 324\n7045 653 9160 7891 4930\n1781 3520 4178 2298 3943\n1405 2956 5447 5494 6528\n3097 1640 7750 4883 8032\n4225 8455 1875 4789 4366", "output": "1508" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "1 1 8\n12", "output": "0" } ]
1,566,729,811
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
0
a = [] n,m ,dd = map(int, input().split()) for i in range(n): j = list(map(int, input().split())) a = a+j mean = sum(a)//(n*m) diff = 10001 alpha = 0 for i in range(n*m): if abs(mean - a[i]) < diff: diff = abs(mean - a[i]) alpha = a[i] ans = 0 for i in range(n*m): c = abs(alpha - a[i])//dd d = (alpha - a[i])%dd if d==0: ans+=c else: print(-1) exit() print(ans)
Title: Polo the Penguin and Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*. In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so. Input Specification: The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). Output Specification: In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). Demo Input: ['2 2 2\n2 4\n6 8\n', '1 2 7\n6 7\n'] Demo Output: ['4\n', '-1\n'] Note: none
```python a = [] n,m ,dd = map(int, input().split()) for i in range(n): j = list(map(int, input().split())) a = a+j mean = sum(a)//(n*m) diff = 10001 alpha = 0 for i in range(n*m): if abs(mean - a[i]) < diff: diff = abs(mean - a[i]) alpha = a[i] ans = 0 for i in range(n*m): c = abs(alpha - a[i])//dd d = (alpha - a[i])%dd if d==0: ans+=c else: print(-1) exit() print(ans) ```
0
842
A
Kirill And The Game
PROGRAMMING
1,200
[ "brute force", "two pointers" ]
null
null
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this?
First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107).
Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register.
[ "1 10 1 10 1\n", "1 5 6 10 1\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "1 10 1 10 1", "output": "YES" }, { "input": "1 5 6 10 1", "output": "NO" }, { "input": "1 1 1 1 1", "output": "YES" }, { "input": "1 1 1 1 2", "output": "NO" }, { "input": "1 100000 1 100000 100000", "output": "YES" }, { "input": "1 100000 1 100000 100001", "output": "NO" }, { "input": "25 10000 200 10000 5", "output": "YES" }, { "input": "1 100000 10 100000 50000", "output": "NO" }, { "input": "91939 94921 10197 89487 1", "output": "NO" }, { "input": "30518 58228 74071 77671 1", "output": "NO" }, { "input": "46646 79126 78816 91164 5", "output": "NO" }, { "input": "30070 83417 92074 99337 2", "output": "NO" }, { "input": "13494 17544 96820 99660 6", "output": "NO" }, { "input": "96918 97018 10077 86510 9", "output": "YES" }, { "input": "13046 45594 14823 52475 1", "output": "YES" }, { "input": "29174 40572 95377 97669 4", "output": "NO" }, { "input": "79894 92433 8634 86398 4", "output": "YES" }, { "input": "96022 98362 13380 94100 6", "output": "YES" }, { "input": "79446 95675 93934 96272 3", "output": "NO" }, { "input": "5440 46549 61481 99500 10", "output": "NO" }, { "input": "21569 53580 74739 87749 3", "output": "NO" }, { "input": "72289 78297 79484 98991 7", "output": "NO" }, { "input": "88417 96645 92742 98450 5", "output": "NO" }, { "input": "71841 96625 73295 77648 8", "output": "NO" }, { "input": "87969 99230 78041 94736 4", "output": "NO" }, { "input": "4 4 1 2 3", "output": "NO" }, { "input": "150 150 1 2 100", "output": "NO" }, { "input": "99 100 1 100 50", "output": "YES" }, { "input": "7 7 3 6 2", "output": "NO" }, { "input": "10 10 1 10 1", "output": "YES" }, { "input": "36 36 5 7 6", "output": "YES" }, { "input": "73 96 1 51 51", "output": "NO" }, { "input": "3 3 1 3 2", "output": "NO" }, { "input": "10000000 10000000 1 100000 10000000", "output": "YES" }, { "input": "9222174 9829060 9418763 9955619 9092468", "output": "NO" }, { "input": "70 70 1 2 50", "output": "NO" }, { "input": "100 200 1 20 5", "output": "YES" }, { "input": "1 200000 65536 65536 65537", "output": "NO" }, { "input": "15 15 1 100 1", "output": "YES" }, { "input": "10000000 10000000 1 10000000 100000", "output": "YES" }, { "input": "10 10 2 5 4", "output": "NO" }, { "input": "67 69 7 7 9", "output": "NO" }, { "input": "100000 10000000 1 10000000 100000", "output": "YES" }, { "input": "9 12 1 2 7", "output": "NO" }, { "input": "5426234 6375745 2636512 8492816 4409404", "output": "NO" }, { "input": "6134912 6134912 10000000 10000000 999869", "output": "NO" }, { "input": "3 3 1 100 1", "output": "YES" }, { "input": "10000000 10000000 10 10000000 100000", "output": "YES" }, { "input": "4 4 1 100 2", "output": "YES" }, { "input": "8 13 1 4 7", "output": "NO" }, { "input": "10 10 100000 10000000 10000000", "output": "NO" }, { "input": "5 6 1 4 2", "output": "YES" }, { "input": "1002 1003 1 2 1000", "output": "NO" }, { "input": "4 5 1 2 2", "output": "YES" }, { "input": "5 6 1 5 1", "output": "YES" }, { "input": "15 21 2 4 7", "output": "YES" }, { "input": "4 5 3 7 1", "output": "YES" }, { "input": "15 15 3 4 4", "output": "NO" }, { "input": "3 6 1 2 2", "output": "YES" }, { "input": "2 10 3 6 3", "output": "YES" }, { "input": "1 10000000 1 10000000 100000", "output": "YES" }, { "input": "8 13 1 2 7", "output": "NO" }, { "input": "98112 98112 100000 100000 128850", "output": "NO" }, { "input": "2 2 1 2 1", "output": "YES" }, { "input": "8 8 3 4 2", "output": "YES" }, { "input": "60 60 2 3 25", "output": "NO" }, { "input": "16 17 2 5 5", "output": "NO" }, { "input": "2 4 1 3 1", "output": "YES" }, { "input": "4 5 1 2 3", "output": "NO" }, { "input": "10 10 3 4 3", "output": "NO" }, { "input": "10 10000000 999999 10000000 300", "output": "NO" }, { "input": "100 120 9 11 10", "output": "YES" }, { "input": "8 20 1 3 4", "output": "YES" }, { "input": "10 14 2 3 4", "output": "YES" }, { "input": "2000 2001 1 3 1000", "output": "YES" }, { "input": "12 13 2 3 5", "output": "NO" }, { "input": "7 7 2 3 3", "output": "NO" }, { "input": "5 8 1 10000000 4", "output": "YES" }, { "input": "5 5 1 1 4", "output": "NO" }, { "input": "5 5 1 6 2", "output": "NO" }, { "input": "200 300 4000381 4000382 4000381", "output": "NO" }, { "input": "11 17 2 5 2", "output": "NO" }, { "input": "9999999 10000000 1 10000000 999997", "output": "NO" }, { "input": "7 8 2 3 3", "output": "NO" }, { "input": "7 7 3 3 2", "output": "NO" }, { "input": "15 15 2 3 7", "output": "NO" }, { "input": "65408 65408 859 859 10000000", "output": "NO" }, { "input": "1000000 10000000 1 100000 1", "output": "NO" }, { "input": "6 12 2 3 2", "output": "YES" }, { "input": "7 8 1 3 3", "output": "NO" }, { "input": "4 4 1 2 2", "output": "YES" }, { "input": "2 3 1 2 2", "output": "YES" }, { "input": "11 14 2 3 5", "output": "NO" }, { "input": "7 7 1 10 3", "output": "NO" }, { "input": "49 50 1 2 27", "output": "NO" }, { "input": "1 10000000 1 10000000 123456", "output": "YES" }, { "input": "100000 10000000 100 10000000 100000", "output": "YES" }, { "input": "17 19 2 3 8", "output": "NO" }, { "input": "4 6 3 9 1", "output": "YES" }, { "input": "19 20 6 7 3", "output": "NO" }, { "input": "5000000 10000000 1 4999999 1", "output": "NO" } ]
1,504,033,424
524
PyPy 3
WRONG_ANSWER
TESTS
13
108
307,200
l, r, x, y, k = map(int, input().split(' ')) b = x if l <= b * k <= r: print('YES') else: print("NO")
Title: Kirill And The Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this? Input Specification: First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). Output Specification: Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register. Demo Input: ['1 10 1 10 1\n', '1 5 6 10 1\n'] Demo Output: ['YES', 'NO'] Note: none
```python l, r, x, y, k = map(int, input().split(' ')) b = x if l <= b * k <= r: print('YES') else: print("NO") ```
0
639
B
Bear and Forgotten Tree 3
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "trees" ]
null
null
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values *n*, *d* and *h*: - The tree had exactly *n* vertices. - The tree had diameter *d*. In other words, *d* was the biggest distance between two vertices. - Limak also remembers that he once rooted the tree in vertex 1 and after that its height was *h*. In other words, *h* was the biggest distance between vertex 1 and some other vertex. The distance between two vertices of the tree is the number of edges on the simple path between them. Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1".
The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.
If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes). Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order.
[ "5 3 2\n", "8 5 2\n", "8 4 2\n" ]
[ "1 2\n1 3\n3 4\n3 5", "-1\n", "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n" ]
Below you can see trees printed to the output in the first sample and the third sample.
750
[ { "input": "5 3 2", "output": "1 2\n2 3\n1 4\n5 1" }, { "input": "8 5 2", "output": "-1" }, { "input": "8 4 2", "output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5" }, { "input": "2 1 1", "output": "1 2" }, { "input": "10 3 3", "output": "1 2\n2 3\n3 4\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2" }, { "input": "15 6 4", "output": "1 2\n2 3\n3 4\n4 5\n1 6\n6 7\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1" }, { "input": "16 15 14", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n1 16" }, { "input": "1000 51 25", "output": "-1" }, { "input": "100000 10 7", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n1 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..." }, { "input": "3 1 1", "output": "-1" }, { "input": "3 2 1", "output": "1 2\n1 3" }, { "input": "3 2 2", "output": "1 2\n2 3" }, { "input": "4 1 1", "output": "-1" }, { "input": "4 2 1", "output": "1 2\n1 3\n4 1" }, { "input": "4 2 2", "output": "1 2\n2 3\n4 2" }, { "input": "4 3 1", "output": "-1" }, { "input": "4 3 2", "output": "1 2\n2 3\n1 4" }, { "input": "4 3 3", "output": "1 2\n2 3\n3 4" }, { "input": "8 5 3", "output": "1 2\n2 3\n3 4\n1 5\n5 6\n7 1\n8 1" }, { "input": "20 19 19", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20" }, { "input": "30 14 14", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2" }, { "input": "33 5 3", "output": "1 2\n2 3\n3 4\n1 5\n5 6\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1" }, { "input": "5432 200 100", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "5433 200 99", "output": "-1" }, { "input": "99999 1 1", "output": "-1" }, { "input": "99999 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "99999 7 4", "output": "1 2\n2 3\n3 4\n4 5\n1 6\n6 7\n7 8\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "9999 7 3", "output": "-1" }, { "input": "100000 1 1", "output": "-1" }, { "input": "100000 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "100000 2 2", "output": "1 2\n2 3\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2\n31 2\n32 2\n33 2\n34 2\n35 2\n36 2\n37 2\n38 2\n39 2\n40 2\n41 2\n42 2\n43 2\n44 2\n45 2\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 2\n54 2\n55 2\n56 2\n57 2\n58 2\n59 2\n60 2\n61 2\n62 2\n63 2\n64 2\n65 2\n66 2\n67 2\n68 2\n69 2\n70 2\n71 2\n72 2\n73 2\n74 2\n75 2\n76 2\n77 2\n78 2\n79 2\n80 2\n81 2\n82 2\n83 2\n84 2\n85 2\n86 2\n87 2\n88 ..." }, { "input": "100000 3 1", "output": "-1" }, { "input": "100000 10 5", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n1 7\n7 8\n8 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..." }, { "input": "100000 10 6", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88..." }, { "input": "100000 10 9", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n1 11\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "100000 10 10", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n12 2\n13 2\n14 2\n15 2\n16 2\n17 2\n18 2\n19 2\n20 2\n21 2\n22 2\n23 2\n24 2\n25 2\n26 2\n27 2\n28 2\n29 2\n30 2\n31 2\n32 2\n33 2\n34 2\n35 2\n36 2\n37 2\n38 2\n39 2\n40 2\n41 2\n42 2\n43 2\n44 2\n45 2\n46 2\n47 2\n48 2\n49 2\n50 2\n51 2\n52 2\n53 2\n54 2\n55 2\n56 2\n57 2\n58 2\n59 2\n60 2\n61 2\n62 2\n63 2\n64 2\n65 2\n66 2\n67 2\n68 2\n69 2\n70 2\n71 2\n72 2\n73 2\n74 2\n75 2\n76 2\n77 2\n78 2\n79 2\n80 2\n81 2\n82 2\n83 2\n84 2\n85 2\n86 2\n87 2\n88..." }, { "input": "100000 99900 78900", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 1", "output": "-1" }, { "input": "100000 99998 49999", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 50000", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 69001", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 99055", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99998 99998", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 1", "output": "-1" }, { "input": "100000 99999 49999", "output": "-1" }, { "input": "100000 99999 50000", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 50001", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 77777", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 99998", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "100000 99999 99999", "output": "1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 ..." }, { "input": "3 1 1", "output": "-1" }, { "input": "5 1 1", "output": "-1" }, { "input": "10 1 1", "output": "-1" }, { "input": "3 2 1", "output": "1 2\n1 3" }, { "input": "8 1 1", "output": "-1" }, { "input": "4 1 1", "output": "-1" }, { "input": "6 1 1", "output": "-1" }, { "input": "20 1 1", "output": "-1" }, { "input": "5 2 1", "output": "1 2\n1 3\n4 1\n5 1" }, { "input": "100 1 1", "output": "-1" }, { "input": "10 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1" }, { "input": "100 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "47 1 1", "output": "-1" }, { "input": "7 1 1", "output": "-1" }, { "input": "4 2 1", "output": "1 2\n1 3\n4 1" }, { "input": "5 2 2", "output": "1 2\n2 3\n4 2\n5 2" }, { "input": "8 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1" }, { "input": "1000 1 1", "output": "-1" }, { "input": "11 1 1", "output": "-1" }, { "input": "15 2 1", "output": "1 2\n1 3\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1" }, { "input": "3 2 2", "output": "1 2\n2 3" }, { "input": "8 2 2", "output": "1 2\n2 3\n4 2\n5 2\n6 2\n7 2\n8 2" } ]
1,461,660,357
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
5,120,000
n,d,h = map(int, input().split()) if n-1 >= d and d >= h and 2*h >= d: for i in range(h): a = str(i+1) + ' ' + str(i+2) print(a) print(str(1)+ ' ' + str(h+2)) for j in range(h+2, d+1): b = str(j) + ' ' + str(j+1) print(b) for k in range(d+2,n+1): c = str(1) + ' ' + str(k) print(c) else: print(-1)
Title: Bear and Forgotten Tree 3 Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values *n*, *d* and *h*: - The tree had exactly *n* vertices. - The tree had diameter *d*. In other words, *d* was the biggest distance between two vertices. - Limak also remembers that he once rooted the tree in vertex 1 and after that its height was *h*. In other words, *h* was the biggest distance between vertex 1 and some other vertex. The distance between two vertices of the tree is the number of edges on the simple path between them. Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1". Input Specification: The first line contains three integers *n*, *d* and *h* (2<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*h*<=≤<=*d*<=≤<=*n*<=-<=1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively. Output Specification: If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes). Otherwise, describe any tree matching Limak's description. Print *n*<=-<=1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order. Demo Input: ['5 3 2\n', '8 5 2\n', '8 4 2\n'] Demo Output: ['1 2\n1 3\n3 4\n3 5', '-1\n', '4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n'] Note: Below you can see trees printed to the output in the first sample and the third sample.
```python n,d,h = map(int, input().split()) if n-1 >= d and d >= h and 2*h >= d: for i in range(h): a = str(i+1) + ' ' + str(i+2) print(a) print(str(1)+ ' ' + str(h+2)) for j in range(h+2, d+1): b = str(j) + ' ' + str(j+1) print(b) for k in range(d+2,n+1): c = str(1) + ' ' + str(k) print(c) else: print(-1) ```
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": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,668,088,803
2,147,483,647
PyPy 3-64
OK
TESTS
30
122
0
inp = input() x= 0 for i in inp: if i.isupper(): x+=1 if x > int(len(inp)/2): print(inp.upper()) else: print(inp.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it 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 inp = input() x= 0 for i in inp: if i.isupper(): x+=1 if x > int(len(inp)/2): print(inp.upper()) else: print(inp.lower()) ```
3.9695
39
D
Cubical Planet
PROGRAMMING
1,100
[ "math" ]
D. Cubical Planet
2
64
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube.
The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly.
Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO".
[ "0 0 0\n0 1 0\n", "1 1 0\n0 1 0\n", "0 0 0\n1 1 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
0
[ { "input": "0 0 0\n0 1 0", "output": "YES" }, { "input": "1 1 0\n0 1 0", "output": "YES" }, { "input": "0 0 0\n1 1 1", "output": "NO" }, { "input": "0 0 0\n1 0 0", "output": "YES" }, { "input": "0 0 0\n0 1 0", "output": "YES" }, { "input": "0 0 0\n1 1 0", "output": "YES" }, { "input": "0 0 0\n0 0 1", "output": "YES" }, { "input": "0 0 0\n1 0 1", "output": "YES" }, { "input": "0 0 0\n0 1 1", "output": "YES" }, { "input": "0 0 0\n1 1 1", "output": "NO" }, { "input": "1 0 0\n0 0 0", "output": "YES" }, { "input": "1 0 0\n0 1 0", "output": "YES" }, { "input": "1 0 0\n1 1 0", "output": "YES" }, { "input": "1 0 0\n0 0 1", "output": "YES" }, { "input": "1 0 0\n1 0 1", "output": "YES" }, { "input": "1 0 0\n0 1 1", "output": "NO" }, { "input": "1 0 0\n1 1 1", "output": "YES" }, { "input": "0 1 0\n0 0 0", "output": "YES" }, { "input": "0 1 0\n1 0 0", "output": "YES" }, { "input": "0 1 0\n1 1 0", "output": "YES" }, { "input": "0 1 0\n0 0 1", "output": "YES" }, { "input": "0 1 0\n1 0 1", "output": "NO" }, { "input": "0 1 0\n0 1 1", "output": "YES" }, { "input": "0 1 0\n1 1 1", "output": "YES" }, { "input": "1 1 0\n0 0 0", "output": "YES" }, { "input": "1 1 0\n1 0 0", "output": "YES" }, { "input": "1 1 0\n0 1 0", "output": "YES" }, { "input": "1 1 0\n0 0 1", "output": "NO" }, { "input": "1 1 0\n1 0 1", "output": "YES" }, { "input": "1 1 0\n0 1 1", "output": "YES" }, { "input": "1 1 0\n1 1 1", "output": "YES" }, { "input": "0 0 1\n0 0 0", "output": "YES" }, { "input": "0 0 1\n1 0 0", "output": "YES" }, { "input": "0 0 1\n0 1 0", "output": "YES" }, { "input": "0 0 1\n1 1 0", "output": "NO" }, { "input": "0 0 1\n1 0 1", "output": "YES" }, { "input": "0 0 1\n0 1 1", "output": "YES" }, { "input": "0 0 1\n1 1 1", "output": "YES" }, { "input": "1 0 1\n0 0 0", "output": "YES" }, { "input": "1 0 1\n1 0 0", "output": "YES" }, { "input": "1 0 1\n0 1 0", "output": "NO" }, { "input": "1 0 1\n1 1 0", "output": "YES" }, { "input": "1 0 1\n0 0 1", "output": "YES" }, { "input": "1 0 1\n0 1 1", "output": "YES" }, { "input": "1 0 1\n1 1 1", "output": "YES" }, { "input": "0 1 1\n0 0 0", "output": "YES" }, { "input": "0 1 1\n1 0 0", "output": "NO" }, { "input": "0 1 1\n0 1 0", "output": "YES" }, { "input": "0 1 1\n1 1 0", "output": "YES" }, { "input": "0 1 1\n0 0 1", "output": "YES" }, { "input": "0 1 1\n1 0 1", "output": "YES" }, { "input": "0 1 1\n1 1 1", "output": "YES" }, { "input": "1 1 1\n0 0 0", "output": "NO" }, { "input": "1 1 1\n1 0 0", "output": "YES" }, { "input": "1 1 1\n0 1 0", "output": "YES" }, { "input": "1 1 1\n1 1 0", "output": "YES" }, { "input": "1 1 1\n0 0 1", "output": "YES" }, { "input": "1 1 1\n1 0 1", "output": "YES" }, { "input": "1 1 1\n0 1 1", "output": "YES" } ]
1,633,532,618
2,147,483,647
Python 3
OK
TESTS
59
124
6,758,400
a,b,c=map(int,input().split()) x,y,z=map(int,input().split()) x=a-x y=b-y z=c-z dist=x**2+y**2+z**2 if dist==3: print('NO') else: print('YES')
Title: Cubical Planet Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube. Input Specification: The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly. Output Specification: Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO". Demo Input: ['0 0 0\n0 1 0\n', '1 1 0\n0 1 0\n', '0 0 0\n1 1 1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python a,b,c=map(int,input().split()) x,y,z=map(int,input().split()) x=a-x y=b-y z=c-z dist=x**2+y**2+z**2 if dist==3: print('NO') else: print('YES') ```
3.918646
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", "output": "888644743" }, { "input": "889", "output": "117099969" }, { "input": "1999", "output": "1331335999" }, { "input": "914", "output": "127259419" }, { "input": "996", "output": "164675486" }, { "input": "17", "output": "833" }, { "input": "50", "output": "20875" }, { "input": "91", "output": "125671" }, { "input": "92", "output": "129858" }, { "input": "256", "output": "2796416" }, { "input": "512", "output": "22370048" }, { "input": "666", "output": "49235271" }, { "input": "667", "output": "49457383" }, { "input": "314", "output": "5160119" }, { "input": "1241", "output": "318541121" }, { "input": "1500", "output": "562501250" }, { "input": "1837", "output": "1033182073" }, { "input": "1000", "output": "166667500" } ]
1,690,108,633
2,147,483,647
Python 3
OK
TESTS
24
92
0
# t = int(input()) # while t>0: n = int(input()) res = n c = 1 for i in range((n-1),0,-1): res+=(i*c) c+=1 print(res) # t-=1
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 # t = int(input()) # while t>0: n = int(input()) res = n c = 1 for i in range((n-1),0,-1): res+=(i*c) c+=1 print(res) # t-=1 ```
3
681
B
Economy Game
PROGRAMMING
1,300
[ "brute force" ]
null
null
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each). Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*? Please help Kolya answer this question.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score.
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).
[ "1359257\n", "17851817\n" ]
[ "YES", "NO" ]
In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
1,000
[ { "input": "1359257", "output": "YES" }, { "input": "17851817", "output": "NO" }, { "input": "1000000000", "output": "YES" }, { "input": "17851818", "output": "YES" }, { "input": "438734347", "output": "YES" }, { "input": "43873430", "output": "YES" }, { "input": "999999987", "output": "YES" }, { "input": "27406117", "output": "NO" }, { "input": "27404883", "output": "NO" }, { "input": "27403649", "output": "NO" }, { "input": "27402415", "output": "NO" }, { "input": "27401181", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "999999244", "output": "YES" }, { "input": "999129999", "output": "YES" }, { "input": "17159199", "output": "NO" }, { "input": "13606913", "output": "NO" }, { "input": "14841529", "output": "NO" }, { "input": "915968473", "output": "YES" }, { "input": "980698615", "output": "YES" }, { "input": "912331505", "output": "YES" }, { "input": "917261049", "output": "YES" }, { "input": "999999997", "output": "YES" }, { "input": "12345", "output": "NO" }, { "input": "1234", "output": "YES" }, { "input": "124690", "output": "YES" }, { "input": "1359257", "output": "YES" }, { "input": "1358023", "output": "YES" }, { "input": "1234", "output": "YES" }, { "input": "1234567", "output": "YES" }, { "input": "124690", "output": "YES" }, { "input": "1358023", "output": "YES" }, { "input": "123456", "output": "YES" }, { "input": "2592590", "output": "YES" }, { "input": "999999998", "output": "YES" }, { "input": "1356789", "output": "NO" }, { "input": "12345670", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "1480800", "output": "YES" }, { "input": "908000000", "output": "YES" }, { "input": "3000", "output": "NO" }, { "input": "1235801", "output": "YES" }, { "input": "991919191", "output": "YES" }, { "input": "25613715", "output": "YES" }, { "input": "13580237", "output": "YES" }, { "input": "14814804", "output": "YES" }, { "input": "11403961", "output": "YES" }, { "input": "999999989", "output": "YES" }, { "input": "1237035", "output": "YES" }, { "input": "81134231", "output": "YES" }, { "input": "1236", "output": "NO" }, { "input": "1359250", "output": "YES" }, { "input": "100", "output": "NO" }, { "input": "987654321", "output": "YES" }, { "input": "122222", "output": "NO" }, { "input": "123458", "output": "NO" }, { "input": "20987639", "output": "YES" }, { "input": "999973333", "output": "YES" }, { "input": "253082", "output": "YES" }, { "input": "1235", "output": "NO" }, { "input": "803219200", "output": "YES" }, { "input": "100000000", "output": "YES" }, { "input": "1485181", "output": "YES" } ]
1,679,539,672
2,147,483,647
Python 3
OK
TESTS
63
46
0
n = int(input()) for i in range(0, n+1, 1234567): for j in range(0, n-i+1, 123456): if (n - i - j) % 1234 == 0: print("YES") exit() print("NO")
Title: Economy Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each). Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*? Please help Kolya answer this question. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. Output Specification: Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). Demo Input: ['1359257\n', '17851817\n'] Demo Output: ['YES', 'NO'] Note: In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
```python n = int(input()) for i in range(0, n+1, 1234567): for j in range(0, n-i+1, 123456): if (n - i - j) % 1234 == 0: print("YES") exit() print("NO") ```
3
1,003
C
Intense Heat
PROGRAMMING
1,300
[ "brute force", "implementation", "math" ]
null
null
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are. Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows: Suppose we want to analyze the segment of $n$ consecutive days. We have measured the temperatures during these $n$ days; the temperature during $i$-th day equals $a_i$. We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $x$ to day $y$, we calculate it as $\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $k$ consecutive days. For example, if analyzing the measures $[3, 4, 1, 2]$ and $k = 3$, we are interested in segments $[3, 4, 1]$, $[4, 1, 2]$ and $[3, 4, 1, 2]$ (we want to find the maximum value of average temperature over these segments). You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task?
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 5000$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 5000$) — the temperature measures during given $n$ days.
Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $k$ consecutive days. Your answer will be considered correct if the following condition holds: $|res - res_0| &lt; 10^{-6}$, where $res$ is your answer, and $res_0$ is the answer given by the jury's solution.
[ "4 3\n3 4 1 2\n" ]
[ "2.666666666666667\n" ]
none
0
[ { "input": "4 3\n3 4 1 2", "output": "2.666666666666667" }, { "input": "5 1\n3 10 9 10 6", "output": "10.000000000000000" }, { "input": "5 2\n7 3 3 1 8", "output": "5.000000000000000" }, { "input": "5 3\n1 7 6 9 1", "output": "7.333333333333333" }, { "input": "5 4\n5 1 10 6 1", "output": "5.500000000000000" }, { "input": "5 5\n4 6 6 6 2", "output": "4.800000000000000" }, { "input": "3 2\n2 1 2", "output": "1.666666666666667" }, { "input": "1 1\n5000", "output": "5000.000000000000000" } ]
1,595,220,543
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
4,000
6,963,200
n,k = map(int,input().split()) ai = list(map(int,input().split())) minm = 0 for i in range(0,len(ai)): summ = 0 for j in range(i,len(ai)): summ += ai[j] if j-i+1 >= k: res = summ/(j-i+1) minm = max(minm,res) print(minm)
Title: Intense Heat Time Limit: None seconds Memory Limit: None megabytes Problem Description: The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are. Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows: Suppose we want to analyze the segment of $n$ consecutive days. We have measured the temperatures during these $n$ days; the temperature during $i$-th day equals $a_i$. We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $x$ to day $y$, we calculate it as $\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $k$ consecutive days. For example, if analyzing the measures $[3, 4, 1, 2]$ and $k = 3$, we are interested in segments $[3, 4, 1]$, $[4, 1, 2]$ and $[3, 4, 1, 2]$ (we want to find the maximum value of average temperature over these segments). You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? Input Specification: The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 5000$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 5000$) — the temperature measures during given $n$ days. Output Specification: Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $k$ consecutive days. Your answer will be considered correct if the following condition holds: $|res - res_0| &lt; 10^{-6}$, where $res$ is your answer, and $res_0$ is the answer given by the jury's solution. Demo Input: ['4 3\n3 4 1 2\n'] Demo Output: ['2.666666666666667\n'] Note: none
```python n,k = map(int,input().split()) ai = list(map(int,input().split())) minm = 0 for i in range(0,len(ai)): summ = 0 for j in range(i,len(ai)): summ += ai[j] if j-i+1 >= k: res = summ/(j-i+1) minm = max(minm,res) print(minm) ```
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,698,483,766
2,147,483,647
Python 3
MEMORY_LIMIT_EXCEEDED
TESTS
3
156
268,390,400
x, y = map(int, input().split()) b = '' for i in range(x): a = input().split() b = b.join(a) if b.find('C')==-1 or b.find('Y')==-1 or b.find('M')==-1: print('#Black&White') else: print('#Color')
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python x, y = map(int, input().split()) b = '' for i in range(x): a = input().split() b = b.join(a) if b.find('C')==-1 or b.find('Y')==-1 or b.find('M')==-1: print('#Black&White') else: print('#Color') ```
0
0
none
none
none
0
[ "none" ]
null
null
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before. Obviously, the game ends when the entire sheet is cut into 1<=×<=1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers. You are given an *n*<=×<=*m* piece of paper, somebody has already made *k* cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move.
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=109,<=0<=≤<=*k*<=≤<=105) — the sizes of the piece of paper and the number of cuts. Then follow *k* lines, each containing 4 integers *xb**i*,<=*yb**i*,<=*xe**i*,<=*ye**i* (0<=≤<=*xb**i*,<=*xe**i*<=≤<=*n*,<=0<=≤<=*yb**i*,<=*ye**i*<=≤<=*m*) — the coordinates of the ends of the existing cuts. It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border. The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game.
If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).
[ "2 1 0\n", "2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n" ]
[ "FIRST\n1 0 1 1\n", "SECOND\n" ]
none
0
[]
1,689,255,641
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1689255641.7811499")# 1689255641.781198
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before. Obviously, the game ends when the entire sheet is cut into 1<=×<=1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers. You are given an *n*<=×<=*m* piece of paper, somebody has already made *k* cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move. Input Specification: The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=109,<=0<=≤<=*k*<=≤<=105) — the sizes of the piece of paper and the number of cuts. Then follow *k* lines, each containing 4 integers *xb**i*,<=*yb**i*,<=*xe**i*,<=*ye**i* (0<=≤<=*xb**i*,<=*xe**i*<=≤<=*n*,<=0<=≤<=*yb**i*,<=*ye**i*<=≤<=*m*) — the coordinates of the ends of the existing cuts. It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border. The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game. Output Specification: If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them). Demo Input: ['2 1 0\n', '2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n'] Demo Output: ['FIRST\n1 0 1 1\n', 'SECOND\n'] Note: none
```python print("_RANDOM_GUESS_1689255641.7811499")# 1689255641.781198 ```
0
466
C
Number of Ways
PROGRAMMING
1,700
[ "binary search", "brute force", "data structures", "dp", "two pointers" ]
null
null
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=*j*<=≤<=*n*<=-<=1), that .
The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*.
Print a single integer — the number of ways to split the array into three parts with the same sum.
[ "5\n1 2 3 0 3\n", "4\n0 1 -1 0\n", "2\n4 1\n" ]
[ "2\n", "1\n", "0\n" ]
none
1,500
[ { "input": "5\n1 2 3 0 3", "output": "2" }, { "input": "4\n0 1 -1 0", "output": "1" }, { "input": "2\n4 1", "output": "0" }, { "input": "9\n0 0 0 0 0 0 0 0 0", "output": "28" }, { "input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "3\n1 2 3", "output": "0" }, { "input": "100\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "2030" }, { "input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "10\n1 0 0 0 1 1 1 0 1 1", "output": "2" }, { "input": "10\n-2 2 -2 0 -2 -1 1 -1 2 0", "output": "0" }, { "input": "4\n0 2 -1 2", "output": "0" }, { "input": "5\n3 3 -3 3 3", "output": "3" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "8\n-1 -1 -1 -1 -1 -1 -1 -1", "output": "0" }, { "input": "2\n0 0", "output": "0" }, { "input": "4\n1 -1 0 0", "output": "1" }, { "input": "3\n6 -3 6", "output": "0" } ]
1,699,460,082
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
2,000
0
n=int(input()) a=list(map(int,input().split())) t=sum(a) if t%3!=0: print(0) else: ti=t//3 for i in range(1,n): a[i]=a[i-1]+a[i] l,r=0,n-1 tl=tr=0 while l<r: if a[l]==ti: tl+=1 l+=1 elif t-a[r]==ti: tr+=1 r-=1 print(tl*tr)
Title: Number of Ways Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=*j*<=≤<=*n*<=-<=1), that . Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. Output Specification: Print a single integer — the number of ways to split the array into three parts with the same sum. Demo Input: ['5\n1 2 3 0 3\n', '4\n0 1 -1 0\n', '2\n4 1\n'] Demo Output: ['2\n', '1\n', '0\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) t=sum(a) if t%3!=0: print(0) else: ti=t//3 for i in range(1,n): a[i]=a[i-1]+a[i] l,r=0,n-1 tl=tr=0 while l<r: if a[l]==ti: tl+=1 l+=1 elif t-a[r]==ti: tr+=1 r-=1 print(tl*tr) ```
0
144
A
Arrival of the General
PROGRAMMING
800
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
500
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "input": "10\n68 47 67 29 63 71 71 65 54 56", "output": "10" }, { "input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92", "output": "4" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14", "output": "0" }, { "input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42", "output": "7" }, { "input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99", "output": "47" }, { "input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57", "output": "50" }, { "input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13", "output": "3" }, { "input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36", "output": "3" }, { "input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73", "output": "73" }, { "input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68", "output": "7" }, { "input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94", "output": "15" }, { "input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64", "output": "104" }, { "input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97", "output": "33" }, { "input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43", "output": "145" }, { "input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26", "output": "76" }, { "input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34", "output": "15" }, { "input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81", "output": "11" }, { "input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95", "output": "13" }, { "input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15", "output": "104" }, { "input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67", "output": "100" }, { "input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32", "output": "107" }, { "input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22", "output": "50" }, { "input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61", "output": "59" }, { "input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95", "output": "99" }, { "input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "2\n100 99", "output": "0" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "197" }, { "input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87", "output": "0" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 3 2", "output": "2" } ]
1,691,986,510
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
def min_swaps_to_correct_lineup(n, heights): max_height = heights[0] min_height = heights[-1] taller_than_first = sum(1 for height in heights if height > max_height) shorter_than_last = sum(1 for height in heights if height < min_height) return taller_than_first + shorter_than_last n = int(input()) heights = list(map(int, input().split())) result = min_swaps_to_correct_lineup(n, heights) print(result)
Title: Arrival of the General Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. Input Specification: The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. Output Specification: Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. Demo Input: ['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n'] Demo Output: ['2\n', '10\n'] Note: In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
```python def min_swaps_to_correct_lineup(n, heights): max_height = heights[0] min_height = heights[-1] taller_than_first = sum(1 for height in heights if height > max_height) shorter_than_last = sum(1 for height in heights if height < min_height) return taller_than_first + shorter_than_last n = int(input()) heights = list(map(int, input().split())) result = min_swaps_to_correct_lineup(n, heights) print(result) ```
0
126
B
Password
PROGRAMMING
1,700
[ "binary search", "dp", "hashing", "string suffix structures", "strings" ]
null
null
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
[ "fixprefixsuffix\n", "abcdabc\n" ]
[ "fix", "Just a legend" ]
none
1,000
[ { "input": "fixprefixsuffix", "output": "fix" }, { "input": "abcdabc", "output": "Just a legend" }, { "input": "qwertyqwertyqwerty", "output": "qwerty" }, { "input": "papapapap", "output": "papap" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaa" }, { "input": "ghbdtn", "output": "Just a legend" }, { "input": "a", "output": "Just a legend" }, { "input": "aa", "output": "Just a legend" }, { "input": "ab", "output": "Just a legend" }, { "input": "aaa", "output": "a" }, { "input": "aba", "output": "Just a legend" }, { "input": "aab", "output": "Just a legend" }, { "input": "abb", "output": "Just a legend" }, { "input": "abc", "output": "Just a legend" }, { "input": "aaabaabaaaaab", "output": "Just a legend" }, { "input": "aabaaabaaaaab", "output": "aab" }, { "input": "aaabaaaabab", "output": "Just a legend" }, { "input": "abcabcabcabcabc", "output": "abcabcabc" }, { "input": "aaaaabaaaa", "output": "aaaa" }, { "input": "aaaabaaaaaaa", "output": "aaaa" }, { "input": "ghghghgxghghghg", "output": "ghghg" }, { "input": "kincenvizh", "output": "Just a legend" }, { "input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw", "output": "Just a legend" }, { "input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx", "output": "Just a legend" }, { "input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb", "output": "nfbdzgdlbjhrlvfryyjb" }, { "input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp", "output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp" }, { "input": "abcazabca", "output": "a" } ]
1,537,982,306
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
248
0
s = input() len_s = len(s) last_char = s[len_s - 1] i_last_char = s.find(last_char) if i_last_char < 0: print("Just a legend") my_word = s[0:i_last_char + 1] len_word = len(my_word) if my_word in s: s = s[len_word:] if my_word in s: s = s[:len(s) - len_word] if my_word in s: print(my_word) else: print("Just a legend")
Title: Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. Input Specification: You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. Output Specification: Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. Demo Input: ['fixprefixsuffix\n', 'abcdabc\n'] Demo Output: ['fix', 'Just a legend'] Note: none
```python s = input() len_s = len(s) last_char = s[len_s - 1] i_last_char = s.find(last_char) if i_last_char < 0: print("Just a legend") my_word = s[0:i_last_char + 1] len_word = len(my_word) if my_word in s: s = s[len_word:] if my_word in s: s = s[:len(s) - len_word] if my_word in s: print(my_word) else: print("Just a legend") ```
0
835
B
The number on the board
PROGRAMMING
1,100
[ "greedy" ]
null
null
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change. You have to find the minimum number of digits in which these two numbers can differ.
The first line contains integer *k* (1<=≤<=*k*<=≤<=109). The second line contains integer *n* (1<=≤<=*n*<=&lt;<=10100000). There are no leading zeros in *n*. It's guaranteed that this situation is possible.
Print the minimum number of digits in which the initial number and *n* can differ.
[ "3\n11\n", "3\n99\n" ]
[ "1\n", "0\n" ]
In the first example, the initial number could be 12. In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*.
750
[ { "input": "3\n11", "output": "1" }, { "input": "3\n99", "output": "0" }, { "input": "10\n5205602270", "output": "0" }, { "input": "70\n3326631213", "output": "6" }, { "input": "200\n1000000010000000000000000000010000000000000001000001000000000000000000000000000000000000000000000000", "output": "22" }, { "input": "500\n1899337170458531693764539600958943248270674811247191310452938511077656066239840703432499357537079035", "output": "6" }, { "input": "700\n9307216756404590162143344901558545760612901767837570518638460182990196397856220673189163417019781185", "output": "32" }, { "input": "900\n7570423817272967027553082464863962024635217372307919506594193055572300657732661146354209508997483330", "output": "91" }, { "input": "18\n900", "output": "1" }, { "input": "23\n12138", "output": "1" }, { "input": "16\n333", "output": "2" }, { "input": "3\n12", "output": "0" }, { "input": "3\n111", "output": "0" }, { "input": "1\n100", "output": "0" }, { "input": "17\n89", "output": "0" }, { "input": "18\n99", "output": "0" }, { "input": "42\n97779", "output": "2" }, { "input": "2\n11", "output": "0" }, { "input": "6\n33", "output": "0" }, { "input": "45\n23456", "output": "5" }, { "input": "3\n21", "output": "0" }, { "input": "2\n2", "output": "0" }, { "input": "108\n199999899899", "output": "3" }, { "input": "6\n222", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "9\n9", "output": "0" }, { "input": "5\n5", "output": "0" }, { "input": "27\n888", "output": "3" } ]
1,615,020,193
2,147,483,647
Python 3
OK
TESTS
48
93
1,228,800
k=int(input()) p=input() n=sorted(map(int,p)) s=sum(n) if s>=k: print(0) else: i=0 while(s<k): s=s+9-n[i] i+=1 print(i)
Title: The number on the board Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change. You have to find the minimum number of digits in which these two numbers can differ. Input Specification: The first line contains integer *k* (1<=≤<=*k*<=≤<=109). The second line contains integer *n* (1<=≤<=*n*<=&lt;<=10100000). There are no leading zeros in *n*. It's guaranteed that this situation is possible. Output Specification: Print the minimum number of digits in which the initial number and *n* can differ. Demo Input: ['3\n11\n', '3\n99\n'] Demo Output: ['1\n', '0\n'] Note: In the first example, the initial number could be 12. In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*.
```python k=int(input()) p=input() n=sorted(map(int,p)) s=sum(n) if s>=k: print(0) else: i=0 while(s<k): s=s+9-n[i] i+=1 print(i) ```
3
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party?
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", "output": "0" }, { "input": "10 1", "output": "9" }, { "input": "10 240", "output": "0" }, { "input": "9 240", "output": "0" }, { "input": "9 1", "output": "9" }, { "input": "9 235", "output": "1" }, { "input": "9 236", "output": "0" }, { "input": "5 225", "output": "2" }, { "input": "5 226", "output": "1" }, { "input": "4 210", "output": "3" }, { "input": "4 211", "output": "2" }, { "input": "4 191", "output": "3" }, { "input": "10 165", "output": "5" }, { "input": "10 166", "output": "4" }, { "input": "8 100", "output": "7" }, { "input": "8 101", "output": "6" }, { "input": "8 60", "output": "8" }, { "input": "8 61", "output": "7" }, { "input": "10 15", "output": "9" }, { "input": "10 16", "output": "8" }, { "input": "4 100", "output": "4" }, { "input": "4 101", "output": "4" }, { "input": "7 167", "output": "4" }, { "input": "10 164", "output": "5" }, { "input": "9 170", "output": "4" }, { "input": "8 160", "output": "5" }, { "input": "1 100", "output": "1" }, { "input": "8 123", "output": "6" }, { "input": "2 99", "output": "2" }, { "input": "10 88", "output": "7" }, { "input": "1 235", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "4 240", "output": "0" }, { "input": "1 55", "output": "1" }, { "input": "1 240", "output": "0" }, { "input": "3 240", "output": "0" }, { "input": "10 240", "output": "0" }, { "input": "2 240", "output": "0" }, { "input": "10 1", "output": "9" }, { "input": "9 1", "output": "9" }, { "input": "2 236", "output": "0" }, { "input": "10 2", "output": "9" }, { "input": "3 239", "output": "0" }, { "input": "1 237", "output": "0" }, { "input": "7 8", "output": "7" }, { "input": "10 235", "output": "1" } ]
1,675,086,640
2,147,483,647
PyPy 3-64
OK
TESTS
52
62
0
import math n, k = [int(i) for i in input().split(" ")] x = math.floor((-1 + math.sqrt(1+4*(96-2/5*k)))/2) print(min(x, n))
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party? Input Specification: The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. Output Specification: Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. Demo Input: ['3 222\n', '4 190\n', '7 1\n'] Demo Output: ['2\n', '4\n', '7\n'] Note: In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
```python import math n, k = [int(i) for i in input().split(" ")] x = math.floor((-1 + math.sqrt(1+4*(96-2/5*k)))/2) print(min(x, n)) ```
3
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25", "output": "840" }, { "input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44", "output": "922" }, { "input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59", "output": "674" }, { "input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82", "output": "848" }, { "input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93", "output": "902" }, { "input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20", "output": "798" }, { "input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31", "output": "632" }, { "input": "1\n4", "output": "4" }, { "input": "2\n1 4", "output": "4" }, { "input": "3\n1 2 4", "output": "6" }, { "input": "2\n9 3", "output": "12" }, { "input": "2\n1000000000 1001", "output": "1000000000" }, { "input": "3\n1 8 4", "output": "12" }, { "input": "3\n7 4 4", "output": "8" }, { "input": "5\n2 3 4 5 3", "output": "14" }, { "input": "2\n4 5", "output": "4" }, { "input": "3\n2 4 5", "output": "6" }, { "input": "3\n2 2 3", "output": "4" }, { "input": "2\n2 3", "output": "2" }, { "input": "4\n2 3 7 7", "output": "16" }, { "input": "2\n999999999 2", "output": "2" }, { "input": "2\n2 5", "output": "2" }, { "input": "3\n5 3 1", "output": "8" }, { "input": "4\n3 2 5 7", "output": "14" } ]
1,690,988,574
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
46
0
def calc(arr,sum): max = 0; if (sum % 2 == 0): print(sum); return; else: for i in range (len(arr)): if(arr[i]%2==0): continue sum=sum-arr[i] max=max(max,sum) print(max) n = int(input()) arr = [] input_str = input() input_values = input_str.split() arr = [] for value in input_values: arr.append(int(value)) sum=sum(arr); sorted(arr) calc(arr,sum)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. Input Specification: The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. Output Specification: Print the maximum possible even sum that can be obtained if we use some of the given integers. Demo Input: ['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n'] Demo Output: ['6', '3999999996'] Note: In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
```python def calc(arr,sum): max = 0; if (sum % 2 == 0): print(sum); return; else: for i in range (len(arr)): if(arr[i]%2==0): continue sum=sum-arr[i] max=max(max,sum) print(max) n = int(input()) arr = [] input_str = input() input_values = input_str.split() arr = [] for value in input_values: arr.append(int(value)) sum=sum(arr); sorted(arr) calc(arr,sum) ```
-1
84
A
Toy Army
PROGRAMMING
900
[ "math", "number theory" ]
A. Toy Army
2
256
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows. There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore. The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends. You are asked to calculate the maximum total number of soldiers that may be killed during the game.
The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields.
Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.
[ "2\n", "4\n" ]
[ "3\n", "6\n" ]
The first sample test: 1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1. 2) Arcady's soldier 2 shoots at Valera's soldier 1. 3) Valera's soldier 1 shoots at Arcady's soldier 2. There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2.
500
[ { "input": "2", "output": "3" }, { "input": "4", "output": "6" }, { "input": "6", "output": "9" }, { "input": "8", "output": "12" }, { "input": "10", "output": "15" }, { "input": "140", "output": "210" }, { "input": "500", "output": "750" }, { "input": "1000", "output": "1500" }, { "input": "2000", "output": "3000" }, { "input": "50000", "output": "75000" }, { "input": "10000", "output": "15000" }, { "input": "25460", "output": "38190" }, { "input": "54646", "output": "81969" }, { "input": "59790", "output": "89685" }, { "input": "578456", "output": "867684" }, { "input": "56798056", "output": "85197084" }, { "input": "8457980", "output": "12686970" }, { "input": "5687986", "output": "8531979" }, { "input": "10984932", "output": "16477398" }, { "input": "99999994", "output": "149999991" }, { "input": "99999996", "output": "149999994" }, { "input": "99999998", "output": "149999997" }, { "input": "100000000", "output": "150000000" } ]
1,535,012,411
2,147,483,647
PyPy 3
OK
TESTS
23
280
0
print((3 * 2 * int(input())) // 4)
Title: Toy Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows. There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore. The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends. You are asked to calculate the maximum total number of soldiers that may be killed during the game. Input Specification: The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. Output Specification: Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. Demo Input: ['2\n', '4\n'] Demo Output: ['3\n', '6\n'] Note: The first sample test: 1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1. 2) Arcady's soldier 2 shoots at Valera's soldier 1. 3) Valera's soldier 1 shoots at Arcady's soldier 2. There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2.
```python print((3 * 2 * int(input())) // 4) ```
3.93
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
1,593,591,218
2,147,483,647
Python 3
OK
TESTS
43
248
307,200
a=input() b=input() c=int(a)+int(b) a1=list(a) b1=list(b) c1=list(str(c)) while '0' in a1: a1.remove('0') while '0' in b1: b1.remove('0') while '0' in c1: c1.remove('0') a2=''.join(a1) b2=''.join(b1) c3=''.join(c1) c2=int(a2)+int(b2) if(int(c3)==c2): print("YES") else: print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. Input Specification: The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. Output Specification: The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Demo Input: ['101\n102\n', '105\n106\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python a=input() b=input() c=int(a)+int(b) a1=list(a) b1=list(b) c1=list(str(c)) while '0' in a1: a1.remove('0') while '0' in b1: b1.remove('0') while '0' in c1: c1.remove('0') a2=''.join(a1) b2=''.join(b1) c3=''.join(c1) c2=int(a2)+int(b2) if(int(c3)==c2): print("YES") else: print("NO") ```
3.937428
929
A
Прокат велосипедов
PROGRAMMING
1,400
[ "*special", "greedy", "implementation" ]
null
null
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды. Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=&lt;<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=&lt;<=*n*. Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение. За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы. Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком.
В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде. В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания.
Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката.
[ "4 4\n3 6 8 10\n", "2 9\n10 20\n", "12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n" ]
[ "2\n", "-1\n", "6\n" ]
В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы добраться от школы до дома. Во втором примере всего два велопроката, расстояние между которыми 10. Но максимальное расстояние, которое можно проехать на одном велосипеде, равно 9. Поэтому Аркадий не сможет добраться от школы до дома только на велосипедах.
500
[ { "input": "4 4\n3 6 8 10", "output": "2" }, { "input": "2 9\n10 20", "output": "-1" }, { "input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21", "output": "6" }, { "input": "2 1\n11164 11165", "output": "1" }, { "input": "3 7\n45823 45825 45829", "output": "1" }, { "input": "2 100000\n0 100000", "output": "1" }, { "input": "50 15001\n1269 1580 5431 5916 6642 14145 15760 19922 20589 22062 24138 33454 33505 35916 37012 42577 43140 49457 54720 55188 56205 56639 56870 57997 58379 59088 59297 61805 61861 63005 64013 68848 71182 71497 72715 73008 75616 76042 76614 80690 83089 85033 86408 92392 92763 93833 95085 95815 97152 99379", "output": "8" }, { "input": "5 7\n6219 6222 6229 6231 6236", "output": "3" }, { "input": "10 448\n78449 78573 78599 78742 78748 78759 78853 79091 79298 79324", "output": "3" }, { "input": "20 19191\n11272 12386 14108 24663 24932 26547 29656 44677 45436 45654 48562 62367 71049 71238 78182 84042 88736 92026 96836 99343", "output": "6" }, { "input": "2 100000\n1 100000", "output": "1" }, { "input": "2 99999\n0 100000", "output": "-1" }, { "input": "2 2\n1 3", "output": "1" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "2 2\n1 4", "output": "-1" }, { "input": "10 1\n1 2 3 4 5 6 7 8 9 10", "output": "9" } ]
1,521,917,980
2,147,483,647
Python 3
OK
TESTS
52
93
7,065,600
n,k=map(int,input().split()) xs=list(map(int,input().split())) cs=[0] for i in range(1,n): cs.append(n+1) for j in range(i-1,-1,-1): if xs[i]-xs[j]<=k: cs[i]=min(cs[i],cs[j]+1) else: break if cs[i]==n+1: print(-1) quit() print(cs[-1])
Title: Прокат велосипедов Time Limit: None seconds Memory Limit: None megabytes Problem Description: Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды. Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=&lt;<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=&lt;<=*n*. Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение. За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы. Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком. Input Specification: В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде. В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания. Output Specification: Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. Demo Input: ['4 4\n3 6 8 10\n', '2 9\n10 20\n', '12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы добраться от школы до дома. Во втором примере всего два велопроката, расстояние между которыми 10. Но максимальное расстояние, которое можно проехать на одном велосипеде, равно 9. Поэтому Аркадий не сможет добраться от школы до дома только на велосипедах.
```python n,k=map(int,input().split()) xs=list(map(int,input().split())) cs=[0] for i in range(1,n): cs.append(n+1) for j in range(i-1,-1,-1): if xs[i]-xs[j]<=k: cs[i]=min(cs[i],cs[j]+1) else: break if cs[i]==n+1: print(-1) quit() print(cs[-1]) ```
3
75
C
Modified GCD
PROGRAMMING
1,600
[ "binary search", "number theory" ]
C. Modified GCD
2
256
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are divisible by. But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range. You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query.
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109).
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
[ "9 27\n3\n1 5\n10 11\n9 11\n" ]
[ "3\n-1\n9\n" ]
none
1,500
[ { "input": "9 27\n3\n1 5\n10 11\n9 11", "output": "3\n-1\n9" }, { "input": "48 72\n2\n8 29\n29 37", "output": "24\n-1" }, { "input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90", "output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1" }, { "input": "84 36\n1\n18 32", "output": "-1" }, { "input": "90 36\n16\n13 15\n5 28\n11 30\n26 35\n2 8\n19 36\n3 17\n5 14\n4 26\n22 33\n16 33\n18 27\n4 17\n1 2\n29 31\n18 36", "output": "-1\n18\n18\n-1\n6\n-1\n9\n9\n18\n-1\n18\n18\n9\n2\n-1\n18" }, { "input": "84 90\n18\n10 75\n2 40\n30 56\n49 62\n19 33\n5 79\n61 83\n13 56\n73 78\n1 18\n23 35\n14 72\n22 33\n1 21\n8 38\n54 82\n6 80\n57 75", "output": "-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n6\n-1" }, { "input": "84 100\n16\n10 64\n3 61\n19 51\n42 67\n51 68\n12 40\n10 47\n52 53\n37 67\n2 26\n23 47\n17 75\n49 52\n3 83\n63 81\n8 43", "output": "-1\n4\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n4\n-1\n-1\n-1\n4\n-1\n-1" }, { "input": "36 60\n2\n17 25\n16 20", "output": "-1\n-1" }, { "input": "90 100\n8\n55 75\n46 68\n44 60\n32 71\n43 75\n23 79\n47 86\n11 57", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "90 36\n8\n1 19\n10 12\n14 28\n21 24\n8 8\n33 34\n10 26\n15 21", "output": "18\n-1\n18\n-1\n-1\n-1\n18\n18" }, { "input": "48 80\n19\n1 1\n16 16\n1 16\n16 48\n16 80\n16 1000000000\n1000000000 1000000000\n1 1000000000\n500000000 1000000000\n15 17\n17 17\n15 15\n8 8\n8 15\n8 16\n8 17\n7 17\n7 15\n9 15", "output": "1\n16\n16\n16\n16\n16\n-1\n16\n-1\n16\n-1\n-1\n8\n8\n16\n16\n16\n8\n-1" }, { "input": "31607 999002449\n18\n31607 31607\n31606 31608\n31607 31608\n31606 31607\n31606 31606\n31608 31608\n1 31607\n1 31606\n1 31608\n1 1000000000\n31607 1000000000\n31606 1000000000\n31608 1000000000\n1000000000 1000000000\n1 1\n2 31606\n2 31607\n2 31608", "output": "31607\n31607\n31607\n31607\n-1\n-1\n31607\n1\n31607\n31607\n31607\n31607\n-1\n-1\n1\n-1\n31607\n31607" }, { "input": "999999937 999999929\n12\n999999929 999999937\n1 1\n1 1000000000\n2 1000000000\n1 2\n999999937 999999937\n999999929 999999929\n2 2\n3 3\n1 100\n1 999999937\n1 999999929", "output": "-1\n1\n1\n-1\n1\n-1\n-1\n-1\n-1\n1\n1\n1" } ]
1,681,141,145
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
1,638,400
from bisect import bisect_left, bisect_right import math a,b=list(map(int,input().split())) n=int(input()) common_factors=set() i=1 while i<=math.gcd(a,b): if a%i == 0 and b%i==0: common_factors.add(i) i+=1 # print(common_factors) common_factors=list(common_factors) # common_factors.sort() for i in range(n): l,r=list(map(int,input().split())) # idx_left=bisect_left(common_factors,l) idx_right=bisect_right(common_factors,r)-1 if common_factors[idx_right]<l: print(-1) else: print(common_factors[idx_right])
Title: Modified GCD Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are divisible by. But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range. You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query. Input Specification: The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109). Output Specification: Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. Demo Input: ['9 27\n3\n1 5\n10 11\n9 11\n'] Demo Output: ['3\n-1\n9\n'] Note: none
```python from bisect import bisect_left, bisect_right import math a,b=list(map(int,input().split())) n=int(input()) common_factors=set() i=1 while i<=math.gcd(a,b): if a%i == 0 and b%i==0: common_factors.add(i) i+=1 # print(common_factors) common_factors=list(common_factors) # common_factors.sort() for i in range(n): l,r=list(map(int,input().split())) # idx_left=bisect_left(common_factors,l) idx_right=bisect_right(common_factors,r)-1 if common_factors[idx_right]<l: print(-1) else: print(common_factors[idx_right]) ```
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,658,973,005
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n, m = map(int, input().split()) lst = [] for i in range(n): lst.append(list(input().split())) for l in lst: if l == "C" or l == "M" or l == "Y": print("#Color") exit() print("#Black&White")
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python n, m = map(int, input().split()) lst = [] for i in range(n): lst.append(list(input().split())) for l in lst: if l == "C" or l == "M" or l == "Y": print("#Color") exit() print("#Black&White") ```
0
94
A
Restoring Password
PROGRAMMING
900
[ "implementation", "strings" ]
A. Restoring Password
2
256
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password". Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address. Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits. Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
[ "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n", "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n" ]
[ "12345678\n", "30234919\n" ]
none
500
[ { "input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110", "output": "12345678" }, { "input": "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000", "output": "30234919" }, { "input": "00010101101110110101100110101100010101100010101111000101011010011010110010000011\n0101010110\n0001001101\n1001101011\n0000100011\n0010101111\n1110110101\n0001010110\n0110111000\n0000111110\n0010000011", "output": "65264629" }, { "input": "10100100010010010011011001101000100100110110011010011001101011000100110110011010\n1111110011\n1001000111\n1001000100\n1100010011\n0110011010\n0010000001\n1110101110\n0010000110\n0010010011\n1010010001", "output": "98484434" }, { "input": "00101100011111010001001000000110110000000110010011001111111010110010001011000000\n0010000001\n0110010011\n0010000010\n1011001000\n0011111110\n0110001000\n1111010001\n1011000000\n0000100110\n0010110001", "output": "96071437" }, { "input": "10001110111110000001000010001010001110110000100010100010111101101101010000100010\n0000010110\n1101010111\n1000101111\n0001011110\n0011110101\n0101100100\n0110110101\n0000100010\n1000111011\n1110000001", "output": "89787267" }, { "input": "10010100011001010001010101001101010100110100111011001010111100011001000010100000\n0011100000\n1001100100\n0001100100\n0010100000\n0101010011\n0010101110\n0010101111\n0100111011\n1001010001\n1111111110", "output": "88447623" }, { "input": "01101100111000000101011011001110000001011111111000111111100001011010001001011001\n1000000101\n0101101000\n0101110101\n1101011110\n0000101100\n1111111000\n0001001101\n0110111011\n0110110011\n1001011001", "output": "80805519" }, { "input": "11100011000100010110010011101010101010011110001100011010111110011000011010110111\n1110001100\n0110101111\n0100111010\n0101000000\n1001100001\n1010101001\n0000100010\n1010110111\n1100011100\n0100010110", "output": "09250147" }, { "input": "10000110110000010100000010001000111101110110101011110111000100001101000000100010\n0000010100\n0000110001\n0110101011\n1101110001\n1000011011\n0000110100\n0011110111\n1000110010\n0000100010\n0000011011", "output": "40862358" }, { "input": "01000000010000000110100101000110110000100100000001101100001000011111111001010001\n1011000010\n1111101010\n0111110011\n0000000110\n0000001001\n0001111111\n0110010010\n0100000001\n1011001000\n1001010001", "output": "73907059" }, { "input": "01111000111110011001110101110011110000111110010001101100110110100111101011001101\n1110010001\n1001100000\n1100001000\n1010011110\n1011001101\n0111100011\n1101011100\n1110011001\n1111000011\n0010000101", "output": "57680434" }, { "input": "01001100101000100010001011110001000101001001100010010000001001001100101001011111\n1001011111\n1110010111\n0111101011\n1000100010\n0011100101\n0100000010\n0010111100\n0100010100\n1001100010\n0100110010", "output": "93678590" }, { "input": "01110111110000111011101010110110101011010100110111000011101101110101011101001000\n0110000101\n1010101101\n1101010111\n1101011100\n0100110111\n0111011111\n1100011001\n0111010101\n0000111011\n1101001000", "output": "58114879" }, { "input": "11101001111100110101110011010100110011011110100111010110110011000111000011001101\n1100011100\n1100110101\n1011101000\n0011011110\n0011001101\n0100010001\n1110100111\n1010101100\n1110110100\n0101101100", "output": "61146904" }, { "input": "10101010001011010001001001011000100101100001011011101010101110101010001010101000\n0010110101\n1010011010\n1010101000\n1011010001\n1010101011\n0010010110\n0110100010\n1010100101\n0001011011\n0110100001", "output": "23558422" }, { "input": "11110101001100010000110100001110101011011111010100110001000001001010001001101111\n0101101100\n1001101111\n1010101101\n0100101000\n1111110000\n0101010010\n1100010000\n1111010100\n1101000011\n1011111111", "output": "76827631" }, { "input": "10001100110000110111100011001101111110110011110101000011011100001101110000110111\n0011110101\n0101100011\n1000110011\n1011011001\n0111111011\n0101111011\n0000110111\n0100001110\n1000000111\n0110110111", "output": "26240666" }, { "input": "10000100010000111101100100111101111011101000001001100001000110000010010000111101\n1001001111\n0000111101\n1000010001\n0110011101\n0110101000\n1011111001\n0111101110\n1000001001\n1101011111\n0001010100", "output": "21067271" }, { "input": "01101111000110111100011011110001101111001010001100101000110001010101100100000010\n1010001100\n0011010011\n0101010110\n1111001100\n1100011000\n0100101100\n1001100101\n0110111100\n0011001101\n0100000010", "output": "77770029" }, { "input": "10100111011010001011111000000111100000010101000011000010111101010000111010011101\n1010011101\n1010111111\n0110100110\n1111000100\n1110000001\n0000101111\n0011111000\n1000110001\n0101000011\n1010001011", "output": "09448580" }, { "input": "10000111111000011111001010101010010011111001001111000010010100100011000010001100\n1101101110\n1001001111\n0000100101\n1100111010\n0010101010\n1110000110\n1100111101\n0010001100\n1110000001\n1000011111", "output": "99411277" }, { "input": "10110110111011001111101100111100111111011011011011001111110110010011100010000111\n0111010011\n0111101100\n1001101010\n0101000101\n0010000111\n0011111101\n1011001111\n1101111000\n1011011011\n1001001110", "output": "86658594" }, { "input": "01001001100101100011110110111100000110001111001000100000110111110010000000011000\n0100100110\n1000001011\n1000111110\n0000011000\n0101100011\n1101101111\n1111001000\n1011011001\n1000001101\n0010101000", "output": "04536863" }, { "input": "10010100011101000011100100001100101111000010111100000010010000001001001101011101\n1001000011\n1101000011\n1001010001\n1101011101\n1000010110\n0011111101\n0010111100\n0000100100\n1010001000\n0101000110", "output": "21066773" }, { "input": "01111111110101111111011111111111010010000001100000101000100100111001011010001001\n0111111111\n0101111111\n0100101101\n0001100000\n0011000101\n0011100101\n1101001000\n0010111110\n1010001001\n1111000111", "output": "01063858" }, { "input": "00100011111001001010001111000011101000001110100000000100101011101000001001001010\n0010001111\n1001001010\n1010011001\n0011100111\n1000111000\n0011110000\n0000100010\n0001001010\n1111110111\n1110100000", "output": "01599791" }, { "input": "11011101000100110100110011010101100011111010011010010011010010010010100110101111\n0100110100\n1001001010\n0001111101\n1101011010\n1101110100\n1100110101\n0110101111\n0110001111\n0001101000\n1010011010", "output": "40579016" }, { "input": "10000010111101110110011000111110000011100110001111100100000111000011011000001011\n0111010100\n1010110110\n1000001110\n1110000100\n0110001111\n1101110110\n1100001101\n1000001011\n0000000101\n1001000001", "output": "75424967" }, { "input": "11101100101110111110111011111010001111111111000001001001000010001111111110110010\n0101100001\n1111010011\n1110111110\n0100110100\n1110011111\n1000111111\n0010010000\n1110110010\n0011000010\n1111000001", "output": "72259657" }, { "input": "01011110100101111010011000001001100000101001110011010111101011010000110110010101\n0100111100\n0101110011\n0101111010\n0110000010\n0101001111\n1101000011\n0110010101\n0111011010\n0001101110\n1001110011", "output": "22339256" }, { "input": "01100000100101111000100001100010000110000010100100100001100000110011101001110000\n0101111000\n1001110000\n0001000101\n0110110111\n0010100100\n1000011000\n1101110110\n0110000010\n0001011010\n0011001110", "output": "70554591" }, { "input": "11110011011000001001111100110101001000010100100000110011001110011111100100100001\n1010011000\n1111001101\n0100100001\n1111010011\n0100100000\n1001111110\n1010100111\n1000100111\n1000001001\n1100110011", "output": "18124952" }, { "input": "10001001011000100101010110011101011001110010000001010110000101000100101111101010\n0101100001\n1100001100\n1111101010\n1000100101\n0010000001\n0100010010\n0010110110\n0101100111\n0000001110\n1101001110", "output": "33774052" }, { "input": "00110010000111001001001100100010010111101011011110001011111100000101000100000001\n0100000001\n1011011110\n0010111111\n0111100111\n0100111001\n0000010100\n1001011110\n0111001001\n0100010011\n0011001000", "output": "97961250" }, { "input": "01101100001000110101101100101111101110010011010111100011010100010001101000110101\n1001101001\n1000110101\n0110110000\n0111100100\n0011010111\n1110111001\n0001000110\n0000000100\n0001101001\n1011001011", "output": "21954161" }, { "input": "10101110000011010110101011100000101101000110100000101101101101110101000011110010\n0110100000\n1011011011\n0011110010\n0001110110\n0010110100\n1100010010\n0001101011\n1010111000\n0011010110\n0111010100", "output": "78740192" }, { "input": "11000101011100100111010000010001000001001100101100000011000000001100000101011010\n1100010101\n1111101011\n0101011010\n0100000100\n1000110111\n1100100111\n1100101100\n0111001000\n0000110000\n0110011111", "output": "05336882" }, { "input": "11110100010000101110010110001000001011100101100010110011011011111110001100110110\n0101100010\n0100010001\n0000101110\n1100110110\n0101000101\n0011001011\n1111010001\n1000110010\n1111111000\n1010011111", "output": "62020383" }, { "input": "00011001111110000011101011010001010111100110100101000110011111011001100000001100\n0111001101\n0101011110\n0001100111\n1101011111\n1110000011\n0000001100\n0111010001\n1101100110\n1010110100\n0110100101", "output": "24819275" }, { "input": "10111110010011111001001111100101010111010011111001001110101000111110011001111101\n0011111001\n0101011101\n0100001010\n0001110010\n1001111101\n0011101010\n1111001001\n1100100001\n1001101000\n1011111001", "output": "90010504" }, { "input": "01111101111100101010001001011110111001110111110111011111011110110111111011011111\n1111110111\n0010000101\n0110000100\n0111111011\n1011100111\n1100101010\n1011011111\n1100010001\n0111110111\n0010010111", "output": "85948866" }, { "input": "01111100000111110000110010111001111100001001101010110010111010001000101001101010\n0100010101\n1011110101\n1010100100\n1010000001\n1001101010\n0101100110\n1000100010\n0111110000\n1100101110\n0110010110", "output": "77874864" }, { "input": "11100011010000000010011110010111001011111001000111000000001000000000100111100101\n0000000010\n1110001101\n0011010101\n0111100101\n1001000111\n1101001111\n0111010110\n1100101111\n0110000000\n1101101011", "output": "10374003" }, { "input": "01111011100111101110011001000110001111101000111110100100100001011111001011100010\n0110010100\n1100010001\n0111101110\n1001001000\n1010011011\n1000111110\n0010110101\n1011100010\n0101111100\n0110010001", "output": "22955387" }, { "input": "11011010001100000011000100110011010101000110011110110000001100111100001000011111\n0000100010\n1000011111\n1101101000\n0110011110\n0011110000\n1100000011\n0010001100\n0101101000\n0001001100\n1101010100", "output": "25893541" }, { "input": "01011001011111010010101111011001000011001100011101101111011011010011101011110110\n0100001100\n0101100101\n1111111011\n1111010010\n1111101100\n1100011101\n1011000011\n1101001110\n1011110110\n0110001010", "output": "13805878" }, { "input": "11110011011000111111001100111110001111111100000010111100110100110011111111001101\n1111001101\n1001101010\n1100110010\n0011001111\n0001011110\n1000110011\n1000111111\n0110001010\n1001011101\n1100000010", "output": "06369030" }, { "input": "01110011110010000011011001011000001000010110010110011001100001100110001100101000\n0000100001\n0110011000\n1010000010\n1110011101\n0111001111\n1100101000\n0010000011\n0110010000\n1100100101\n0110010110", "output": "46909115" }, { "input": "00001011001111110111111111011111111101110101110100010111010010100101100001010110\n1111110111\n0001010110\n0111011011\n0111000001\n1010010110\n0101110100\n0001000101\n0000111000\n0110100001\n0000101100", "output": "90005541" } ]
1,599,029,159
2,147,483,647
Python 3
OK
TESTS
50
216
0
def splitter(s): li=[] i=0 j=10 for k in range(8): li.append(s[i:j]) i+=10 j+=10 return li list1=splitter(input()) ans="" key_w=[] for i in range(10): key_w.append(input()) for i in list1: ans+=str(key_w.index(i)) print(ans)
Title: Restoring Password Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password". Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address. Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits. Help Igor K. restore his ISQ account by the encrypted password and encryption specification. Input Specification: The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. Output Specification: Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. Demo Input: ['01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n', '10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n'] Demo Output: ['12345678\n', '30234919\n'] Note: none
```python def splitter(s): li=[] i=0 j=10 for k in range(8): li.append(s[i:j]) i+=10 j+=10 return li list1=splitter(input()) ans="" key_w=[] for i in range(10): key_w.append(input()) for i in list1: ans+=str(key_w.index(i)) print(ans) ```
3.946
620
A
Professor GukiZ's Robot
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.
The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot. The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot.
Print the only integer *d* — the minimal number of steps to get the finish position.
[ "0 0\n4 5\n", "3 4\n6 1\n" ]
[ "5\n", "3\n" ]
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position. In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one three times.
0
[ { "input": "0 0\n4 5", "output": "5" }, { "input": "3 4\n6 1", "output": "3" }, { "input": "0 0\n4 6", "output": "6" }, { "input": "1 1\n-3 -5", "output": "6" }, { "input": "-1 -1\n-10 100", "output": "101" }, { "input": "1 -1\n100 -100", "output": "99" }, { "input": "-1000000000 -1000000000\n1000000000 1000000000", "output": "2000000000" }, { "input": "-1000000000 -1000000000\n0 999999999", "output": "1999999999" }, { "input": "0 0\n2 1", "output": "2" }, { "input": "10 0\n100 0", "output": "90" }, { "input": "1 5\n6 4", "output": "5" }, { "input": "0 0\n5 4", "output": "5" }, { "input": "10 1\n20 1", "output": "10" }, { "input": "1 1\n-3 4", "output": "4" }, { "input": "-863407280 504312726\n786535210 -661703810", "output": "1649942490" }, { "input": "-588306085 -741137832\n341385643 152943311", "output": "929691728" }, { "input": "0 0\n4 0", "output": "4" }, { "input": "93097194 -48405232\n-716984003 -428596062", "output": "810081197" }, { "input": "9 1\n1 1", "output": "8" }, { "input": "4 6\n0 4", "output": "4" }, { "input": "2 4\n5 2", "output": "3" }, { "input": "-100000000 -100000000\n100000000 100000123", "output": "200000123" }, { "input": "5 6\n5 7", "output": "1" }, { "input": "12 16\n12 1", "output": "15" }, { "input": "0 0\n5 1", "output": "5" }, { "input": "0 1\n1 1", "output": "1" }, { "input": "-44602634 913365223\n-572368780 933284951", "output": "527766146" }, { "input": "-2 0\n2 -2", "output": "4" }, { "input": "0 0\n3 1", "output": "3" }, { "input": "-458 2\n1255 4548", "output": "4546" }, { "input": "-5 -4\n-3 -3", "output": "2" }, { "input": "4 5\n7 3", "output": "3" }, { "input": "-1000000000 -999999999\n1000000000 999999998", "output": "2000000000" }, { "input": "-1000000000 -1000000000\n1000000000 -1000000000", "output": "2000000000" }, { "input": "-464122675 -898521847\n656107323 -625340409", "output": "1120229998" }, { "input": "-463154699 -654742385\n-699179052 -789004997", "output": "236024353" }, { "input": "982747270 -593488945\n342286841 -593604186", "output": "640460429" }, { "input": "-80625246 708958515\n468950878 574646184", "output": "549576124" }, { "input": "0 0\n1 0", "output": "1" }, { "input": "109810 1\n2 3", "output": "109808" }, { "input": "-9 0\n9 9", "output": "18" }, { "input": "9 9\n9 9", "output": "0" }, { "input": "1 1\n4 3", "output": "3" }, { "input": "1 2\n45 1", "output": "44" }, { "input": "207558188 -313753260\n-211535387 -721675423", "output": "419093575" }, { "input": "-11 0\n0 0", "output": "11" }, { "input": "-1000000000 1000000000\n1000000000 -1000000000", "output": "2000000000" }, { "input": "0 0\n1 1", "output": "1" }, { "input": "0 0\n0 1", "output": "1" }, { "input": "0 0\n-1 1", "output": "1" }, { "input": "0 0\n-1 0", "output": "1" }, { "input": "0 0\n-1 -1", "output": "1" }, { "input": "0 0\n0 -1", "output": "1" }, { "input": "0 0\n1 -1", "output": "1" }, { "input": "10 90\n90 10", "output": "80" }, { "input": "851016864 573579544\n-761410925 -380746263", "output": "1612427789" }, { "input": "1 9\n9 9", "output": "8" }, { "input": "1000 1000\n1000 1000", "output": "0" }, { "input": "1 9\n9 1", "output": "8" }, { "input": "1 90\n90 90", "output": "89" }, { "input": "100 100\n1000 1000", "output": "900" }, { "input": "-1 0\n0 0", "output": "1" }, { "input": "-750595959 -2984043\n649569876 -749608783", "output": "1400165835" }, { "input": "958048496 712083589\n423286949 810566863", "output": "534761547" }, { "input": "146316710 53945094\n-523054748 147499505", "output": "669371458" }, { "input": "50383856 -596516251\n-802950224 -557916272", "output": "853334080" }, { "input": "-637204864 -280290367\n-119020929 153679771", "output": "518183935" }, { "input": "-100 -100\n-60 -91", "output": "40" }, { "input": "337537326 74909428\n-765558776 167951547", "output": "1103096102" }, { "input": "0 81\n18 90", "output": "18" }, { "input": "283722202 -902633305\n-831696497 -160868946", "output": "1115418699" }, { "input": "1000 1000\n-1000 1000", "output": "2000" }, { "input": "5 6\n4 8", "output": "2" }, { "input": "40572000 597493595\n-935051731 368493185", "output": "975623731" }, { "input": "-5 5\n5 5", "output": "10" } ]
1,453,389,413
1,013
Python 3
OK
TESTS
75
62
0
x1,y1=list(map(int,input().split(" "))) x2,y2=list(map(int,input().split(" "))) result1=max(x1,x2)-min(x1,x2) result2=max(y1,y2)-min(y1,y2) print(max(result1,result2))
Title: Professor GukiZ's Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position. Input Specification: The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot. The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. Output Specification: Print the only integer *d* — the minimal number of steps to get the finish position. Demo Input: ['0 0\n4 5\n', '3 4\n6 1\n'] Demo Output: ['5\n', '3\n'] Note: In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position. In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one three times.
```python x1,y1=list(map(int,input().split(" "))) x2,y2=list(map(int,input().split(" "))) result1=max(x1,x2)-min(x1,x2) result2=max(y1,y2)-min(y1,y2) print(max(result1,result2)) ```
3
903
A
Hungry Student Problem
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken. Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks. Help Ivan to answer this question for several values of *x*!
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases. The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat.
Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO.
[ "2\n6\n5\n" ]
[ "YES\nNO\n" ]
In the first example Ivan can buy two small portions. In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
0
[ { "input": "2\n6\n5", "output": "YES\nNO" }, { "input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100", "output": "NO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" }, { "input": "3\n6\n6\n6", "output": "YES\nYES\nYES" }, { "input": "47\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\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n1\n52\n76", "output": "NO\nYES\nYES" }, { "input": "87\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" }, { "input": "3\n3\n2\n1", "output": "YES\nNO\nNO" }, { "input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES" } ]
1,627,404,735
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
77
20,172,800
import math cases = input() for x in range(int(cases)): chunks = input() for y in range(math.ceil(int(chunks) / 7)): if int(chunks) % 3 == 0: print("YES") break else: if int(chunks) < 7: print("NO") else: chunks = int(chunks) - 7
Title: Hungry Student Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken. Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks. Help Ivan to answer this question for several values of *x*! Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases. The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. Output Specification: Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. Demo Input: ['2\n6\n5\n'] Demo Output: ['YES\nNO\n'] Note: In the first example Ivan can buy two small portions. In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
```python import math cases = input() for x in range(int(cases)): chunks = input() for y in range(math.ceil(int(chunks) / 7)): if int(chunks) % 3 == 0: print("YES") break else: if int(chunks) < 7: print("NO") else: chunks = int(chunks) - 7 ```
0
22
A
Second Order Statistics
PROGRAMMING
800
[ "brute force" ]
A. Second Order Statistics
2
256
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
[ "4\n1 2 2 -4\n", "5\n1 2 3 1 1\n" ]
[ "1\n", "2\n" ]
none
0
[ { "input": "4\n1 2 2 -4", "output": "1" }, { "input": "5\n1 2 3 1 1", "output": "2" }, { "input": "1\n28", "output": "NO" }, { "input": "2\n-28 12", "output": "12" }, { "input": "3\n-83 40 -80", "output": "-80" }, { "input": "8\n93 77 -92 26 21 -48 53 91", "output": "-48" }, { "input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49", "output": "-86" }, { "input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94", "output": "-98" }, { "input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46", "output": "-91" }, { "input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89", "output": "-98" }, { "input": "2\n-1 -1", "output": "NO" }, { "input": "3\n-2 -2 -2", "output": "NO" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100", "output": "100" }, { "input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47", "output": "40" }, { "input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90", "output": "-64" }, { "input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93", "output": "-93" }, { "input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83", "output": "-86" }, { "input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43", "output": "-95" }, { "input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92", "output": "-92" }, { "input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12", "output": "-98" }, { "input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100", "output": "-98" }, { "input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92", "output": "-98" }, { "input": "3\n1 2 3", "output": "2" }, { "input": "3\n1 3 2", "output": "2" }, { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 3 1", "output": "2" }, { "input": "3\n3 1 2", "output": "2" }, { "input": "3\n3 2 1", "output": "2" }, { "input": "9\n99 99 99 99 100 100 100 100 100", "output": "100" }, { "input": "5\n-100 -100 -100 -100 -100", "output": "NO" } ]
1,494,082,755
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
92
0
N = int(input()) A = input() A = A.split() for k in range (N): A[k]=int(A[k]) A = list(set(A)) A.sort() print(A[1])
Title: Second Order Statistics Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. Output Specification: If the given sequence has the second order statistics, output this order statistics, otherwise output NO. Demo Input: ['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n'] Demo Output: ['1\n', '2\n'] Note: none
```python N = int(input()) A = input() A = A.split() for k in range (N): A[k]=int(A[k]) A = list(set(A)) A.sort() print(A[1]) ```
-1
991
A
If at first you don't succeed...
PROGRAMMING
1,000
[ "implementation" ]
null
null
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group. Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.
[ "10 10 5 20\n", "2 2 0 4\n", "2 2 2 1\n" ]
[ "5", "-1", "-1" ]
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam. In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible. The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.
500
[ { "input": "10 10 5 20", "output": "5" }, { "input": "2 2 0 4", "output": "-1" }, { "input": "2 2 2 1", "output": "-1" }, { "input": "98 98 97 100", "output": "1" }, { "input": "1 5 2 10", "output": "-1" }, { "input": "5 1 2 10", "output": "-1" }, { "input": "6 7 5 8", "output": "-1" }, { "input": "6 7 5 9", "output": "1" }, { "input": "6 7 5 7", "output": "-1" }, { "input": "50 50 1 100", "output": "1" }, { "input": "8 3 2 12", "output": "3" }, { "input": "10 19 6 25", "output": "2" }, { "input": "1 0 0 99", "output": "98" }, { "input": "0 1 0 98", "output": "97" }, { "input": "1 1 0 97", "output": "95" }, { "input": "1 1 1 96", "output": "95" }, { "input": "0 0 0 0", "output": "-1" }, { "input": "100 0 0 0", "output": "-1" }, { "input": "0 100 0 0", "output": "-1" }, { "input": "100 100 0 0", "output": "-1" }, { "input": "0 0 100 0", "output": "-1" }, { "input": "100 0 100 0", "output": "-1" }, { "input": "0 100 100 0", "output": "-1" }, { "input": "100 100 100 0", "output": "-1" }, { "input": "0 0 0 100", "output": "100" }, { "input": "100 0 0 100", "output": "-1" }, { "input": "0 100 0 100", "output": "-1" }, { "input": "100 100 0 100", "output": "-1" }, { "input": "0 0 100 100", "output": "-1" }, { "input": "100 0 100 100", "output": "-1" }, { "input": "0 100 100 100", "output": "-1" }, { "input": "100 100 100 100", "output": "-1" }, { "input": "10 45 7 52", "output": "4" }, { "input": "38 1 1 68", "output": "30" }, { "input": "8 45 2 67", "output": "16" }, { "input": "36 36 18 65", "output": "11" }, { "input": "10 30 8 59", "output": "27" }, { "input": "38 20 12 49", "output": "3" }, { "input": "8 19 4 38", "output": "15" }, { "input": "36 21 17 72", "output": "32" }, { "input": "14 12 12 89", "output": "75" }, { "input": "38 6 1 44", "output": "1" }, { "input": "13 4 6 82", "output": "-1" }, { "input": "5 3 17 56", "output": "-1" }, { "input": "38 5 29 90", "output": "-1" }, { "input": "22 36 18 55", "output": "15" }, { "input": "13 0 19 75", "output": "-1" }, { "input": "62 65 10 89", "output": "-1" }, { "input": "2 29 31 72", "output": "-1" }, { "input": "1 31 19 55", "output": "-1" }, { "input": "1 25 28 88", "output": "-1" }, { "input": "34 32 28 33", "output": "-1" }, { "input": "43 36 1 100", "output": "22" }, { "input": "16 39 55 70", "output": "-1" }, { "input": "2 3 0 91", "output": "86" }, { "input": "55 29 12 48", "output": "-1" }, { "input": "7 33 20 88", "output": "-1" }, { "input": "40 38 27 99", "output": "48" }, { "input": "18 28 14 84", "output": "52" }, { "input": "34 25 25 92", "output": "58" }, { "input": "4 24 5 76", "output": "-1" }, { "input": "5 22 16 96", "output": "-1" }, { "input": "1 1 0 4", "output": "2" }, { "input": "5 5 3 1", "output": "-1" }, { "input": "0 0 0 1", "output": "1" }, { "input": "2 3 0 8", "output": "3" }, { "input": "5 5 2 5", "output": "-1" }, { "input": "1 2 1 3", "output": "1" }, { "input": "3 0 0 4", "output": "1" }, { "input": "0 0 0 5", "output": "5" }, { "input": "5 5 0 3", "output": "-1" }, { "input": "5 6 1 7", "output": "-1" }, { "input": "10 10 10 11", "output": "1" }, { "input": "0 0 0 10", "output": "10" }, { "input": "5 15 5 30", "output": "15" }, { "input": "3 2 0 7", "output": "2" } ]
1,684,934,045
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
s=input().split() a,b,c,n=int(s[0]),int(s[1]),int(s[2]),int(s[3]) pas=a+b-c if pas<n: print(n-pas) else: print(-1)
Title: If at first you don't succeed... Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group. Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time? Input Specification: The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). Output Specification: If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$. Demo Input: ['10 10 5 20\n', '2 2 0 4\n', '2 2 2 1\n'] Demo Output: ['5', '-1', '-1'] Note: The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam. In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible. The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.
```python s=input().split() a,b,c,n=int(s[0]),int(s[1]),int(s[2]),int(s[3]) pas=a+b-c if pas<n: print(n-pas) else: print(-1) ```
0
931
B
World Cup
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over. Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet.
The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in. It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal.
In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final. Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1.
[ "4 1 2\n", "8 2 6\n", "8 7 5\n" ]
[ "1\n", "Final!\n", "2\n" ]
In the first example teams 1 and 2 meet in the first round. In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds. In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.
1,000
[ { "input": "4 1 2", "output": "1" }, { "input": "8 2 6", "output": "Final!" }, { "input": "8 7 5", "output": "2" }, { "input": "128 30 98", "output": "Final!" }, { "input": "256 128 256", "output": "Final!" }, { "input": "256 2 127", "output": "7" }, { "input": "2 1 2", "output": "Final!" }, { "input": "2 2 1", "output": "Final!" }, { "input": "4 1 3", "output": "Final!" }, { "input": "4 1 4", "output": "Final!" }, { "input": "4 2 1", "output": "1" }, { "input": "4 2 3", "output": "Final!" }, { "input": "4 2 4", "output": "Final!" }, { "input": "4 3 1", "output": "Final!" }, { "input": "4 3 2", "output": "Final!" }, { "input": "4 3 4", "output": "1" }, { "input": "4 4 1", "output": "Final!" }, { "input": "4 4 2", "output": "Final!" }, { "input": "4 4 3", "output": "1" }, { "input": "8 8 7", "output": "1" }, { "input": "8 8 5", "output": "2" }, { "input": "8 8 1", "output": "Final!" }, { "input": "16 4 3", "output": "1" }, { "input": "16 2 4", "output": "2" }, { "input": "16 14 11", "output": "3" }, { "input": "16 3 11", "output": "Final!" }, { "input": "32 10 9", "output": "1" }, { "input": "32 25 28", "output": "2" }, { "input": "32 22 18", "output": "3" }, { "input": "32 17 25", "output": "4" }, { "input": "32 18 3", "output": "Final!" }, { "input": "64 40 39", "output": "1" }, { "input": "64 60 58", "output": "2" }, { "input": "64 34 37", "output": "3" }, { "input": "64 26 24", "output": "4" }, { "input": "64 50 43", "output": "5" }, { "input": "64 17 42", "output": "Final!" }, { "input": "128 116 115", "output": "1" }, { "input": "128 35 33", "output": "2" }, { "input": "128 61 59", "output": "3" }, { "input": "128 116 123", "output": "4" }, { "input": "128 17 15", "output": "5" }, { "input": "128 124 77", "output": "6" }, { "input": "128 4 80", "output": "Final!" }, { "input": "256 224 223", "output": "1" }, { "input": "256 24 22", "output": "2" }, { "input": "256 199 196", "output": "3" }, { "input": "256 148 159", "output": "4" }, { "input": "256 178 166", "output": "5" }, { "input": "256 75 97", "output": "6" }, { "input": "256 185 200", "output": "7" }, { "input": "256 3 238", "output": "Final!" }, { "input": "256 128 129", "output": "Final!" }, { "input": "256 255 129", "output": "7" }, { "input": "256 255 128", "output": "Final!" }, { "input": "256 129 256", "output": "7" }, { "input": "128 98 69", "output": "6" }, { "input": "128 47 83", "output": "Final!" }, { "input": "16 2 3", "output": "2" }, { "input": "64 32 30", "output": "2" }, { "input": "8 4 5", "output": "Final!" }, { "input": "8 7 8", "output": "1" }, { "input": "8 2 3", "output": "2" }, { "input": "8 2 5", "output": "Final!" } ]
1,658,151,130
2,147,483,647
PyPy 3
OK
TESTS
64
77
0
n,a,b=[int(i) for i in input().split()] ans=[] for i in range(1,n+1): ans.append(i) nd=0 while len(ans)>=2: newans=[] for i in range(0,len(ans)-1,2): if (ans[i]==a and ans[i+1]==b) or (ans[i]==b and ans[i+1]==a): if (len(ans)==2): print('Final!') else: print(nd+1) break elif ans[i]==a or ans[i+1]==a: newans.append(a) elif ans[i]==b or ans[i+1]==b: newans.append(b) else: newans.append(ans[i]) nd+=1 ans=newans
Title: World Cup Time Limit: None seconds Memory Limit: None megabytes Problem Description: The last stage of Football World Cup is played using the play-off system. There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over. Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet. Input Specification: The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in. It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. Output Specification: In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final. Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. Demo Input: ['4 1 2\n', '8 2 6\n', '8 7 5\n'] Demo Output: ['1\n', 'Final!\n', '2\n'] Note: In the first example teams 1 and 2 meet in the first round. In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds. In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.
```python n,a,b=[int(i) for i in input().split()] ans=[] for i in range(1,n+1): ans.append(i) nd=0 while len(ans)>=2: newans=[] for i in range(0,len(ans)-1,2): if (ans[i]==a and ans[i+1]==b) or (ans[i]==b and ans[i+1]==a): if (len(ans)==2): print('Final!') else: print(nd+1) break elif ans[i]==a or ans[i+1]==a: newans.append(a) elif ans[i]==b or ans[i+1]==b: newans.append(b) else: newans.append(ans[i]) nd+=1 ans=newans ```
3
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output": "1" }, { "input": "86", "output": "2" }, { "input": "2", "output": "0" }, { "input": "8", "output": "0" }, { "input": "34", "output": "1" }, { "input": "13", "output": "1" }, { "input": "28", "output": "2" }, { "input": "23", "output": "1" }, { "input": "57", "output": "2" }, { "input": "29", "output": "2" }, { "input": "353869285", "output": "3" }, { "input": "549548646", "output": "2" }, { "input": "858893424", "output": "2" }, { "input": "644818852", "output": "3" }, { "input": "360322525", "output": "3" }, { "input": "122937520", "output": "2" }, { "input": "288403032", "output": "2" }, { "input": "677257481", "output": "3" }, { "input": "58059561", "output": "3" }, { "input": "211288847", "output": "2" }, { "input": "339900034079539584", "output": "2" }, { "input": "784084029310269952", "output": "3" }, { "input": "774730557264864000", "output": "3" }, { "input": "478233807148352256", "output": "3" }, { "input": "165646874056812544", "output": "3" }, { "input": "477533739511673792", "output": "3" }, { "input": "660119944377002240", "output": "3" }, { "input": "448375218506078080", "output": "3" }, { "input": "77213334785795616", "output": "3" }, { "input": "165767221702271872", "output": "3" }, { "input": "1", "output": "0" }, { "input": "5", "output": "0" }, { "input": "8", "output": "0" }, { "input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561", "output": "3" }, { "input": "9", "output": "0" } ]
1,676,460,270
2,147,483,647
Python 3
OK
TESTS
51
1,870
0
n = int(input()) cnt = 0 while n > 9: sum = 0 for i in str(n): sum += int(i) n = sum cnt += 1 print(cnt)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python n = int(input()) cnt = 0 while n > 9: sum = 0 for i in str(n): sum += int(i) n = sum cnt += 1 print(cnt) ```
3.5325
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" }, { "input": "15 15\n4 15\n12 1\n15 6\n11 6\n15 7\n6 8\n15 10\n6 12\n12 8\n15 8\n15 3\n11 9\n7 3\n6 4\n12 11", "output": "4" }, { "input": "12 66\n9 12\n1 4\n8 4\n5 3\n10 5\n12 2\n3 2\n2 7\n1 7\n3 7\n6 2\n4 2\n6 10\n8 10\n4 6\n8 5\n12 6\n11 9\n7 12\n5 4\n11 7\n9 4\n10 4\n6 3\n1 6\n9 7\n3 8\n6 11\n10 9\n3 11\n11 1\n5 12\n8 2\n2 1\n3 1\n12 4\n3 9\n10 12\n8 11\n7 10\n11 5\n9 5\n8 7\n11 4\n8 1\n2 11\n5 1\n3 4\n8 12\n9 2\n10 11\n9 1\n5 7\n10 3\n11 12\n7 4\n2 10\n12 3\n6 8\n7 6\n2 5\n1 10\n12 1\n9 6\n8 9\n6 5", "output": "27" }, { "input": "3 0", "output": "-1" }, { "input": "3 2\n2 3\n2 1", "output": "-1" }, { "input": "3 3\n3 1\n3 2\n2 1", "output": "0" }, { "input": "4 6\n3 4\n1 3\n4 1\n3 2\n2 1\n4 2", "output": "3" }, { "input": "8 10\n1 5\n4 1\n1 2\n2 8\n2 7\n6 3\n5 8\n3 5\n7 8\n1 6", "output": "2" }, { "input": "15 17\n1 3\n7 10\n7 9\n8 13\n6 15\n8 2\n13 6\n10 5\n15 3\n4 15\n4 6\n5 11\n13 9\n12 2\n11 14\n4 12\n14 1", "output": "3" }, { "input": "25 10\n19 11\n19 13\n13 11\n13 22\n19 23\n19 20\n13 17\n19 14\n13 15\n19 4", "output": "7" }, { "input": "987 50\n221 959\n221 553\n959 695\n553 959\n819 437\n371 295\n695 553\n959 347\n595 699\n652 628\n553 347\n868 589\n695 221\n282 714\n351 703\n104 665\n755 436\n556 511\n695 347\n221 347\n243 874\n695 847\n863 501\n583 145\n786 221\n38 286\n72 397\n808 658\n724 437\n911 548\n405 759\n681 316\n648 328\n327 199\n772 139\n932 609\n859 576\n915 507\n379 316\n381 348\n918 871\n261 450\n443 389\n549 246\n901 515\n930 923\n336 545\n179 225\n213 677\n458 204", "output": "6" }, { "input": "4000 0", "output": "-1" } ]
1,620,047,653
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
77
716,800
graph = {} # {node: [idx, idx]} def find_k3(node, parent=None, iter=0): ret = -1 costs = [] for adj in graph[node]: if adj != parent: if iter == 0: cost_next_iter = find_k3(adj, node, iter=1) if cost_next_iter != -1: costs.append((cost_next_iter, (len(graph[adj]) - 2))) if iter == 1: if parent in graph[adj]: costs.append(len(graph[adj]) - 2) if costs: ret = costs return ret def process(): ret = -1 costs = [] for node in graph: if graph[node]: costs_iter = find_k3(node) if costs_iter != -1 and costs_iter[0]: actual_costs_iter = [min(cost[0]) + cost[1] for cost in costs_iter] costs.append(min(actual_costs_iter) + (len(graph[node]) - 2)) costs = list(filter(lambda x : x > 0, costs)) if costs: ret = min(costs) return ret def entrypoint(): n, m = list(map(int, input().split())) for _ in range(m): a, b = list(map(int, input().split())) if not a in graph: graph[a] = [b] else: graph[a].append(b) if not b in graph: graph[b] = [a] else: graph[b].append(a) def main(): entrypoint() print(process()) if __name__ == '__main__': main()
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 graph = {} # {node: [idx, idx]} def find_k3(node, parent=None, iter=0): ret = -1 costs = [] for adj in graph[node]: if adj != parent: if iter == 0: cost_next_iter = find_k3(adj, node, iter=1) if cost_next_iter != -1: costs.append((cost_next_iter, (len(graph[adj]) - 2))) if iter == 1: if parent in graph[adj]: costs.append(len(graph[adj]) - 2) if costs: ret = costs return ret def process(): ret = -1 costs = [] for node in graph: if graph[node]: costs_iter = find_k3(node) if costs_iter != -1 and costs_iter[0]: actual_costs_iter = [min(cost[0]) + cost[1] for cost in costs_iter] costs.append(min(actual_costs_iter) + (len(graph[node]) - 2)) costs = list(filter(lambda x : x > 0, costs)) if costs: ret = min(costs) return ret def entrypoint(): n, m = list(map(int, input().split())) for _ in range(m): a, b = list(map(int, input().split())) if not a in graph: graph[a] = [b] else: graph[a].append(b) if not b in graph: graph[b] = [a] else: graph[b].append(a) def main(): entrypoint() print(process()) if __name__ == '__main__': main() ```
0
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" }, { "input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "output": "IGNORE HIM!" }, { "input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "output": "CHAT WITH HER!" }, { "input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt", "output": "IGNORE HIM!" }, { "input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk", "output": "IGNORE HIM!" }, { "input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz", "output": "IGNORE HIM!" }, { "input": "tgcdptnkc", "output": "IGNORE HIM!" }, { "input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi", "output": "IGNORE HIM!" }, { "input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp", "output": "IGNORE HIM!" }, { "input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia", "output": "IGNORE HIM!" }, { "input": "fpellxwskyekoyvrfnuf", "output": "CHAT WITH HER!" }, { "input": "xninyvkuvakfbs", "output": "IGNORE HIM!" }, { "input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak", "output": "CHAT WITH HER!" }, { "input": "kmsk", "output": "IGNORE HIM!" }, { "input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz", "output": "CHAT WITH HER!" }, { "input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq", "output": "CHAT WITH HER!" }, { "input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm", "output": "IGNORE HIM!" }, { "input": "ppcpbnhwoizajrl", "output": "IGNORE HIM!" }, { "input": "sgubujztzwkzvztitssxxxwzanfmddfqvv", "output": "CHAT WITH HER!" }, { "input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw", "output": "IGNORE HIM!" }, { "input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu", "output": "CHAT WITH HER!" }, { "input": "ojjvpnkrxibyevxk", "output": "CHAT WITH HER!" }, { "input": "wjweqcrqfuollfvfbiyriijovweg", "output": "IGNORE HIM!" }, { "input": "hkdbykboclchfdsuovvpknwqr", "output": "IGNORE HIM!" }, { "input": "stjvyfrfowopwfjdveduedqylerqugykyu", "output": "IGNORE HIM!" }, { "input": "rafcaanqytfclvfdegak", "output": "CHAT WITH HER!" }, { "input": "xczn", "output": "CHAT WITH HER!" }, { "input": "arcoaeozyeawbveoxpmafxxzdjldsielp", "output": "IGNORE HIM!" }, { "input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika", "output": "CHAT WITH HER!" }, { "input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh", "output": "CHAT WITH HER!" }, { "input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg", "output": "CHAT WITH HER!" }, { "input": "udlpagtpq", "output": "CHAT WITH HER!" }, { "input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy", "output": "CHAT WITH HER!" }, { "input": "qagzrqjomdwhagkhrjahhxkieijyten", "output": "CHAT WITH HER!" }, { "input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb", "output": "CHAT WITH HER!" }, { "input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr", "output": "CHAT WITH HER!" }, { "input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc", "output": "IGNORE HIM!" }, { "input": "lnpdosnceumubvk", "output": "IGNORE HIM!" }, { "input": "efrk", "output": "CHAT WITH HER!" }, { "input": "temnownneghnrujforif", "output": "IGNORE HIM!" }, { "input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta", "output": "IGNORE HIM!" }, { "input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh", "output": "IGNORE HIM!" }, { "input": "gwntwbpj", "output": "IGNORE HIM!" }, { "input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim", "output": "IGNORE HIM!" }, { "input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd", "output": "CHAT WITH HER!" }, { "input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx", "output": "IGNORE HIM!" }, { "input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks", "output": "CHAT WITH HER!" }, { "input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx", "output": "CHAT WITH HER!" }, { "input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc", "output": "CHAT WITH HER!" }, { "input": "yzlzmesxdttfcztooypjztlgxwcr", "output": "IGNORE HIM!" }, { "input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc", "output": "IGNORE HIM!" }, { "input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq", "output": "CHAT WITH HER!" }, { "input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj", "output": "IGNORE HIM!" }, { "input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom", "output": "CHAT WITH HER!" }, { "input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo", "output": "CHAT WITH HER!" }, { "input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh", "output": "IGNORE HIM!" }, { "input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa", "output": "CHAT WITH HER!" }, { "input": "oh", "output": "CHAT WITH HER!" }, { "input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri", "output": "IGNORE HIM!" }, { "input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp", "output": "CHAT WITH HER!" }, { "input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp", "output": "CHAT WITH HER!" }, { "input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo", "output": "CHAT WITH HER!" }, { "input": "mnmbupgo", "output": "IGNORE HIM!" }, { "input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl", "output": "IGNORE HIM!" }, { "input": "yocxrzspinchmhtmqo", "output": "CHAT WITH HER!" }, { "input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv", "output": "CHAT WITH HER!" }, { "input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad", "output": "IGNORE HIM!" }, { "input": "ubvhyaebyxoghakajqrpqpctwbrfqzli", "output": "CHAT WITH HER!" }, { "input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy", "output": "IGNORE HIM!" }, { "input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd", "output": "IGNORE HIM!" }, { "input": "acrzbavz", "output": "CHAT WITH HER!" }, { "input": "drvzznznvrzskftnrhvvzxcalwutxmdza", "output": "IGNORE HIM!" }, { "input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws", "output": "CHAT WITH HER!" }, { "input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff", "output": "CHAT WITH HER!" }, { "input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu", "output": "CHAT WITH HER!" }, { "input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw", "output": "IGNORE HIM!" }, { "input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy", "output": "CHAT WITH HER!" }, { "input": "rhh", "output": "CHAT WITH HER!" }, { "input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo", "output": "IGNORE HIM!" }, { "input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn", "output": "CHAT WITH HER!" }, { "input": "urigreuzpxnej", "output": "CHAT WITH HER!" } ]
1,697,478,286
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
x = str(input()) if (len(x)%2!=0): print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. Input Specification: The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. Output Specification: If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Demo Input: ['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n'] Demo Output: ['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n'] Note: For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
```python x = str(input()) if (len(x)%2!=0): print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
0
388
A
Fox and Box Accumulation
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100).
Output a single integer — the minimal possible number of piles.
[ "3\n0 0 10\n", "5\n0 1 2 3 4\n", "4\n0 0 0 0\n", "9\n0 1 0 2 0 1 1 2 10\n" ]
[ "2\n", "1\n", "4\n", "3\n" ]
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
500
[ { "input": "3\n0 0 10", "output": "2" }, { "input": "5\n0 1 2 3 4", "output": "1" }, { "input": "4\n0 0 0 0", "output": "4" }, { "input": "9\n0 1 0 2 0 1 1 2 10", "output": "3" }, { "input": "1\n0", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n100 99", "output": "1" }, { "input": "9\n0 1 1 0 2 0 3 45 4", "output": "3" }, { "input": "10\n1 1 1 1 2 2 2 2 2 2", "output": "4" }, { "input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "2" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "1" }, { "input": "11\n71 34 31 71 42 38 64 60 36 76 67", "output": "1" }, { "input": "39\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54", "output": "1" }, { "input": "59\n61 33 84 76 56 47 70 94 46 77 95 85 35 90 83 62 48 74 36 74 83 97 62 92 95 75 70 82 94 67 82 42 78 70 50 73 80 76 94 83 96 80 80 88 91 79 83 54 38 90 33 93 53 33 86 95 48 34 46", "output": "1" }, { "input": "87\n52 63 93 90 50 35 67 66 46 89 43 64 33 88 34 80 69 59 75 55 55 68 66 83 46 33 72 36 73 34 54 85 52 87 67 68 47 95 52 78 92 58 71 66 84 61 36 77 69 44 84 70 71 55 43 91 33 65 77 34 43 59 83 70 95 38 92 92 74 53 66 65 81 45 55 89 49 52 43 69 78 41 37 79 63 70 67", "output": "1" }, { "input": "15\n20 69 36 63 40 40 52 42 20 43 59 68 64 49 47", "output": "1" }, { "input": "39\n40 20 49 35 80 18 20 75 39 62 43 59 46 37 58 52 67 16 34 65 32 75 59 42 59 41 68 21 41 61 66 19 34 63 19 63 78 62 24", "output": "1" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "18" }, { "input": "46\n14 13 13 10 13 15 8 8 12 9 11 15 8 10 13 8 12 13 11 8 12 15 12 15 11 13 12 9 13 12 10 8 13 15 9 15 8 13 11 8 9 9 9 8 11 8", "output": "3" }, { "input": "70\n6 1 4 1 1 6 5 2 5 1 1 5 2 1 2 4 1 1 1 2 4 5 2 1 6 6 5 2 1 4 3 1 4 3 6 5 2 1 3 4 4 1 4 5 6 2 1 2 4 4 5 3 6 1 1 2 2 1 5 6 1 6 3 1 4 4 2 3 1 4", "output": "11" }, { "input": "94\n11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11", "output": "8" }, { "input": "18\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "46\n14 8 7 4 8 7 8 8 12 9 9 12 9 12 14 8 10 14 14 6 9 11 7 14 14 13 11 4 13 13 11 13 9 10 10 12 10 8 12 10 13 10 7 13 14 6", "output": "4" }, { "input": "74\n4 4 5 5 5 5 5 5 6 6 5 4 4 4 3 3 5 4 5 3 4 4 5 6 3 3 5 4 4 5 4 3 5 5 4 4 3 5 6 4 3 6 6 3 4 5 4 4 3 3 3 6 3 5 6 5 5 5 5 3 6 4 5 4 4 6 6 3 4 5 6 6 6 6", "output": "11" }, { "input": "100\n48 35 44 37 35 42 42 39 49 53 35 55 41 42 42 39 43 49 46 54 48 39 42 53 55 39 56 43 43 38 48 40 54 36 48 55 46 40 41 39 45 56 38 40 47 46 45 46 53 51 38 41 54 35 35 47 42 43 54 54 39 44 49 41 37 49 36 37 37 49 53 44 47 37 55 49 45 40 35 51 44 40 42 35 46 48 53 48 35 38 42 36 54 46 44 47 41 40 41 42", "output": "2" }, { "input": "100\n34 3 37 35 40 44 38 46 13 31 12 23 26 40 26 18 28 36 5 21 2 4 10 29 3 46 38 41 37 28 44 14 39 10 35 17 24 28 38 16 29 6 2 42 47 34 43 2 43 46 7 16 16 43 33 32 20 47 8 48 32 4 45 38 15 7 25 25 19 41 20 35 16 2 31 5 31 25 27 3 45 29 32 36 9 47 39 35 9 21 32 17 21 41 29 48 11 40 5 25", "output": "3" }, { "input": "100\n2 4 5 5 0 5 3 0 3 0 5 3 4 1 0 3 0 5 5 0 4 3 3 3 0 2 1 2 2 4 4 2 4 0 1 3 4 1 4 2 5 3 5 2 3 0 1 2 5 5 2 0 4 2 5 1 0 0 4 0 1 2 0 1 2 4 1 4 5 3 4 5 5 1 0 0 3 1 4 0 4 5 1 3 3 0 4 2 0 4 5 2 3 0 5 1 4 4 1 0", "output": "21" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "17" }, { "input": "100\n1 1 1 2 2 2 2 2 2 1 1 1 2 0 2 2 0 0 0 0 0 2 0 0 2 2 1 0 2 0 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 0 1 2 2 0 2 2 2 2 1 0 1 0 0 0 2 0 2 0 1 1 0 2 2 2 2 1 1 1 2 1 1 2 1 1 1 2 1 0 2 1 0 1 2 0 1 1 2 0 0 1 1 0 1 1", "output": "34" }, { "input": "100\n0 3 1 0 3 2 1 2 2 1 2 1 3 2 1 2 1 3 2 0 0 2 3 0 0 2 1 2 2 3 1 2 2 2 0 3 3 2 0 0 1 0 1 2 3 1 0 3 3 3 0 2 1 3 0 1 3 2 2 2 2 3 3 2 0 2 0 1 0 1 3 0 1 2 0 1 3 2 0 3 1 1 2 3 1 3 1 0 3 0 3 0 2 1 1 1 2 2 0 1", "output": "26" }, { "input": "100\n1 0 2 2 2 2 1 0 1 2 2 2 0 1 0 1 2 1 2 1 0 1 2 2 2 1 0 1 0 2 1 2 0 2 1 1 2 1 1 0 1 2 1 1 2 1 1 0 2 2 0 0 1 2 0 2 0 0 1 1 0 0 2 1 2 1 0 2 2 2 2 2 2 1 2 0 1 2 1 2 1 0 1 0 1 0 1 1 0 2 1 0 0 1 2 2 1 0 0 1", "output": "34" }, { "input": "100\n3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 3 4 4 4 3 4 3 4 3 4 3 3 4 4 3 4 4 3 4 4 4 4 4 3 4 3 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 3 3 3 4 4 3 4 4 3 4 3 3 3 4 4 3 3 3 3 3 4 3 4 4 3 3 4 3 4 3 4 4 4 3 3 3 4 4 4 4 3", "output": "20" }, { "input": "100\n8 7 9 10 2 7 8 11 11 4 7 10 2 5 8 9 10 3 9 4 10 5 5 6 3 8 8 9 6 9 5 5 4 11 4 2 11 8 3 5 6 6 11 9 8 11 9 8 3 3 8 9 8 9 4 8 6 11 4 4 4 9 7 5 3 4 11 3 9 11 8 10 3 5 5 7 6 9 4 5 2 11 3 6 2 10 9 4 6 10 5 11 8 10 10 8 9 8 5 3", "output": "9" }, { "input": "5\n4 1 1 1 1", "output": "2" } ]
1,566,201,458
2,147,483,647
PyPy 3
OK
TESTS
36
140
1,228,800
import math class CodeforcesTask388ASolution: def __init__(self): self.result = '' self.n = 0 self.boxes = [] def read_input(self): self.n = int(input()) self.boxes = [int(x) for x in input().split(" ")] def process_task(self): counts = [self.boxes.count(x) for x in range(max(self.boxes) + 1)] constraints = [math.ceil(sum(counts[0:x + 1]) / (x + 1)) for x in range(len(counts))] self.result = str(max(constraints)) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask388ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result())
Title: Fox and Box Accumulation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). Output Specification: Output a single integer — the minimal possible number of piles. Demo Input: ['3\n0 0 10\n', '5\n0 1 2 3 4\n', '4\n0 0 0 0\n', '9\n0 1 0 2 0 1 1 2 10\n'] Demo Output: ['2\n', '1\n', '4\n', '3\n'] Note: In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
```python import math class CodeforcesTask388ASolution: def __init__(self): self.result = '' self.n = 0 self.boxes = [] def read_input(self): self.n = int(input()) self.boxes = [int(x) for x in input().split(" ")] def process_task(self): counts = [self.boxes.count(x) for x in range(max(self.boxes) + 1)] constraints = [math.ceil(sum(counts[0:x + 1]) / (x + 1)) for x in range(len(counts))] self.result = str(max(constraints)) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask388ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
3
519
B
A and B and Compilation Errors
PROGRAMMING
1,100
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected?
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
1,000
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428", "output": "25720377\n661369649" }, { "input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482", "output": "819602309\n796067435" }, { "input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780", "output": "374054998\n902899520" }, { "input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990", "output": "939116221\n323703261" }, { "input": "3\n77 77 77\n77 77\n77", "output": "77\n77" }, { "input": "3\n84 30 9\n9 84\n9", "output": "30\n84" }, { "input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3", "output": "5\n5" }, { "input": "4\n1 5 7 8\n1 5 7\n1 5", "output": "8\n7" } ]
1,674,663,571
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
zn=int(input()) za=list(map(int,input().split())) zb=list(map(int,input().split())) zc=list(map(int,input().split())) for i in za-zb: print(sum(za)-sum(zb)) for i in zb-zc: print(sum(zb)-sum(zc))
Title: A and B and Compilation Errors Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected? Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. Output Specification: Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. Demo Input: ['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n'] Demo Output: ['8\n123\n', '1\n3\n'] Note: In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
```python zn=int(input()) za=list(map(int,input().split())) zb=list(map(int,input().split())) zc=list(map(int,input().split())) for i in za-zb: print(sum(za)-sum(zb)) for i in zb-zc: print(sum(zb)-sum(zc)) ```
-1
0
none
none
none
0
[ "none" ]
null
null
Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not. A permutation triple of permutations of length *n* (*a*,<=*b*,<=*c*) is called a Lucky Permutation Triple if and only if . The sign *a**i* denotes the *i*-th element of permutation *a*. The modular equality described above denotes that the remainders after dividing *a**i*<=+<=*b**i* by *n* and dividing *c**i* by *n* are equal. Now, he has an integer *n* and wants to find a Lucky Permutation Triple. Could you please help him?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
If no Lucky Permutation Triple of length *n* exists print -1. Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*. If there are multiple solutions, print any of them.
[ "5\n", "2\n" ]
[ "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n", "-1\n" ]
In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds: - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/48cc13134296b68f459f69d78e0240859aaec702.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ac44412de7b46833e90348a6b3298f9796e3977c.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3825b0bb758208dda2ead1c5224c05d89ad9ab55.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0a72e2da40048a507839927a211267ac01c9bf89.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In Sample 2, you can easily notice that no lucky permutation triple exists.
0
[ { "input": "5", "output": "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3" }, { "input": "2", "output": "-1" }, { "input": "8", "output": "-1" }, { "input": "9", "output": "0 1 2 3 4 5 6 7 8 \n0 1 2 3 4 5 6 7 8 \n0 2 4 6 8 1 3 5 7 " }, { "input": "2", "output": "-1" }, { "input": "77", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 4..." }, { "input": "6", "output": "-1" }, { "input": "87", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 \n0 2 4..." }, { "input": "72", "output": "-1" }, { "input": "1", "output": "0 \n0 \n0 " }, { "input": "23", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 2 4 6 8 10 12 14 16 18 20 22 1 3 5 7 9 11 13 15 17 19 21 " }, { "input": "52", "output": "-1" }, { "input": "32", "output": "-1" }, { "input": "25", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n0 2 4 6 8 10 12 14 16 18 20 22 24 1 3 5 7 9 11 13 15 17 19 21 23 " }, { "input": "54", "output": "-1" }, { "input": "39", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 " }, { "input": "20", "output": "-1" }, { "input": "53", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 " }, { "input": "34", "output": "-1" }, { "input": "23", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 2 4 6 8 10 12 14 16 18 20 22 1 3 5 7 9 11 13 15 17 19 21 " }, { "input": "37123", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "41904", "output": "-1" }, { "input": "46684", "output": "-1" }, { "input": "67817", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "72598", "output": "-1" }, { "input": "85891", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "74320", "output": "-1" }, { "input": "11805", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "16586", "output": "-1" }, { "input": "5014", "output": "-1" }, { "input": "73268", "output": "-1" }, { "input": "61697", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "99182", "output": "-1" }, { "input": "79771", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "68199", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "5684", "output": "-1" }, { "input": "10465", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "31598", "output": "-1" }, { "input": "36379", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "16968", "output": "-1" }, { "input": "93061", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "73650", "output": "-1" }, { "input": "94783", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "99564", "output": "-1" }, { "input": "37049", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "25478", "output": "-1" }, { "input": "30259", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "43551", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "31980", "output": "-1" }, { "input": "69465", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "1", "output": "0 \n0 \n0 " }, { "input": "100000", "output": "-1" }, { "input": "99999", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "99998", "output": "-1" } ]
1,566,728,669
2,147,483,647
Python 3
OK
TESTS
54
1,184
2,867,200
n=int(input()); if n%2: print(*[int(i) for i in range(0,n)]) print(*[int(j) for j in range(0,n)]) print(*[int((2*i)%n) for i in range(0,n)]) else: print(-1)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not. A permutation triple of permutations of length *n* (*a*,<=*b*,<=*c*) is called a Lucky Permutation Triple if and only if . The sign *a**i* denotes the *i*-th element of permutation *a*. The modular equality described above denotes that the remainders after dividing *a**i*<=+<=*b**i* by *n* and dividing *c**i* by *n* are equal. Now, he has an integer *n* and wants to find a Lucky Permutation Triple. Could you please help him? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). Output Specification: If no Lucky Permutation Triple of length *n* exists print -1. Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*. If there are multiple solutions, print any of them. Demo Input: ['5\n', '2\n'] Demo Output: ['1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n', '-1\n'] Note: In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds: - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/48cc13134296b68f459f69d78e0240859aaec702.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ac44412de7b46833e90348a6b3298f9796e3977c.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3825b0bb758208dda2ead1c5224c05d89ad9ab55.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0a72e2da40048a507839927a211267ac01c9bf89.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In Sample 2, you can easily notice that no lucky permutation triple exists.
```python n=int(input()); if n%2: print(*[int(i) for i in range(0,n)]) print(*[int(j) for j in range(0,n)]) print(*[int((2*i)%n) for i in range(0,n)]) else: print(-1) ```
3
369
C
Valera and Elections
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "trees" ]
null
null
The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired. There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located. Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road. It's guaranteed that the graph structure of the city is a tree.
In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them.
[ "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n", "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n", "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n" ]
[ "1\n5 \n", "1\n3 \n", "4\n5 4 3 2 \n" ]
none
1,500
[ { "input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2", "output": "1\n5 " }, { "input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1", "output": "1\n3 " }, { "input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2", "output": "4\n5 4 3 2 " }, { "input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2", "output": "1\n2 " }, { "input": "2\n1 2 1", "output": "0" }, { "input": "10\n7 5 1\n2 1 2\n8 7 2\n2 4 1\n4 5 2\n9 5 1\n3 2 2\n2 10 1\n6 5 2", "output": "3\n8 6 3 " }, { "input": "2\n2 1 1", "output": "0" }, { "input": "2\n1 2 2", "output": "1\n2 " }, { "input": "5\n3 1 1\n4 5 1\n1 4 1\n1 2 1", "output": "0" }, { "input": "5\n1 3 2\n5 4 2\n2 1 2\n4 3 2", "output": "2\n5 2 " }, { "input": "10\n1 9 1\n3 2 2\n1 2 2\n4 7 2\n3 5 2\n4 3 2\n10 3 2\n7 8 2\n3 6 1", "output": "3\n8 10 5 " }, { "input": "10\n7 9 2\n2 6 2\n7 4 1\n5 4 2\n3 2 1\n8 5 2\n4 3 2\n7 10 1\n1 2 2", "output": "3\n9 8 6 " }, { "input": "10\n3 9 1\n2 10 2\n1 7 1\n3 4 1\n7 8 2\n1 2 1\n5 3 1\n5 6 2\n2 3 2", "output": "3\n6 10 8 " }, { "input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 1\n7 5 1\n6 4 1\n5 3 1\n4 2 1", "output": "2\n7 8 " }, { "input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 2\n7 5 2\n6 4 2\n5 3 2\n4 2 2", "output": "2\n3 2 " }, { "input": "4\n1 2 2\n2 3 1\n2 4 2", "output": "1\n4 " } ]
1,592,424,525
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
5
436
15,769,600
def find_winners(adj, root, visited): # this ensures that the same node isn't visited again. visited.add(root) winners = set() for neighbour, broken in adj[root]: if neighbour not in visited: subtree_winners = find_winners(adj, neighbour, visited) # Either we get the case that the subtree didn't require # any winner. This is the case when there is no broken # road in the subtree. In this case, the root of the subtree # is required if and only if (root -> subtree_root) is # broken. Else if there is atleast one winner from the # subtree then winners from the subtree will cover # (root -> subtree_root) even if it is broken. So just add # then to the answer as it is. if len(subtree_winners) is 0: if broken == 1: winners.add(neighbour) else: winners = winners.union(subtree_winners) return winners if __name__ == '__main__': N = int(input()) # list of lists representing adjacency matrix adj = [[] for _ in range(N)] # parse edges from the input for _ in range(N - 1): # subtracting does with two things: # 1. convert 1 indexing to 0 indexing # 2. broken and not broken is now 0 and 1 respectively. u, v, broken = [int(x) - 1 for x in input().split()] # append both ways because it is an undirected graph adj[u].append((v, broken)) adj[v].append((u, broken)) parliament_location = 0 # given in the problem result = find_winners(adj, parliament_location, set()) print(len(result)) # Add one to all values in result because we need to print # 1-indexed nodes. print(' '.join([str(x + 1) for x in result]))
Title: Valera and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired. There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located. Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road. It's guaranteed that the graph structure of the city is a tree. Output Specification: In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them. Demo Input: ['5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n', '5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n', '5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n'] Demo Output: ['1\n5 \n', '1\n3 \n', '4\n5 4 3 2 \n'] Note: none
```python def find_winners(adj, root, visited): # this ensures that the same node isn't visited again. visited.add(root) winners = set() for neighbour, broken in adj[root]: if neighbour not in visited: subtree_winners = find_winners(adj, neighbour, visited) # Either we get the case that the subtree didn't require # any winner. This is the case when there is no broken # road in the subtree. In this case, the root of the subtree # is required if and only if (root -> subtree_root) is # broken. Else if there is atleast one winner from the # subtree then winners from the subtree will cover # (root -> subtree_root) even if it is broken. So just add # then to the answer as it is. if len(subtree_winners) is 0: if broken == 1: winners.add(neighbour) else: winners = winners.union(subtree_winners) return winners if __name__ == '__main__': N = int(input()) # list of lists representing adjacency matrix adj = [[] for _ in range(N)] # parse edges from the input for _ in range(N - 1): # subtracting does with two things: # 1. convert 1 indexing to 0 indexing # 2. broken and not broken is now 0 and 1 respectively. u, v, broken = [int(x) - 1 for x in input().split()] # append both ways because it is an undirected graph adj[u].append((v, broken)) adj[v].append((u, broken)) parliament_location = 0 # given in the problem result = find_winners(adj, parliament_location, set()) print(len(result)) # Add one to all values in result because we need to print # 1-indexed nodes. print(' '.join([str(x + 1) for x in result])) ```
-1
841
A
Generous Kefa
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends. Next line contains string *s* — colors of baloons.
Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary.
[ "4 2\naabb\n", "6 3\naacaab\n" ]
[ "YES\n", "NO\n" ]
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
500
[ { "input": "4 2\naabb", "output": "YES" }, { "input": "6 3\naacaab", "output": "NO" }, { "input": "2 2\nlu", "output": "YES" }, { "input": "5 3\novvoo", "output": "YES" }, { "input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf", "output": "YES" }, { "input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv", "output": "NO" }, { "input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "YES" }, { "input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod", "output": "NO" }, { "input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl", "output": "YES" }, { "input": "18 6\njzwtnkvmscqhmdlsxy", "output": "YES" }, { "input": "21 2\nfscegcqgzesefghhwcexs", "output": "NO" }, { "input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc", "output": "YES" }, { "input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd", "output": "YES" }, { "input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv", "output": "YES" }, { "input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul", "output": "YES" }, { "input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii", "output": "NO" }, { "input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq", "output": "YES" }, { "input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb", "output": "YES" }, { "input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc", "output": "YES" }, { "input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab", "output": "YES" }, { "input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia", "output": "NO" }, { "input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf", "output": "YES" }, { "input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb", "output": "YES" }, { "input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa", "output": "NO" }, { "input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo", "output": "YES" }, { "input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib", "output": "YES" }, { "input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf", "output": "YES" }, { "input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci", "output": "YES" }, { "input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn", "output": "YES" }, { "input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev", "output": "YES" }, { "input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss", "output": "YES" }, { "input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs", "output": "NO" }, { "input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc", "output": "NO" }, { "input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi", "output": "NO" }, { "input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah", "output": "NO" }, { "input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka", "output": "YES" }, { "input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq", "output": "YES" }, { "input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb", "output": "YES" }, { "input": "14 5\nfssmmsfffmfmmm", "output": "NO" }, { "input": "2 1\nff", "output": "NO" }, { "input": "2 1\nhw", "output": "YES" }, { "input": "2 2\nss", "output": "YES" }, { "input": "1 1\nl", "output": "YES" }, { "input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp", "output": "YES" }, { "input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj", "output": "YES" }, { "input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj", "output": "YES" }, { "input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "output": "YES" }, { "input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq", "output": "YES" }, { "input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt", "output": "YES" }, { "input": "1 2\na", "output": "YES" }, { "input": "3 1\nabb", "output": "NO" }, { "input": "2 1\naa", "output": "NO" }, { "input": "2 1\nab", "output": "YES" }, { "input": "6 2\naaaaaa", "output": "NO" }, { "input": "8 4\naaaaaaaa", "output": "NO" }, { "input": "4 2\naaaa", "output": "NO" }, { "input": "4 3\naaaa", "output": "NO" }, { "input": "1 3\na", "output": "YES" }, { "input": "4 3\nzzzz", "output": "NO" }, { "input": "4 1\naaaa", "output": "NO" }, { "input": "3 4\nabc", "output": "YES" }, { "input": "2 5\nab", "output": "YES" }, { "input": "2 4\nab", "output": "YES" }, { "input": "1 10\na", "output": "YES" }, { "input": "5 2\nzzzzz", "output": "NO" }, { "input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "NO" }, { "input": "4 1\nabab", "output": "NO" }, { "input": "4 1\nabcb", "output": "NO" }, { "input": "4 2\nabbb", "output": "NO" }, { "input": "5 2\nabccc", "output": "NO" }, { "input": "2 3\nab", "output": "YES" }, { "input": "4 3\nbbbs", "output": "YES" }, { "input": "10 2\nazzzzzzzzz", "output": "NO" }, { "input": "1 2\nb", "output": "YES" }, { "input": "1 3\nb", "output": "YES" }, { "input": "4 5\nabcd", "output": "YES" }, { "input": "4 6\naabb", "output": "YES" }, { "input": "5 2\naaaab", "output": "NO" }, { "input": "3 5\naaa", "output": "YES" }, { "input": "5 3\nazzzz", "output": "NO" }, { "input": "4 100\naabb", "output": "YES" }, { "input": "3 10\naaa", "output": "YES" }, { "input": "3 4\naaa", "output": "YES" }, { "input": "12 5\naaaaabbbbbbb", "output": "NO" }, { "input": "5 2\naabbb", "output": "NO" }, { "input": "10 5\nzzzzzzzzzz", "output": "NO" }, { "input": "2 4\naa", "output": "YES" }, { "input": "1 5\na", "output": "YES" }, { "input": "10 5\naaaaaaaaaa", "output": "NO" }, { "input": "6 3\naaaaaa", "output": "NO" }, { "input": "7 1\nabcdeee", "output": "NO" }, { "input": "18 3\naaaaaabbbbbbcccccc", "output": "NO" }, { "input": "8 2\naabbccdd", "output": "YES" }, { "input": "4 2\nzzzz", "output": "NO" }, { "input": "4 2\nabaa", "output": "NO" }, { "input": "3 2\naaa", "output": "NO" }, { "input": "3 1\nzzz", "output": "NO" }, { "input": "5 4\nzzzzz", "output": "NO" }, { "input": "6 2\naabbbc", "output": "NO" }, { "input": "3 6\naaa", "output": "YES" }, { "input": "2 1\nzz", "output": "NO" }, { "input": "10 3\naaaeeeeeee", "output": "NO" }, { "input": "4 5\naabb", "output": "YES" }, { "input": "3 1\naaa", "output": "NO" }, { "input": "5 2\naazzz", "output": "NO" }, { "input": "6 2\nabbbbc", "output": "NO" }, { "input": "4 2\nxxxx", "output": "NO" }, { "input": "6 3\nzzzzzz", "output": "NO" }, { "input": "3 2\nabb", "output": "YES" }, { "input": "3 2\nzzz", "output": "NO" }, { "input": "6 5\nzzzzzz", "output": "NO" }, { "input": "6 3\nbcaaaa", "output": "NO" }, { "input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "YES" }, { "input": "3 6\nabc", "output": "YES" } ]
1,507,708,390
2,147,483,647
Python 3
OK
TESTS
114
77
0
n,k = input().split() n,k = map(int,[n,k]) s = input() A = [] for i in s: A.append(i) n1 = A.count(max(set(A),key = A.count)) #print(n1) if n1 >k: print('NO') else: print('YES')
Title: Generous Kefa Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends. Next line contains string *s* — colors of baloons. Output Specification: Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary. Demo Input: ['4 2\naabb\n', '6 3\naacaab\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
```python n,k = input().split() n,k = map(int,[n,k]) s = input() A = [] for i in s: A.append(i) n1 = A.count(max(set(A),key = A.count)) #print(n1) if n1 >k: print('NO') else: print('YES') ```
3
451
A
Game With Sticks
PROGRAMMING
900
[ "implementation" ]
null
null
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game?
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
[ "2 2\n", "2 3\n", "3 3\n" ]
[ "Malvika\n", "Malvika\n", "Akshat\n" ]
Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty. In the empty grid, Akshat cannot make any move, hence he will lose. Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
500
[ { "input": "2 2", "output": "Malvika" }, { "input": "2 3", "output": "Malvika" }, { "input": "3 3", "output": "Akshat" }, { "input": "20 68", "output": "Malvika" }, { "input": "1 1", "output": "Akshat" }, { "input": "1 2", "output": "Akshat" }, { "input": "1 3", "output": "Akshat" }, { "input": "2 1", "output": "Akshat" }, { "input": "2 2", "output": "Malvika" }, { "input": "3 1", "output": "Akshat" }, { "input": "3 2", "output": "Malvika" }, { "input": "68 42", "output": "Malvika" }, { "input": "1 35", "output": "Akshat" }, { "input": "25 70", "output": "Akshat" }, { "input": "59 79", "output": "Akshat" }, { "input": "65 63", "output": "Akshat" }, { "input": "46 6", "output": "Malvika" }, { "input": "28 82", "output": "Malvika" }, { "input": "98 98", "output": "Malvika" }, { "input": "98 99", "output": "Malvika" }, { "input": "98 100", "output": "Malvika" }, { "input": "99 98", "output": "Malvika" }, { "input": "99 99", "output": "Akshat" }, { "input": "99 100", "output": "Akshat" }, { "input": "100 98", "output": "Malvika" }, { "input": "100 99", "output": "Akshat" }, { "input": "100 100", "output": "Malvika" }, { "input": "3 4", "output": "Akshat" } ]
1,691,843,857
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
62
0
nm = list(map(int, input().split(" "))) n = nm[0] m = nm[1] res = n*m print("Akshat" if res&1 else "Malvika")
Title: Game With Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game? Input Specification: The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Output Specification: Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. Demo Input: ['2 2\n', '2 3\n', '3 3\n'] Demo Output: ['Malvika\n', 'Malvika\n', 'Akshat\n'] Note: Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty. In the empty grid, Akshat cannot make any move, hence he will lose. Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
```python nm = list(map(int, input().split(" "))) n = nm[0] m = nm[1] res = n*m print("Akshat" if res&1 else "Malvika") ```
0
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcdefghijklm" }, { "input": "100 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "100 10", "output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij" }, { "input": "3 3", "output": "abc" }, { "input": "6 3", "output": "abcabc" }, { "input": "10 3", "output": "abcabcabca" }, { "input": "50 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab" }, { "input": "90 2", "output": "ababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "6 2", "output": "ababab" }, { "input": "99 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc" }, { "input": "4 2", "output": "abab" }, { "input": "100 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "40 22", "output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr" }, { "input": "13 8", "output": "abcdefghabcde" }, { "input": "16 15", "output": "abcdefghijklmnoa" }, { "input": "17 17", "output": "abcdefghijklmnopq" }, { "input": "19 4", "output": "abcdabcdabcdabcdabc" }, { "input": "100 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv" }, { "input": "100 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy" }, { "input": "26 26", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "27 26", "output": "abcdefghijklmnopqrstuvwxyza" }, { "input": "2 2", "output": "ab" }, { "input": "26 25", "output": "abcdefghijklmnopqrstuvwxya" }, { "input": "99 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababa" }, { "input": "99 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu" }, { "input": "4 4", "output": "abcd" }, { "input": "5 3", "output": "abcab" }, { "input": "5 4", "output": "abcda" }, { "input": "5 5", "output": "abcde" }, { "input": "24 22", "output": "abcdefghijklmnopqrstuvab" }, { "input": "26 14", "output": "abcdefghijklmnabcdefghijkl" }, { "input": "26 15", "output": "abcdefghijklmnoabcdefghijk" }, { "input": "30 12", "output": "abcdefghijklabcdefghijklabcdef" }, { "input": "35 4", "output": "abcdabcdabcdabcdabcdabcdabcdabcdabc" }, { "input": "79 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "79 14", "output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi" }, { "input": "85 13", "output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg" }, { "input": "90 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno" }, { "input": "90 19", "output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn" }, { "input": "26 24", "output": "abcdefghijklmnopqrstuvwxab" }, { "input": "100 17", "output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno" }, { "input": "26 2", "output": "ababababababababababababab" } ]
1,643,476,018
2,147,483,647
Python 3
OK
TESTS
47
46
0
n, k = map(int, input().split()) answer = '' for i in range(n): answer += chr(97 + i % k) print(answer)
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. Input Specification: The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists. Output Specification: Print any password which satisfies all conditions given by Innokentiy. Demo Input: ['4 3\n', '6 6\n', '5 2\n'] Demo Output: ['java\n', 'python\n', 'phphp\n'] Note: In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
```python n, k = map(int, input().split()) answer = '' for i in range(n): answer += chr(97 + i % k) print(answer) ```
3
847
G
University Classes
PROGRAMMING
900
[ "implementation" ]
null
null
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups. Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Print minimum number of rooms needed to hold all groups classes on Monday.
[ "2\n0101010\n1010101\n", "3\n0101011\n0011001\n0110111\n" ]
[ "1\n", "3\n" ]
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group. In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
0
[ { "input": "2\n0101010\n1010101", "output": "1" }, { "input": "3\n0101011\n0011001\n0110111", "output": "3" }, { "input": "1\n0111000", "output": "1" }, { "input": "1\n0000000", "output": "0" }, { "input": "1\n1111111", "output": "1" }, { "input": "2\n1000000\n0101000", "output": "1" }, { "input": "3\n0101111\n1101011\n1010011", "output": "3" }, { "input": "5\n0100101\n0000001\n0110000\n0010000\n0011110", "output": "3" }, { "input": "6\n1101110\n1111011\n1101110\n0100011\n1110110\n1110100", "output": "6" }, { "input": "10\n0000000\n0010000\n0000000\n0000010\n0000000\n0100001\n1000000\n0000000\n0000000\n0000000", "output": "1" }, { "input": "20\n1111111\n1101011\n1111011\n0111111\n1111111\n1110111\n1111111\n1111111\n1111111\n1111111\n1110111\n1111111\n0111111\n1011111\n1111111\n1111111\n1101110\n1111111\n1111111\n1111111", "output": "20" } ]
1,505,742,489
2,589
Python 3
OK
TESTS
21
62
4,608,000
n = int(input()) ans = 0 ans1 = 0 arr_ans = [] arr_slot = [] for i in range(n): arr_slot.append(input()) for i in range(7): for j in range(n): arr_ans.append(arr_slot[j][i]) ans = arr_ans.count("1") if ans > ans1: ans1 = ans ans = 0 arr_ans = [] print(ans1)
Title: University Classes Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups. Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot. Output Specification: Print minimum number of rooms needed to hold all groups classes on Monday. Demo Input: ['2\n0101010\n1010101\n', '3\n0101011\n0011001\n0110111\n'] Demo Output: ['1\n', '3\n'] Note: In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group. In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
```python n = int(input()) ans = 0 ans1 = 0 arr_ans = [] arr_slot = [] for i in range(n): arr_slot.append(input()) for i in range(7): for j in range(n): arr_ans.append(arr_slot[j][i]) ans = arr_ans.count("1") if ans > ans1: ans1 = ans ans = 0 arr_ans = [] print(ans1) ```
3
0
none
none
none
0
[ "none" ]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
0
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000 1000", "output": "100" }, { "input": "8\n200000 1 200000 1 200000 1 200000 2", "output": "1" }, { "input": "5\n20000 1 2 3 4", "output": "20000" }, { "input": "2\n200000 1", "output": "200000" }, { "input": "3\n2 100 2", "output": "100" }, { "input": "2\n10 1", "output": "10" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "3\n5 5 5", "output": "5" }, { "input": "2\n5 1", "output": "5" } ]
1,510,602,868
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
13,004,800
a = int( input()) s = input() v =s.split(' ') h = [] h1 = [] for x in set(v): h.append(s.rfind(x)//2) h1.append(x) min = h[0] it = 0 for i in range(len(h)): if(min > h[i]): min = h[i] it = i print(h1[it])
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. Input Specification: In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. Output Specification: Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. Demo Input: ['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n'] Demo Output: ['3\n', '2\n'] Note: In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
```python a = int( input()) s = input() v =s.split(' ') h = [] h1 = [] for x in set(v): h.append(s.rfind(x)//2) h1.append(x) min = h[0] it = 0 for i in range(len(h)): if(min > h[i]): min = h[i] it = i print(h1[it]) ```
0
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,670,565,527
2,147,483,647
PyPy 3-64
OK
TESTS
3
92
0
t = int(input()) for _ in range(t): angle = int(input()) print("YES" if 360 % (180-angle) == 0 else "NO")
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? Input Specification: The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees. Output Specification: For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. Demo Input: ['3\n30\n60\n90\n'] Demo Output: ['NO\nYES\nYES\n'] Note: In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
```python t = int(input()) for _ in range(t): angle = int(input()) print("YES" if 360 % (180-angle) == 0 else "NO") ```
3
500
A
New Year Transportation
PROGRAMMING
1,000
[ "dfs and similar", "graphs", "implementation" ]
null
null
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
[ "8 4\n1 2 1 2 1 2 1\n", "8 5\n1 2 1 2 1 1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
500
[ { "input": "8 4\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "8 5\n1 2 1 2 1 1 1", "output": "NO" }, { "input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "output": "YES" }, { "input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1", "output": "YES" }, { "input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1", "output": "NO" }, { "input": "10 3\n8 3 5 4 2 3 2 2 1", "output": "NO" }, { "input": "10 9\n8 3 5 4 2 3 2 2 1", "output": "YES" }, { "input": "3 2\n1 1", "output": "YES" }, { "input": "3 2\n2 1", "output": "NO" }, { "input": "4 2\n2 1 1", "output": "NO" }, { "input": "4 4\n2 2 1", "output": "YES" }, { "input": "8 8\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "3 3\n1 1", "output": "YES" }, { "input": "8 8\n1 2 1 2 1 1 1", "output": "YES" }, { "input": "3 3\n2 1", "output": "YES" }, { "input": "4 4\n1 1 1", "output": "YES" }, { "input": "8 8\n1 1 1 1 1 1 1", "output": "YES" }, { "input": "5 5\n1 1 1 1", "output": "YES" } ]
1,688,714,227
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
a, b = map(int, input().split()) c = list(map(int, input().split())) i = 1 while not i >= b: i = i + c[i - 1] print(i) print(i) if i == b: print('YES') else: print('NO')
Title: New Year Transportation Time Limit: None seconds Memory Limit: None megabytes Problem Description: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. Input Specification: The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. Output Specification: If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". Demo Input: ['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
```python a, b = map(int, input().split()) c = list(map(int, input().split())) i = 1 while not i >= b: i = i + c[i - 1] print(i) print(i) if i == b: print('YES') else: print('NO') ```
0
990
A
Commentary Boxes
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation. If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment. Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes. What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)?
The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box.
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$.
[ "9 7 3 8\n", "2 7 3 7\n", "30 6 17 19\n" ]
[ "15\n", "14\n", "0\n" ]
In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them. In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them. In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes.
0
[ { "input": "9 7 3 8", "output": "15" }, { "input": "2 7 3 7", "output": "14" }, { "input": "30 6 17 19", "output": "0" }, { "input": "500000000001 1000000000000 100 100", "output": "49999999999900" }, { "input": "1000000000000 750000000001 10 100", "output": "5000000000020" }, { "input": "1000000000000 750000000001 100 10", "output": "2499999999990" }, { "input": "42 1 1 1", "output": "0" }, { "input": "1 1000000000000 1 100", "output": "100" }, { "input": "7 2 3 7", "output": "3" }, { "input": "999999999 2 1 1", "output": "1" }, { "input": "999999999999 10000000007 100 100", "output": "70100" }, { "input": "10000000001 2 1 1", "output": "1" }, { "input": "29 6 1 2", "output": "1" }, { "input": "99999999999 6 100 100", "output": "300" }, { "input": "1000000000000 7 3 8", "output": "8" }, { "input": "99999999999 2 1 1", "output": "1" }, { "input": "1 2 1 1", "output": "1" }, { "input": "999999999999 2 1 1", "output": "1" }, { "input": "9 2 1 1", "output": "1" }, { "input": "17 4 5 5", "output": "5" }, { "input": "100000000000 3 1 1", "output": "1" }, { "input": "100 7 1 1", "output": "2" }, { "input": "1000000000000 3 100 100", "output": "100" }, { "input": "70 3 10 10", "output": "10" }, { "input": "1 2 5 1", "output": "1" }, { "input": "1000000000000 3 1 1", "output": "1" }, { "input": "804289377 846930887 78 16", "output": "3326037780" }, { "input": "1000000000000 9 55 55", "output": "55" }, { "input": "957747787 424238336 87 93", "output": "10162213695" }, { "input": "25 6 1 2", "output": "2" }, { "input": "22 7 3 8", "output": "8" }, { "input": "10000000000 1 1 1", "output": "0" }, { "input": "999999999999 2 10 10", "output": "10" }, { "input": "999999999999 2 100 100", "output": "100" }, { "input": "100 3 3 8", "output": "6" }, { "input": "99999 2 1 1", "output": "1" }, { "input": "100 3 2 5", "output": "4" }, { "input": "1000000000000 13 10 17", "output": "17" }, { "input": "7 2 1 2", "output": "1" }, { "input": "10 3 1 2", "output": "2" }, { "input": "5 2 2 2", "output": "2" }, { "input": "100 3 5 2", "output": "2" }, { "input": "7 2 1 1", "output": "1" }, { "input": "70 4 1 1", "output": "2" }, { "input": "10 4 1 1", "output": "2" }, { "input": "6 7 41 42", "output": "41" }, { "input": "10 3 10 1", "output": "1" }, { "input": "5 5 2 3", "output": "0" }, { "input": "1000000000000 3 99 99", "output": "99" }, { "input": "7 3 100 1", "output": "1" }, { "input": "7 2 100 5", "output": "5" }, { "input": "1000000000000 1 23 33", "output": "0" }, { "input": "30 7 1 1", "output": "2" }, { "input": "100 3 1 1", "output": "1" }, { "input": "90001 300 100 1", "output": "1" }, { "input": "13 4 1 2", "output": "2" }, { "input": "1000000000000 6 1 3", "output": "2" }, { "input": "50 4 5 100", "output": "10" }, { "input": "999 2 1 1", "output": "1" }, { "input": "5 2 5 5", "output": "5" }, { "input": "20 3 3 3", "output": "3" }, { "input": "3982258181 1589052704 87 20", "output": "16083055460" }, { "input": "100 3 1 3", "output": "2" }, { "input": "7 3 1 1", "output": "1" }, { "input": "19 10 100 100", "output": "100" }, { "input": "23 3 100 1", "output": "2" }, { "input": "25 7 100 1", "output": "4" }, { "input": "100 9 1 2", "output": "2" }, { "input": "9999999999 2 1 100", "output": "1" }, { "input": "1000000000000 2 1 1", "output": "0" }, { "input": "10000 3 1 1", "output": "1" }, { "input": "22 7 1 6", "output": "6" }, { "input": "100000000000 1 1 1", "output": "0" }, { "input": "18 7 100 1", "output": "4" }, { "input": "10003 4 1 100", "output": "1" }, { "input": "3205261341 718648876 58 11", "output": "3637324207" }, { "input": "8 3 100 1", "output": "2" }, { "input": "15 7 1 1", "output": "1" }, { "input": "1000000000000 1 20 20", "output": "0" }, { "input": "16 7 3 2", "output": "4" }, { "input": "1000000000000 1 1 1", "output": "0" }, { "input": "7 3 1 100", "output": "2" }, { "input": "16 3 1 100", "output": "2" }, { "input": "13 4 1 10", "output": "3" }, { "input": "10 4 5 5", "output": "10" }, { "input": "14 3 1 100", "output": "1" }, { "input": "100 33 100 1", "output": "1" }, { "input": "22 7 1 8", "output": "6" }, { "input": "10 4 2 1", "output": "2" }, { "input": "6 4 2 2", "output": "4" }, { "input": "17 4 2 1", "output": "1" }, { "input": "7 3 100 10", "output": "10" }, { "input": "702 7 3 2", "output": "4" }, { "input": "8 3 1 5", "output": "1" }, { "input": "3 2 5 2", "output": "2" }, { "input": "99 19 1 7", "output": "15" }, { "input": "16 3 100 1", "output": "1" }, { "input": "100 34 1 100", "output": "2" }, { "input": "100 33 1 1", "output": "1" }, { "input": "2 3 4 3", "output": "4" }, { "input": "15 4 4 10", "output": "4" }, { "input": "1144108931 470211273 45 79", "output": "11993619960" }, { "input": "2 3 3 4", "output": "3" }, { "input": "29 5 4 9", "output": "4" }, { "input": "15 7 1 5", "output": "5" }, { "input": "1 1 1 1", "output": "0" }, { "input": "1 1 3 4", "output": "0" }, { "input": "10 12 2 1", "output": "4" }, { "input": "1 2 3 4", "output": "3" } ]
1,528,629,097
3,997
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
0
def get_data(): d = input() a = 0 c = '' f = [] i = 0 while a != 3: if d[i] != ' ': c = c + d[i] if d[i] == ' ': a = a + 1 f.append(int(c)) c = '' i = i + 1 p = len(d) c = '' for j in range(i, p): c = c + d[j] f.append(int(c)) return f def check(d): ind = 1 if d[0] % d[1] == 0: ind = 0 if d[2] < 1 or d[2] > 100 or d[3] < 1 or d[3] > 100 or d[0] < 1 or d[0] > 10**12 or d[1] < 1 or d[1] > 10**12: ind = 2 return ind def res(ind, n, m, a, b): if ind == 2: print('error') return 0 ans = 0 cost1 = 0 cost2 = 0 nt = n if ind == 1: while nt % m != 0: nt = nt + 1 cost1 = cost1 + a while n % m != 0: n = n - 1 cost2 = cost2 + b if cost1 < cost2: ans = cost1 else: ans = cost2 print(ans) d = get_data() ind = check(d) res(ind, d[0], d[1], d[2], d[3])
Title: Commentary Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation. If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment. Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes. What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)? Input Specification: The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. Output Specification: Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. Demo Input: ['9 7 3 8\n', '2 7 3 7\n', '30 6 17 19\n'] Demo Output: ['15\n', '14\n', '0\n'] Note: In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them. In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them. In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes.
```python def get_data(): d = input() a = 0 c = '' f = [] i = 0 while a != 3: if d[i] != ' ': c = c + d[i] if d[i] == ' ': a = a + 1 f.append(int(c)) c = '' i = i + 1 p = len(d) c = '' for j in range(i, p): c = c + d[j] f.append(int(c)) return f def check(d): ind = 1 if d[0] % d[1] == 0: ind = 0 if d[2] < 1 or d[2] > 100 or d[3] < 1 or d[3] > 100 or d[0] < 1 or d[0] > 10**12 or d[1] < 1 or d[1] > 10**12: ind = 2 return ind def res(ind, n, m, a, b): if ind == 2: print('error') return 0 ans = 0 cost1 = 0 cost2 = 0 nt = n if ind == 1: while nt % m != 0: nt = nt + 1 cost1 = cost1 + a while n % m != 0: n = n - 1 cost2 = cost2 + b if cost1 < cost2: ans = cost1 else: ans = cost2 print(ans) d = get_data() ind = check(d) res(ind, d[0], d[1], d[2], d[3]) ```
0
3
B
Lorry
PROGRAMMING
1,900
[ "greedy", "sortings" ]
B. Lorry
2
64
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times bigger than kayaks (and occupy the space of 2 cubic metres). Each waterborne vehicle has a particular carrying capacity, and it should be noted that waterborne vehicles that look the same can have different carrying capacities. Knowing the truck body volume and the list of waterborne vehicles in the boat depot (for each one its type and carrying capacity are known), find out such set of vehicles that can be taken in the lorry, and that has the maximum total carrying capacity. The truck body volume of the lorry can be used effectively, that is to say you can always put into the lorry a waterborne vehicle that occupies the space not exceeding the free space left in the truck body.
The first line contains a pair of integer numbers *n* and *v* (1<=≤<=*n*<=≤<=105; 1<=≤<=*v*<=≤<=109), where *n* is the number of waterborne vehicles in the boat depot, and *v* is the truck body volume of the lorry in cubic metres. The following *n* lines contain the information about the waterborne vehicles, that is a pair of numbers *t**i*,<=*p**i* (1<=≤<=*t**i*<=≤<=2; 1<=≤<=*p**i*<=≤<=104), where *t**i* is the vehicle type (1 – a kayak, 2 – a catamaran), and *p**i* is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file.
In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.
[ "3 2\n1 2\n2 7\n1 3\n" ]
[ "7\n2\n" ]
none
0
[ { "input": "3 2\n1 2\n2 7\n1 3", "output": "7\n2" }, { "input": "5 3\n1 9\n2 9\n1 9\n2 10\n1 6", "output": "24\n3 1 5" }, { "input": "10 10\n1 14\n2 15\n2 11\n2 12\n2 9\n1 14\n2 15\n1 9\n2 11\n2 6", "output": "81\n6 1 7 2 4 9" }, { "input": "20 19\n2 47\n1 37\n1 48\n2 42\n2 48\n1 38\n2 47\n1 48\n2 47\n1 41\n2 46\n1 28\n1 49\n1 45\n2 34\n1 43\n2 29\n1 46\n2 45\n2 18", "output": "630\n13 8 3 18 14 16 10 6 2 5 9 7 1 11" }, { "input": "50 27\n2 93\n1 98\n2 62\n1 56\n1 86\n1 42\n2 67\n2 97\n2 59\n1 73\n1 83\n2 96\n1 20\n1 66\n1 84\n1 83\n1 91\n2 97\n1 81\n2 88\n2 63\n1 99\n2 57\n1 39\n1 74\n2 88\n1 30\n2 68\n1 100\n2 57\n1 87\n1 93\n1 83\n1 100\n1 91\n1 14\n1 38\n2 98\n2 85\n2 61\n1 44\n2 93\n2 66\n2 55\n2 74\n1 67\n2 67\n1 85\n2 59\n1 83", "output": "2055\n34 29 22 2 32 35 17 31 5 48 15 50 33 16 11 19 25 10 46 14 4 38 18 8" }, { "input": "1 1\n1 600", "output": "600\n1" }, { "input": "10 14\n2 230\n2 516\n2 527\n2 172\n2 854\n2 61\n1 52\n2 154\n2 832\n2 774", "output": "3905\n5 9 10 3 2 1 4" }, { "input": "8 8\n1 1\n1 1\n1 1\n1 1\n2 100\n2 100\n2 100\n2 100", "output": "400\n8 7 6 5" }, { "input": "8 4\n1 100\n1 100\n1 100\n1 100\n2 1\n2 1\n2 1\n2 1", "output": "400\n4 3 2 1" } ]
1,669,363,846
4,726
Python 3
WRONG_ANSWER
TESTS
0
60
0
def mySort(e): return e[1] n, v = map(int, input().split()) complect1 = [] complect2 = [] for i in range(n): t, p = map(int, input().split()) if t == 1: complect1.append([t, p]) else: complect2.append([t, p]) complect1.sort(key=mySort, reverse=True) complect2.sort(key=mySort, reverse=True) print(complect1) print(complect2) a = 0 ans = [] while v != 3 and v > 0: if len(complect1) and len(complect2): if complect1[0][1] >= complect2[0][1]: ans.append(1) v -= 1 a += complect1[0][1] complect1.pop(0) elif len(complect1) > 1: if complect1[0][1] + complect1[1][1] >= complect2[0][1]: ans.extend([1, 1]) v -= 2 a += complect1[0][1] + complect1[1][1] complect1.pop(0) complect1.pop(0) else: ans.append(2) v -= 2 a += complect2[0][1] complect2.pop(0) else: if len(complect1): ans.append(1) v -= 1 a += complect1[0][1] complect1.pop(0) else: ans.append(2) v -= 2 a += complect2[0][1] complect2.pop(0) if v == 3: if len(complect1) > 2 and len(complect2) > 0: if complect1[0][1] + complect1[1][1] + complect1[2][1] >= complect2[0][1]: ans.extend([1, 1, 1]) v -= 3 a += complect1[0][1] + complect1[1][1] + complect1[2][1] else: ans.append(2) v -= 2 a += complect2[0][1] elif len(complect1) > 1 and len(complect2) > 0: if complect1[0][1] + complect1[1][1] >= complect2[0][1]: ans.extend([1, 1]) v -= 2 a += complect1[0][1] + complect1[1][1] else: ans.append(2) v -= 2 a += complect2[0][1] complect2.pop(0) elif len(complect1) > 0 and len(complect2) > 0: if complect1[0][1] >= complect2[0][1]: ans.append(1) v -= 1 a += complect1[0][1] print(a) print(*ans)
Title: Lorry Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times bigger than kayaks (and occupy the space of 2 cubic metres). Each waterborne vehicle has a particular carrying capacity, and it should be noted that waterborne vehicles that look the same can have different carrying capacities. Knowing the truck body volume and the list of waterborne vehicles in the boat depot (for each one its type and carrying capacity are known), find out such set of vehicles that can be taken in the lorry, and that has the maximum total carrying capacity. The truck body volume of the lorry can be used effectively, that is to say you can always put into the lorry a waterborne vehicle that occupies the space not exceeding the free space left in the truck body. Input Specification: The first line contains a pair of integer numbers *n* and *v* (1<=≤<=*n*<=≤<=105; 1<=≤<=*v*<=≤<=109), where *n* is the number of waterborne vehicles in the boat depot, and *v* is the truck body volume of the lorry in cubic metres. The following *n* lines contain the information about the waterborne vehicles, that is a pair of numbers *t**i*,<=*p**i* (1<=≤<=*t**i*<=≤<=2; 1<=≤<=*p**i*<=≤<=104), where *t**i* is the vehicle type (1 – a kayak, 2 – a catamaran), and *p**i* is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file. Output Specification: In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them. Demo Input: ['3 2\n1 2\n2 7\n1 3\n'] Demo Output: ['7\n2\n'] Note: none
```python def mySort(e): return e[1] n, v = map(int, input().split()) complect1 = [] complect2 = [] for i in range(n): t, p = map(int, input().split()) if t == 1: complect1.append([t, p]) else: complect2.append([t, p]) complect1.sort(key=mySort, reverse=True) complect2.sort(key=mySort, reverse=True) print(complect1) print(complect2) a = 0 ans = [] while v != 3 and v > 0: if len(complect1) and len(complect2): if complect1[0][1] >= complect2[0][1]: ans.append(1) v -= 1 a += complect1[0][1] complect1.pop(0) elif len(complect1) > 1: if complect1[0][1] + complect1[1][1] >= complect2[0][1]: ans.extend([1, 1]) v -= 2 a += complect1[0][1] + complect1[1][1] complect1.pop(0) complect1.pop(0) else: ans.append(2) v -= 2 a += complect2[0][1] complect2.pop(0) else: if len(complect1): ans.append(1) v -= 1 a += complect1[0][1] complect1.pop(0) else: ans.append(2) v -= 2 a += complect2[0][1] complect2.pop(0) if v == 3: if len(complect1) > 2 and len(complect2) > 0: if complect1[0][1] + complect1[1][1] + complect1[2][1] >= complect2[0][1]: ans.extend([1, 1, 1]) v -= 3 a += complect1[0][1] + complect1[1][1] + complect1[2][1] else: ans.append(2) v -= 2 a += complect2[0][1] elif len(complect1) > 1 and len(complect2) > 0: if complect1[0][1] + complect1[1][1] >= complect2[0][1]: ans.extend([1, 1]) v -= 2 a += complect1[0][1] + complect1[1][1] else: ans.append(2) v -= 2 a += complect2[0][1] complect2.pop(0) elif len(complect1) > 0 and len(complect2) > 0: if complect1[0][1] >= complect2[0][1]: ans.append(1) v -= 1 a += complect1[0][1] print(a) print(*ans) ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,579,157,531
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
186
0
num = eval(input()) suma = 0 sumb = 0 sumc = 0 for i in range (0, num): a,b,c = input().split() suma += int(a) sumb += int(b) sumc += int(c) if a==0 and b == 0 and c == 0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python num = eval(input()) suma = 0 sumb = 0 sumc = 0 for i in range (0, num): a,b,c = input().split() suma += int(a) sumb += int(b) sumc += int(c) if a==0 and b == 0 and c == 0: print('YES') else: print('NO') ```
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", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,652,802,402
2,147,483,647
Python 3
OK
TESTS
20
46
4,505,600
i=input().split() n=int(i[0]) m=int(i[1]) a=int(i[2]) if m%a!=0: m=m-m%a+a if n%a!=0: n=n-n%a+a print (int(m*n/a**2))
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 i=input().split() n=int(i[0]) m=int(i[1]) a=int(i[2]) if m%a!=0: m=m-m%a+a if n%a!=0: n=n-n%a+a print (int(m*n/a**2)) ```
3.968608
0
none
none
none
0
[ "none" ]
null
null
Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить *n* ножек одинаковой длины. При составлении ножки любые две части могут быть соединены друг с другом. Изначально все ножки стола разобраны, а вам заданы длины 2*n* частей в произвольном порядке. Помогите Васе собрать все ножки стола так, чтобы все они были одинаковой длины, разбив заданные 2*n* части на пары правильным образом. Каждая ножка обязательно должна быть составлена ровно из двух частей, не разрешается использовать как ножку только одну часть.
В первой строке задано число *n* (1<=≤<=*n*<=≤<=1000) — количество ножек у стола, купленного Васей. Во второй строке следует последовательность из 2*n* целых положительных чисел *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=100<=000) — длины частей ножек стола в произвольном порядке.
Выведите *n* строк по два целых числа в каждой — длины частей ножек, которые надо соединить друг с другом. Гарантируется, что всегда возможно собрать *n* ножек одинаковой длины. Если ответов несколько, разрешается вывести любой из них.
[ "3\n1 3 2 4 5 3\n", "3\n1 1 1 2 2 2\n" ]
[ "1 5\n2 4\n3 3\n", "1 2\n2 1\n1 2\n" ]
none
0
[ { "input": "3\n1 3 2 4 5 3", "output": "1 5\n2 4\n3 3" }, { "input": "3\n1 1 1 2 2 2", "output": "1 2\n1 2\n1 2" }, { "input": "1\n3 7", "output": "3 7" }, { "input": "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15", "output": "2 18\n2 18\n2 18\n3 17\n4 16\n5 15\n5 15\n7 13\n7 13\n9 11" }, { "input": "10\n759 82 475 841 46 461 288 525 918 241 789 847 58 954 712 159 942 211 153 539", "output": "46 954\n58 942\n82 918\n153 847\n159 841\n211 789\n241 759\n288 712\n461 539\n475 525" }, { "input": "100\n8 7 7 5 2 7 7 5 1 8 6 3 6 7 2 4 4 2 6 8 5 6 5 2 6 1 3 9 5 8 7 6 5 4 8 6 5 5 3 2 6 5 4 9 7 1 5 7 9 5 7 4 1 6 5 8 2 6 6 1 4 2 3 2 3 9 3 8 7 1 2 4 5 7 3 5 5 6 3 8 3 6 1 5 5 3 3 3 8 8 1 4 3 6 7 1 1 2 4 4 7 3 7 7 8 9 5 8 6 6 4 7 4 9 3 4 7 5 2 8 4 1 9 7 9 7 9 6 7 7 9 6 1 1 1 9 9 4 4 1 5 6 6 3 9 3 3 7 4 2 4 9 6 3 7 5 5 2 9 7 5 4 8 3 1 8 6 3 5 9 9 3 6 8 1 3 7 7 4 4 4 3 8 1 9 3 3 3 3 7 2 4 7 7 1 2 9 3 2 2", "output": "1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1" }, { "input": "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15", "output": "2 18\n2 18\n2 18\n3 17\n4 16\n5 15\n5 15\n7 13\n7 13\n9 11" }, { "input": "10\n759 82 475 841 46 461 288 525 918 241 789 847 58 954 712 159 942 211 153 539", "output": "46 954\n58 942\n82 918\n153 847\n159 841\n211 789\n241 759\n288 712\n461 539\n475 525" }, { "input": "100\n8 7 7 5 2 7 7 5 1 8 6 3 6 7 2 4 4 2 6 8 5 6 5 2 6 1 3 9 5 8 7 6 5 4 8 6 5 5 3 2 6 5 4 9 7 1 5 7 9 5 7 4 1 6 5 8 2 6 6 1 4 2 3 2 3 9 3 8 7 1 2 4 5 7 3 5 5 6 3 8 3 6 1 5 5 3 3 3 8 8 1 4 3 6 7 1 1 2 4 4 7 3 7 7 8 9 5 8 6 6 4 7 4 9 3 4 7 5 2 8 4 1 9 7 9 7 9 6 7 7 9 6 1 1 1 9 9 4 4 1 5 6 6 3 9 3 3 7 4 2 4 9 6 3 7 5 5 2 9 7 5 4 8 3 1 8 6 3 5 9 9 3 6 8 1 3 7 7 4 4 4 3 8 1 9 3 3 3 3 7 2 4 7 7 1 2 9 3 2 2", "output": "1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n1 9\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n2 8\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n3 7\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n4 6\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5\n5 5" }, { "input": "1\n7 7", "output": "7 7" } ]
1,458,749,869
4,669
Python 3
OK
TESTS
57
608
5,529,600
n = int(input()) s = 0 a = list(map(int,input().split())) j = 1 for i in range (n*2): s += a[i] b = s/n while len (a) > 0: f = a[0] + a[j] if f==b: print (a[0], a[j], sep=' ') a = a[1:j] + a[j+1:] j = 0 j+=1
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить *n* ножек одинаковой длины. При составлении ножки любые две части могут быть соединены друг с другом. Изначально все ножки стола разобраны, а вам заданы длины 2*n* частей в произвольном порядке. Помогите Васе собрать все ножки стола так, чтобы все они были одинаковой длины, разбив заданные 2*n* части на пары правильным образом. Каждая ножка обязательно должна быть составлена ровно из двух частей, не разрешается использовать как ножку только одну часть. Input Specification: В первой строке задано число *n* (1<=≤<=*n*<=≤<=1000) — количество ножек у стола, купленного Васей. Во второй строке следует последовательность из 2*n* целых положительных чисел *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=100<=000) — длины частей ножек стола в произвольном порядке. Output Specification: Выведите *n* строк по два целых числа в каждой — длины частей ножек, которые надо соединить друг с другом. Гарантируется, что всегда возможно собрать *n* ножек одинаковой длины. Если ответов несколько, разрешается вывести любой из них. Demo Input: ['3\n1 3 2 4 5 3\n', '3\n1 1 1 2 2 2\n'] Demo Output: ['1 5\n2 4\n3 3\n', '1 2\n2 1\n1 2\n'] Note: none
```python n = int(input()) s = 0 a = list(map(int,input().split())) j = 1 for i in range (n*2): s += a[i] b = s/n while len (a) > 0: f = a[0] + a[j] if f==b: print (a[0], a[j], sep=' ') a = a[1:j] + a[j+1:] j = 0 j+=1 ```
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39 75", "output": "48.142857142857" }, { "input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "output": "11.615384615385" }, { "input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "output": "12.761904761905" }, { "input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "output": "69.538461538462" }, { "input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94", "output": "91.551724137931" }, { "input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100", "output": "99.515151515152" }, { "input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2", "output": "8.147058823529" }, { "input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93", "output": "91.921052631579" }, { "input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100", "output": "97.019230769231" }, { "input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6", "output": "50.965517241379" }, { "input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10", "output": "7.505882352941" }, { "input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6", "output": "10.418918918919" }, { "input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41", "output": "20.928571428571" }, { "input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96", "output": "49.191919191919" }, { "input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92", "output": "73.484848484848" }, { "input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6", "output": "7.640000000000" }, { "input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100", "output": "77.660000000000" }, { "input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81", "output": "91.480000000000" }, { "input": "1\n0", "output": "0.000000000000" }, { "input": "1\n100", "output": "100.000000000000" }, { "input": "1\n78", "output": "78.000000000000" }, { "input": "2\n0 100", "output": "50.000000000000" }, { "input": "2\n100 100", "output": "100.000000000000" }, { "input": "5\n0 0 0 0 1", "output": "0.200000000000" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99", "output": "99.990000000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "0.010000000000" }, { "input": "5\n100 100 100 100 100", "output": "100.000000000000" } ]
1,693,614,080
2,147,483,647
Python 3
OK
TESTS
31
92
0
def Drinks(number_of_orange , volume_fraction) : return sum(volume_fraction) / number_of_orange if __name__ == "__main__" : number_of_orange = int(input()) volume_fraction = list(map(int , input().split()[:number_of_orange])) print(Drinks(number_of_orange , volume_fraction))
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. Output Specification: Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. Demo Input: ['3\n50 50 100\n', '4\n0 25 50 75\n'] Demo Output: ['66.666666666667\n', '37.500000000000\n'] Note: Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
```python def Drinks(number_of_orange , volume_fraction) : return sum(volume_fraction) / number_of_orange if __name__ == "__main__" : number_of_orange = int(input()) volume_fraction = list(map(int , input().split()[:number_of_orange])) print(Drinks(number_of_orange , volume_fraction)) ```
3
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning 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": "6 11", "output": "6 2" }, { "input": "10 40", "output": "10 15" }, { "input": "11 56", "output": "11 22" }, { "input": "34 30", "output": "30 2" }, { "input": "33 33", "output": "33 0" }, { "input": "100 45", "output": "45 27" }, { "input": "100 23", "output": "23 38" }, { "input": "45 12", "output": "12 16" }, { "input": "1 1", "output": "1 0" }, { "input": "1 100", "output": "1 49" }, { "input": "100 1", "output": "1 49" }, { "input": "68 59", "output": "59 4" }, { "input": "45 99", "output": "45 27" }, { "input": "99 100", "output": "99 0" }, { "input": "100 98", "output": "98 1" }, { "input": "59 12", "output": "12 23" }, { "input": "86 4", "output": "4 41" }, { "input": "68 21", "output": "21 23" }, { "input": "100 11", "output": "11 44" }, { "input": "100 10", "output": "10 45" }, { "input": "15 45", "output": "15 15" }, { "input": "11 32", "output": "11 10" }, { "input": "34 96", "output": "34 31" }, { "input": "89 89", "output": "89 0" } ]
1,693,559,108
2,147,483,647
PyPy 3-64
OK
TESTS
30
62
0
r, b = [int(x) for x in input().split()] print(min(r,b),(max(r,b)-min(r,b))//2)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red 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 r, b = [int(x) for x in input().split()] print(min(r,b),(max(r,b)-min(r,b))//2) ```
3
366
B
Dima and To-do List
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks. Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one. Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.
The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task. It is guaranteed that *n* is divisible by *k*.
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
[ "6 2\n3 2 1 6 5 4\n", "10 5\n1 3 5 7 9 9 4 1 8 5\n" ]
[ "1\n", "3\n" ]
Explanation of the first example. If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12. Explanation of the second example. In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.
1,000
[ { "input": "6 2\n3 2 1 6 5 4", "output": "1" }, { "input": "10 5\n1 3 5 7 9 9 4 1 8 5", "output": "3" }, { "input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 10\n8 4 5 7 6 9 2 2 3 5", "output": "7" }, { "input": "50 10\n1 2 3 4 5 6 7 8 9 10 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "1 1\n1", "output": "1" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "4 2\n2 1 1 3", "output": "1" }, { "input": "15 5\n5 5 5 5 5 1 2 3 4 5 1 2 3 4 5", "output": "1" }, { "input": "20 10\n3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 6 4", "output": "1" } ]
1,586,089,745
2,147,483,647
Python 3
OK
TESTS
36
217
6,963,200
n, k = map(int,input().split()) a = list(map(int,input().split())) ans = 10 ** 9 sol = -1 for i in range(k): x = n // k; y = i; tmp = 0 while(x): tmp += a[y] y += k y %= n x -= 1 if tmp < ans: ans = tmp sol = i + 1 print(sol);
Title: Dima and To-do List Time Limit: None seconds Memory Limit: None megabytes Problem Description: You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks. Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one. Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible. Input Specification: The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task. It is guaranteed that *n* is divisible by *k*. Output Specification: In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do. Demo Input: ['6 2\n3 2 1 6 5 4\n', '10 5\n1 3 5 7 9 9 4 1 8 5\n'] Demo Output: ['1\n', '3\n'] Note: Explanation of the first example. If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12. Explanation of the second example. In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.
```python n, k = map(int,input().split()) a = list(map(int,input().split())) ans = 10 ** 9 sol = -1 for i in range(k): x = n // k; y = i; tmp = 0 while(x): tmp += a[y] y += k y %= n x -= 1 if tmp < ans: ans = tmp sol = i + 1 print(sol); ```
3
867
A
Between the Offices
PROGRAMMING
800
[ "implementation" ]
null
null
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower).
[ "4\nFSSF\n", "2\nSF\n", "10\nFFFFFFFFFF\n", "10\nSSFFSFFSFF\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you stayed the whole period in San Francisco, so the answer is "NO". In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
500
[ { "input": "4\nFSSF", "output": "NO" }, { "input": "2\nSF", "output": "YES" }, { "input": "10\nFFFFFFFFFF", "output": "NO" }, { "input": "10\nSSFFSFFSFF", "output": "YES" }, { "input": "20\nSFSFFFFSSFFFFSSSSFSS", "output": "NO" }, { "input": "20\nSSFFFFFSFFFFFFFFFFFF", "output": "YES" }, { "input": "20\nSSFSFSFSFSFSFSFSSFSF", "output": "YES" }, { "input": "20\nSSSSFSFSSFSFSSSSSSFS", "output": "NO" }, { "input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF", "output": "NO" }, { "input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF", "output": "YES" }, { "input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS", "output": "NO" }, { "input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS", "output": "NO" }, { "input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS", "output": "NO" }, { "input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS", "output": "NO" }, { "input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS", "output": "NO" }, { "input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS", "output": "NO" }, { "input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", "output": "NO" }, { "input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "YES" }, { "input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "YES" }, { "input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF", "output": "YES" }, { "input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF", "output": "YES" }, { "input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF", "output": "YES" }, { "input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF", "output": "YES" }, { "input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF", "output": "YES" }, { "input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF", "output": "YES" }, { "input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF", "output": "YES" }, { "input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF", "output": "YES" }, { "input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF", "output": "YES" }, { "input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF", "output": "YES" }, { "input": "2\nSS", "output": "NO" } ]
1,543,160,178
2,147,483,647
PyPy 3
OK
TESTS
34
140
0
n = int (input()) a=input() if a[0]+a[-1]=="SF": exit(print("YES")) print("NO")
Title: Between the Offices Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. Input Specification: The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. Output Specification: Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you stayed the whole period in San Francisco, so the answer is "NO". In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
```python n = int (input()) a=input() if a[0]+a[-1]=="SF": exit(print("YES")) print("NO") ```
3
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
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. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "480", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "49", "output": "YES" }, { "input": "56", "output": "YES" }, { "input": "124", "output": "YES" }, { "input": "1000", "output": "YES" }, { "input": "999", "output": "NO" }, { "input": "298", "output": "NO" }, { "input": "274", "output": "NO" }, { "input": "998", "output": "NO" }, { "input": "42", "output": "YES" }, { "input": "788", "output": "YES" }, { "input": "70", "output": "YES" }, { "input": "444", "output": "YES" }, { "input": "777", "output": "YES" }, { "input": "799", "output": "YES" }, { "input": "25", "output": "NO" }, { "input": "882", "output": "YES" }, { "input": "88", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "YES" }, { "input": "94", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "141", "output": "YES" } ]
1,688,638,641
2,147,483,647
Python 3
OK
TESTS
36
92
0
chast = [4, 7, 44, 47, 77, 444, 447, 477, 777, 774, 744] f1 = 0 n = int(input()) for elem in chast: if n % elem == 0: print("YES") f1 = 1 break if f1 == 0: print("NO") # Thu Jul 06 2023 13:17:21 GMT+0300 (Moscow Standard Time)
Title: Lucky Division 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. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. Output Specification: In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['47\n', '16\n', '78\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
```python chast = [4, 7, 44, 47, 77, 444, 447, 477, 777, 774, 744] f1 = 0 n = int(input()) for elem in chast: if n % elem == 0: print("YES") f1 = 1 break if f1 == 0: print("NO") # Thu Jul 06 2023 13:17:21 GMT+0300 (Moscow Standard Time) ```
3
554
B
Ohana Cleans Up
PROGRAMMING
1,200
[ "brute force", "greedy", "strings" ]
null
null
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column. Return the maximum number of rows that she can make completely clean.
The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100). The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty.
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
[ "4\n0101\n1000\n1111\n0101\n", "3\n111\n111\n111\n" ]
[ "2\n", "3\n" ]
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean. In the second sample, everything is already clean, so Ohana doesn't need to do anything.
500
[ { "input": "4\n0101\n1000\n1111\n0101", "output": "2" }, { "input": "3\n111\n111\n111", "output": "3" }, { "input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "output": "9" }, { "input": "1\n1", "output": "1" }, { "input": "10\n0111010011\n0111010011\n1010010001\n0111010011\n0000110000\n0111010011\n0111010011\n0000110000\n1010010001\n0111010011", "output": "6" }, { "input": "20\n10101011101000011010\n11111010001100110101\n01011100010000001111\n10110100000101010011\n11010001110111101101\n00100110011011101010\n01000110101011001100\n01101100111101101101\n10111010010100111100\n00010010110001101110\n10111110010000101010\n10010111110100100100\n11010111001111110100\n11110111101100000001\n00011010100111011000\n11110001011000011010\n10001101010000011011\n01010101110010000111\n11100110111101101111\n11011111110010001111", "output": "1" }, { "input": "10\n1001000000\n0111101111\n1111001011\n1000010100\n0111101111\n0101100110\n1001000000\n1000010100\n0111101111\n1001000000", "output": "3" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "output": "10" }, { "input": "10\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111", "output": "10" }, { "input": "10\n1000000000\n0100000000\n0010000000\n0001000000\n0000100000\n0000010000\n0000001000\n0000000100\n0000000010\n0000000001", "output": "1" }, { "input": "2\n10\n01", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "4\n0000\n0000\n1111\n1111", "output": "2" }, { "input": "11\n10000000001\n10000000001\n10000000001\n10000000001\n10001000001\n10001000000\n10001000001\n10001000001\n10001000000\n10001000000\n10001000100", "output": "4" } ]
1,435,166,206
2,806
Python 3
OK
TESTS
36
343
102,400
n = int(input()) grid = [[0]*n for i in range(n)] for r in range(n): s = input() for c in range(n): grid[r][c] = ord(s[c]) - ord('0') max_clean_count = 0 for r in range(n): state = [x ^ 1 for x in grid[r]] clean_count = 0 for r2 in range(n): if all(grid[r2][c] ^ state[c] == 1 for c in range(n)): clean_count += 1 max_clean_count = max(max_clean_count, clean_count) print(max_clean_count)
Title: Ohana Cleans Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column. Return the maximum number of rows that she can make completely clean. Input Specification: The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100). The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty. Output Specification: The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. Demo Input: ['4\n0101\n1000\n1111\n0101\n', '3\n111\n111\n111\n'] Demo Output: ['2\n', '3\n'] Note: In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean. In the second sample, everything is already clean, so Ohana doesn't need to do anything.
```python n = int(input()) grid = [[0]*n for i in range(n)] for r in range(n): s = input() for c in range(n): grid[r][c] = ord(s[c]) - ord('0') max_clean_count = 0 for r in range(n): state = [x ^ 1 for x in grid[r]] clean_count = 0 for r2 in range(n): if all(grid[r2][c] ^ state[c] == 1 for c in range(n)): clean_count += 1 max_clean_count = max(max_clean_count, clean_count) print(max_clean_count) ```
3
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1" }, { "input": "20\n5 3 7 2 1 6 4", "output": "6" }, { "input": "10\n5 1 1 1 1 1 5", "output": "6" }, { "input": "50\n10 1 10 1 10 1 10", "output": "1" }, { "input": "77\n11 11 11 11 11 11 10", "output": "1" }, { "input": "1\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n100 100 100 100 100 100 100", "output": "3" }, { "input": "999\n10 20 10 20 30 20 10", "output": "3" }, { "input": "433\n109 58 77 10 39 125 15", "output": "7" }, { "input": "1\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n1 0 1 0 1 0 1", "output": "1" }, { "input": "997\n1 1 0 0 1 0 1", "output": "1" }, { "input": "1000\n1 1 1 1 1 1 1", "output": "6" }, { "input": "1000\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n1 0 0 0 0 0 0", "output": "1" }, { "input": "1000\n0 0 0 0 0 0 1", "output": "7" }, { "input": "1000\n1 0 0 1 0 0 1", "output": "1" }, { "input": "509\n105 23 98 0 7 0 155", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "2\n1 1 0 0 0 0 0", "output": "2" }, { "input": "1\n0 0 0 0 0 1 0", "output": "6" }, { "input": "10\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n0 0 0 0 0 6 0", "output": "6" }, { "input": "3\n0 1 0 0 0 0 0", "output": "2" }, { "input": "10\n0 0 0 0 0 0 10", "output": "7" }, { "input": "28\n1 2 3 4 5 6 7", "output": "7" }, { "input": "100\n5 5 5 5 5 5 5", "output": "6" }, { "input": "4\n1 0 0 0 0 0 1", "output": "7" }, { "input": "2\n0 0 0 0 0 0 1", "output": "7" }, { "input": "7\n0 0 0 0 0 0 7", "output": "7" }, { "input": "7\n2 1 1 1 1 1 0", "output": "6" }, { "input": "2\n0 0 1 1 0 0 0", "output": "4" }, { "input": "6\n1 1 1 1 1 1 0", "output": "6" }, { "input": "5\n1 1 1 0 0 1 1", "output": "7" }, { "input": "100\n10 20 30 10 10 10 10", "output": "7" }, { "input": "1\n0 0 0 1 0 0 0", "output": "4" }, { "input": "70\n10 10 10 10 10 10 10", "output": "7" }, { "input": "22\n1 2 3 4 5 6 10", "output": "7" }, { "input": "5\n0 0 0 1 0 0 0", "output": "4" }, { "input": "2\n0 0 0 1 0 0 0", "output": "4" }, { "input": "6\n1 0 0 0 0 0 2", "output": "7" }, { "input": "10\n1 2 2 1 2 1 1", "output": "7" }, { "input": "5\n0 0 0 0 0 0 10", "output": "7" }, { "input": "4\n0 1 1 0 0 0 0", "output": "3" }, { "input": "100\n0 0 0 0 0 1 0", "output": "6" } ]
1,650,377,889
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> int main() { int n,day{0}; std::cin >> n; int coordinates[7]; for (int i{0};i<7;i++){ std::cin>>coordinates[i]; } while (n>0){ n-=coordinates[(day%7)]; day++; } std::cout<<(day%7); }
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. Input Specification: The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. Output Specification: Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. Demo Input: ['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n'] Demo Output: ['6\n', '1\n'] Note: Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
```python #include <iostream> int main() { int n,day{0}; std::cin >> n; int coordinates[7]; for (int i{0};i<7;i++){ std::cin>>coordinates[i]; } while (n>0){ n-=coordinates[(day%7)]; day++; } std::cout<<(day%7); } ```
-1
582
B
Once Again...
PROGRAMMING
1,900
[ "constructive algorithms", "dp", "matrices" ]
null
null
You are given an array of positive integers *a*1,<=*a*2,<=...,<=*a**n*<=×<=*T* of length *n*<=×<=*T*. We know that for any *i*<=&gt;<=*n* it is true that *a**i*<==<=*a**i*<=-<=*n*. Find the length of the longest non-decreasing sequence of the given array.
The first line contains two space-separated integers: *n*, *T* (1<=≤<=*n*<=≤<=100, 1<=≤<=*T*<=≤<=107). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=300).
Print a single number — the length of a sought sequence.
[ "4 3\n3 1 4 2\n" ]
[ "5\n" ]
The array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.
1,250
[ { "input": "4 3\n3 1 4 2", "output": "5" }, { "input": "1 1000\n42", "output": "1000" }, { "input": "31 3767\n16 192 152 78 224 202 186 52 118 19 13 38 199 196 35 295 100 64 205 37 166 124 169 214 66 243 134 192 253 270 92", "output": "7546" }, { "input": "15 12226\n18 125 213 221 124 147 154 182 134 184 51 49 267 88 251", "output": "12234" }, { "input": "81 10683\n3 52 265 294 213 242 185 151 27 165 128 237 124 14 43 147 104 162 124 103 233 156 288 57 289 195 129 77 97 138 153 289 203 126 34 5 97 35 224 120 200 203 222 94 171 294 293 108 145 193 227 206 34 295 1 233 258 7 246 34 60 232 58 169 77 150 272 279 171 228 168 84 114 229 149 97 66 246 212 236 151", "output": "32070" }, { "input": "29 7954\n1 257 8 47 4 26 49 228 120 53 138 101 101 35 293 232 299 195 219 45 195 174 96 157 168 138 288 114 291", "output": "15919" }, { "input": "39 1057\n1 120 247 206 260 117 152 24 162 266 202 152 278 199 63 188 271 62 62 177 213 77 229 197 263 178 211 102 255 257 163 134 14 66 11 113 216 288 225", "output": "2128" }, { "input": "2 766\n147 282", "output": "767" }, { "input": "2 13101\n180 199", "output": "13102" }, { "input": "29 1918\n8 81 38 146 195 199 31 153 267 139 48 202 38 259 139 71 253 3 289 44 210 81 78 259 236 189 219 102 133", "output": "3845" }, { "input": "46 13793\n1 239 20 83 33 183 122 208 46 141 11 264 196 266 104 130 116 117 31 213 235 207 219 206 206 46 89 112 260 191 245 234 87 255 186 4 251 177 130 59 81 54 227 116 105 284", "output": "27600" }, { "input": "2 8698\n71 225", "output": "8699" }, { "input": "68 2450\n107 297 185 215 224 128 8 65 101 202 19 145 255 233 138 223 144 132 32 122 153 85 31 160 219 125 167 220 138 255 219 119 165 249 47 124 20 37 160 24 156 154 163 226 270 88 74 192 204 300 194 184 235 93 267 160 12 216 91 191 267 241 152 9 111 76 201 295", "output": "7366" }, { "input": "100 10000000\n98 99 96 97 94 95 92 93 90 91 88 89 86 87 84 85 82 83 80 81 78 79 76 77 74 75 72 73 70 71 68 69 66 67 64 65 62 63 60 61 58 59 56 57 54 55 52 53 50 51 48 49 46 47 44 45 42 43 40 41 38 39 36 37 34 35 32 33 30 31 28 29 26 27 24 25 22 23 20 21 18 19 16 17 14 15 12 13 10 11 8 9 6 7 4 5 2 3 1 100", "output": "10000050" }, { "input": "99 10000000\n97 98 95 96 93 94 91 92 89 90 87 88 85 86 83 84 81 82 79 80 77 78 75 76 73 74 71 72 69 70 67 68 65 66 63 64 61 62 59 60 57 58 55 56 53 54 51 52 49 50 47 48 45 46 43 44 41 42 39 40 37 38 35 36 33 34 31 32 29 30 27 28 25 26 23 24 21 22 19 20 17 18 15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2 99", "output": "10000050" }, { "input": "99 10000000\n96 97 98 93 94 95 90 91 92 87 88 89 84 85 86 81 82 83 78 79 80 75 76 77 72 73 74 69 70 71 66 67 68 63 64 65 60 61 62 57 58 59 54 55 56 51 52 53 48 49 50 45 46 47 42 43 44 39 40 41 36 37 38 33 34 35 30 31 32 27 28 29 24 25 26 21 22 23 18 19 20 15 16 17 12 13 14 9 10 11 6 7 8 3 4 5 2 1 99", "output": "10000065" }, { "input": "100 10000000\n97 98 99 94 95 96 91 92 93 88 89 90 85 86 87 82 83 84 79 80 81 76 77 78 73 74 75 70 71 72 67 68 69 64 65 66 61 62 63 58 59 60 55 56 57 52 53 54 49 50 51 46 47 48 43 44 45 40 41 42 37 38 39 34 35 36 31 32 33 28 29 30 25 26 27 22 23 24 19 20 21 16 17 18 13 14 15 10 11 12 7 8 9 4 5 6 1 2 3 100", "output": "10000067" }, { "input": "98 10000000\n95 96 97 92 93 94 89 90 91 86 87 88 83 84 85 80 81 82 77 78 79 74 75 76 71 72 73 68 69 70 65 66 67 62 63 64 59 60 61 56 57 58 53 54 55 50 51 52 47 48 49 44 45 46 41 42 43 38 39 40 35 36 37 32 33 34 29 30 31 26 27 28 23 24 25 20 21 22 17 18 19 14 15 16 11 12 13 8 9 10 5 6 7 2 3 4 97 98", "output": "20000034" }, { "input": "95 10000000\n92 93 94 89 90 91 86 87 88 83 84 85 80 81 82 77 78 79 74 75 76 71 72 73 68 69 70 65 66 67 62 63 64 59 60 61 56 57 58 53 54 55 50 51 52 47 48 49 44 45 46 41 42 43 38 39 40 35 36 37 32 33 34 29 30 31 26 27 28 23 24 25 20 21 22 17 18 19 14 15 16 11 12 13 8 9 10 5 6 7 2 3 4 94 95", "output": "20000033" }, { "input": "98 10000000\n195 196 197 192 193 194 189 190 191 186 187 188 183 184 185 180 181 182 177 178 179 174 175 176 171 172 173 168 169 170 165 166 167 162 163 164 159 160 161 156 157 158 153 154 155 150 151 152 147 148 149 144 145 146 141 142 143 138 139 140 135 136 137 132 133 134 129 130 131 126 127 128 123 124 125 120 121 122 117 118 119 114 115 116 111 112 113 108 109 110 105 106 107 102 103 104 1 2", "output": "10000065" }, { "input": "95 10000000\n192 193 194 189 190 191 186 187 188 183 184 185 180 181 182 177 178 179 174 175 176 171 172 173 168 169 170 165 166 167 162 163 164 159 160 161 156 157 158 153 154 155 150 151 152 147 148 149 144 145 146 141 142 143 138 139 140 135 136 137 132 133 134 129 130 131 126 127 128 123 124 125 120 121 122 117 118 119 114 115 116 111 112 113 108 109 110 105 106 107 102 103 104 1 2", "output": "10000063" }, { "input": "98 10000000\n1 2 195 196 197 192 193 194 189 190 191 186 187 188 183 184 185 180 181 182 177 178 179 174 175 176 171 172 173 168 169 170 165 166 167 162 163 164 159 160 161 156 157 158 153 154 155 150 151 152 147 148 149 144 145 146 141 142 143 138 139 140 135 136 137 132 133 134 129 130 131 126 127 128 123 124 125 120 121 122 117 118 119 114 115 116 111 112 113 108 109 110 105 106 107 102 103 104", "output": "10000066" }, { "input": "98 10000000\n1 2 5 4 3 8 7 6 11 10 9 14 13 12 17 16 15 20 19 18 23 22 21 26 25 24 29 28 27 32 31 30 35 34 33 38 37 36 41 40 39 44 43 42 47 46 45 50 49 48 53 52 51 56 55 54 59 58 57 62 61 60 65 64 63 68 67 66 71 70 69 74 73 72 77 76 75 80 79 78 83 82 81 86 85 84 89 88 87 92 91 90 95 94 93 98 97 96", "output": "10000033" }, { "input": "98 10000000\n1 1 5 4 3 8 7 6 11 10 9 14 13 12 17 16 15 20 19 18 23 22 21 26 25 24 29 28 27 32 31 30 35 34 33 38 37 36 41 40 39 44 43 42 47 46 45 50 49 48 53 52 51 56 55 54 59 58 57 62 61 60 65 64 63 68 67 66 71 70 69 74 73 72 77 76 75 80 79 78 83 82 81 86 85 84 89 88 87 92 91 90 95 94 93 98 97 96", "output": "20000032" }, { "input": "98 10000000\n1 2 95 96 97 92 93 94 89 90 91 86 87 88 83 84 85 80 81 82 77 78 79 74 75 76 71 72 73 68 69 70 65 66 67 62 63 64 59 60 61 56 57 58 53 54 55 50 51 52 47 48 49 44 45 46 41 42 43 38 39 40 35 36 37 32 33 34 29 30 31 26 27 28 23 24 25 20 21 22 17 18 19 14 15 16 11 12 13 8 9 10 5 6 7 2 3 4", "output": "20000034" }, { "input": "99 10000000\n1 2 3 95 96 97 92 93 94 89 90 91 86 87 88 83 84 85 80 81 82 77 78 79 74 75 76 71 72 73 68 69 70 65 66 67 62 63 64 59 60 61 56 57 58 53 54 55 50 51 52 47 48 49 44 45 46 41 42 43 38 39 40 35 36 37 32 33 34 29 30 31 26 27 28 23 24 25 20 21 22 17 18 19 14 15 16 11 12 13 8 9 10 5 6 7 2 3 4", "output": "20000034" }, { "input": "100 10000000\n1 2 2 1 2 2 1 1 2 2 1 2 1 1 1 1 1 2 2 2 1 2 1 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 1 2 2 1 1 2 2 2 2 2 2 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 2 2 2 1 1 2 2 1 2 1 1 2 2 1 1 1 2 1 2 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1", "output": "560000000" }, { "input": "100 10000000\n2 4 2 5 2 1 1 3 2 4 3 5 3 4 2 4 2 4 1 2 3 3 1 1 3 3 1 3 5 1 2 1 5 2 3 4 5 2 1 2 1 3 4 4 4 3 5 5 3 1 5 2 1 4 4 3 2 3 2 3 2 4 2 1 3 3 3 2 3 5 1 5 4 3 1 4 5 3 2 4 5 4 1 3 4 1 1 3 4 2 2 5 4 2 2 3 3 2 3 1", "output": "260000004" }, { "input": "100 10000000\n31 150 132 17 273 18 292 260 226 217 165 68 36 176 89 75 227 246 137 151 87 215 267 242 21 156 27 27 202 73 218 290 57 2 85 159 96 39 191 268 67 64 55 266 29 209 215 85 149 267 161 153 118 293 104 197 91 252 275 56 288 76 82 239 215 105 283 88 76 294 138 166 9 273 14 119 67 101 250 13 63 215 80 5 221 234 258 195 129 67 152 56 277 129 111 98 213 22 209 299", "output": "40000023" }, { "input": "100 10000000\n285 219 288 277 266 249 297 286 290 266 210 201 275 280 200 272 297 253 246 292 272 285 226 250 297 270 214 251 263 285 237 292 245 225 247 221 263 250 253 280 235 288 278 297 283 294 208 279 227 290 246 208 274 238 282 240 214 277 239 282 255 278 214 292 277 267 290 257 239 234 252 246 217 274 254 249 229 275 210 297 254 215 222 228 262 287 290 292 277 227 292 282 248 278 207 249 236 240 252 216", "output": "50000016" }, { "input": "100 10000000\n300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300", "output": "1000000000" }, { "input": "99 10000000\n300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300", "output": "990000000" }, { "input": "99 10000000\n299 299 300 300 299 299 300 299 299 299 299 299 299 299 299 300 300 300 299 300 300 300 299 299 299 299 299 299 300 299 299 300 299 299 300 300 300 299 300 300 299 299 300 299 300 300 299 300 299 300 299 300 300 299 299 299 299 299 299 300 299 299 300 300 300 299 300 299 300 300 299 299 299 299 299 299 299 299 300 299 300 300 299 300 300 299 299 300 300 299 300 300 299 300 299 299 300 299 299", "output": "580000001" }, { "input": "1 1\n5", "output": "1" }, { "input": "1 10000000\n1", "output": "10000000" }, { "input": "2 1\n1 2", "output": "2" }, { "input": "2 2\n1 2", "output": "3" }, { "input": "2 1000\n1 2", "output": "1001" }, { "input": "100 100\n99 100 97 98 95 96 93 94 91 92 89 90 87 88 85 86 83 84 81 82 79 80 77 78 75 76 73 74 71 72 69 70 67 68 65 66 63 64 61 62 59 60 57 58 55 56 53 54 51 52 49 50 47 48 45 46 43 44 41 42 39 40 37 38 35 36 33 34 31 32 29 30 27 28 25 26 23 24 21 22 19 20 17 18 15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2", "output": "150" }, { "input": "100 82\n151 81 114 37 17 178 92 164 215 108 286 89 108 87 77 166 110 215 212 300 125 92 247 221 78 120 163 113 249 141 36 241 179 116 187 287 69 103 76 80 160 200 249 170 159 72 8 138 171 45 97 271 114 176 54 181 4 259 246 39 29 292 203 49 122 253 99 259 252 74 231 92 43 142 23 144 109 282 47 207 140 212 9 3 255 137 285 146 22 84 52 98 41 21 177 63 217 62 291 64", "output": "274" }, { "input": "99 105\n16 118 246 3 44 149 156 290 44 267 221 123 57 175 233 24 23 120 298 228 119 62 23 183 169 294 195 115 131 157 223 298 77 106 283 117 255 41 17 298 22 176 164 187 214 101 10 181 117 70 271 291 59 156 44 204 140 205 253 176 270 43 188 287 40 250 271 100 244 297 133 228 98 218 290 69 171 66 195 283 63 154 191 66 238 104 32 122 79 190 55 110 276 2 188 26 44 276 230", "output": "435" }, { "input": "99 84\n62 4 145 285 106 132 30 96 211 28 144 190 95 184 227 177 128 60 143 19 19 81 38 83 108 172 241 228 48 39 171 282 233 294 74 271 178 87 24 180 212 190 223 153 230 198 261 232 150 18 190 91 265 61 280 13 207 70 182 117 270 77 242 163 138 212 165 273 247 23 52 88 243 85 293 12 135 284 162 91 174 109 42 19 218 289 9 59 9 117 61 122 78 287 144 176 281 123 243", "output": "280" }, { "input": "99 116\n102 257 115 247 279 111 118 255 198 168 183 184 32 3 36 204 178 186 88 67 205 91 21 40 116 93 2 148 226 65 37 69 69 7 82 205 152 25 34 272 26 283 78 142 17 110 101 250 120 128 145 276 182 57 19 104 228 221 94 220 279 216 220 294 3 289 185 272 73 180 246 107 246 260 219 268 218 41 166 50 230 143 166 158 194 153 256 209 28 255 77 33 143 296 38 81 133 57 263", "output": "268" }, { "input": "99 125\n85 108 102 3 173 193 27 38 288 272 14 270 98 42 34 206 275 54 20 164 207 255 3 196 183 3 61 37 98 223 208 231 144 76 114 19 138 156 157 198 124 39 120 283 34 139 240 240 247 132 211 81 225 12 101 108 63 20 30 158 266 201 101 101 113 157 132 108 41 215 54 27 154 102 175 276 103 35 52 130 10 266 229 202 85 210 116 149 214 14 121 263 217 152 240 275 113 253 53", "output": "404" }, { "input": "99 9\n218 254 64 32 130 52 242 40 29 188 196 300 258 165 110 151 265 142 295 166 141 260 158 218 184 251 180 16 177 125 192 279 201 189 170 37 7 150 117 79 97 13 69 156 254 287 17 214 95 300 150 197 133 161 46 26 82 119 174 6 252 42 264 136 273 127 42 274 113 278 165 173 231 209 159 56 248 39 46 41 222 278 114 84 150 13 63 106 179 279 44 15 13 74 50 168 38 181 127", "output": "51" }, { "input": "100 200\n99 100 97 98 95 96 93 94 91 92 89 90 87 88 85 86 83 84 81 82 79 80 77 78 75 76 73 74 71 72 69 70 67 68 65 66 63 64 61 62 59 60 57 58 55 56 53 54 51 52 49 50 47 48 45 46 43 44 41 42 39 40 37 38 35 36 33 34 31 32 29 30 27 28 25 26 23 24 21 22 19 20 17 18 15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2", "output": "250" }, { "input": "100 201\n99 100 97 98 95 96 93 94 91 92 89 90 87 88 85 86 83 84 81 82 79 80 77 78 75 76 73 74 71 72 69 70 67 68 65 66 63 64 61 62 59 60 57 58 55 56 53 54 51 52 49 50 47 48 45 46 43 44 41 42 39 40 37 38 35 36 33 34 31 32 29 30 27 28 25 26 23 24 21 22 19 20 17 18 15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2", "output": "251" }, { "input": "100 199\n99 100 97 98 95 96 93 94 91 92 89 90 87 88 85 86 83 84 81 82 79 80 77 78 75 76 73 74 71 72 69 70 67 68 65 66 63 64 61 62 59 60 57 58 55 56 53 54 51 52 49 50 47 48 45 46 43 44 41 42 39 40 37 38 35 36 33 34 31 32 29 30 27 28 25 26 23 24 21 22 19 20 17 18 15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2", "output": "249" } ]
1,679,822,518
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
# LUOGU_RID: 106017893 #include<bits/stdc++.h> using namespace std; const int N = 105; int n,T,a[N],h[405],dp[N*N]; int main(){ scanf("%d%d",&n,&T); for(int i=1;i<=n;i++) scanf("%d",a+i),h[a[i]]++; int maxx=-1,id=1; for(int i=1;i<=300;i++){ if(maxx<h[i]){ maxx=h[i]; id=i; } } int nn=n*min(n,T),c=0; for(int i=1;i<=nn;i++){ for(int j=i-1;j>=(i==1?1:i-n);j--){ if(a[i]>=a[j]){ dp[i]=max(dp[i],dp[j]+1); } } c=max(c,dp[i]); } if(nn==n*n){ printf("%d",c); return 0; }else{ printf("%d",c+(t-n)); } return 0; }
Title: Once Again... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of positive integers *a*1,<=*a*2,<=...,<=*a**n*<=×<=*T* of length *n*<=×<=*T*. We know that for any *i*<=&gt;<=*n* it is true that *a**i*<==<=*a**i*<=-<=*n*. Find the length of the longest non-decreasing sequence of the given array. Input Specification: The first line contains two space-separated integers: *n*, *T* (1<=≤<=*n*<=≤<=100, 1<=≤<=*T*<=≤<=107). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=300). Output Specification: Print a single number — the length of a sought sequence. Demo Input: ['4 3\n3 1 4 2\n'] Demo Output: ['5\n'] Note: The array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.
```python # LUOGU_RID: 106017893 #include<bits/stdc++.h> using namespace std; const int N = 105; int n,T,a[N],h[405],dp[N*N]; int main(){ scanf("%d%d",&n,&T); for(int i=1;i<=n;i++) scanf("%d",a+i),h[a[i]]++; int maxx=-1,id=1; for(int i=1;i<=300;i++){ if(maxx<h[i]){ maxx=h[i]; id=i; } } int nn=n*min(n,T),c=0; for(int i=1;i<=nn;i++){ for(int j=i-1;j>=(i==1?1:i-n);j--){ if(a[i]>=a[j]){ dp[i]=max(dp[i],dp[j]+1); } } c=max(c,dp[i]); } if(nn==n*n){ printf("%d",c); return 0; }else{ printf("%d",c+(t-n)); } return 0; } ```
-1
177
A1
Good Matrix Elements
PROGRAMMING
800
[ "implementation" ]
null
null
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it. Help the Smart Beaver count the sum of good elements of the given matrix.
The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=101
Print a single integer — the sum of good matrix elements.
[ "3\n1 2 3\n4 5 6\n7 8 9\n", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n" ]
[ "45\n", "17\n" ]
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
30
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "45" }, { "input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "output": "17" }, { "input": "1\n3", "output": "3" }, { "input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33", "output": "756" }, { "input": "3\n19 7 16\n12 15 5\n15 15 5", "output": "109" }, { "input": "3\n36 4 33\n11 46 32\n20 49 34", "output": "265" }, { "input": "3\n79 91 74\n33 82 22\n18 28 54", "output": "481" }, { "input": "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8 1 6\n1 2 3 2 7\n6 0 1 9 6", "output": "65" }, { "input": "5\n27 20 28 11 17\n25 21 1 20 14\n14 22 28 1 6\n1 2 23 2 7\n6 0 1 29 6", "output": "225" }, { "input": "5\n57 50 58 41 17\n25 21 1 50 44\n44 22 28 31 36\n31 32 23 32 37\n6 0 31 59 6", "output": "495" }, { "input": "5\n57 80 28 41 47\n85 51 61 50 74\n44 82 28 31 36\n31 32 23 32 37\n66 60 31 59 6", "output": "705" }, { "input": "5\n13 58 10 17 43\n61 73 100 0 9\n52 38 16 22 96\n11 4 14 67 62\n70 89 7 98 83", "output": "708" }, { "input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "5\n0 1 0 1 0\n0 0 0 0 1\n0 0 5 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "5" }, { "input": "5\n0 0 0 0 1\n0 1 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 1 0 0 0", "output": "3" }, { "input": "3\n0 0 0\n0 0 0\n0 0 0", "output": "0" } ]
1,674,956,699
2,147,483,647
Python 3
OK
TESTS1
17
92
0
n = int(input()) m = [[int(i) for i in input().split()] for _ in range(n)] res = 0 for r in range(n): for c in range(n): if r == c or r + c == n - 1 or r == (n - 1) / 2 or c == (n - 1) / 2: res += m[r][c] print(res)
Title: Good Matrix Elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it. Help the Smart Beaver count the sum of good elements of the given matrix. Input Specification: The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=101 Output Specification: Print a single integer — the sum of good matrix elements. Demo Input: ['3\n1 2 3\n4 5 6\n7 8 9\n', '5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n'] Demo Output: ['45\n', '17\n'] Note: In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
```python n = int(input()) m = [[int(i) for i in input().split()] for _ in range(n)] res = 0 for r in range(n): for c in range(n): if r == c or r + c == n - 1 or r == (n - 1) / 2 or c == (n - 1) / 2: res += m[r][c] print(res) ```
3
696
B
Puzzles
PROGRAMMING
1,700
[ "dfs and similar", "math", "probabilities", "trees" ]
null
null
Barney lives in country USC (United States of Charzeh). USC has *n* cities numbered from 1 through *n* and *n*<=-<=1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city he wants by following roads. Some girl has stolen Barney's heart, and Barney wants to find her. He starts looking for in the root of the tree and (since he is Barney Stinson not a random guy), he uses a random DFS to search in the cities. A pseudo code of this algorithm is as follows: As told before, Barney will start his journey in the root of the tree (equivalent to call dfs(1)). Now Barney needs to pack a backpack and so he wants to know more about his upcoming journey: for every city *i*, Barney wants to know the expected value of starting_time[i]. He's a friend of Jon Snow and knows nothing, that's why he asked for your help.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities in USC. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is the number of the parent city of city number *i* in the tree, meaning there is a road between cities numbered *p**i* and *i* in USC.
In the first and only line of output print *n* numbers, where *i*-th number is the expected value of starting_time[i]. Your answer for each city will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
[ "7\n1 2 1 1 4 4\n", "12\n1 1 2 2 4 4 3 3 1 10 8\n" ]
[ "1.0 4.0 5.0 3.5 4.5 5.0 5.0 \n", "1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 \n" ]
none
1,000
[ { "input": "7\n1 2 1 1 4 4", "output": "1.0 4.0 5.0 3.5 4.5 5.0 5.0 " }, { "input": "12\n1 1 2 2 4 4 3 3 1 10 8", "output": "1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 " }, { "input": "3\n1 2", "output": "1.0 2.0 3.0 " }, { "input": "8\n1 1 2 2 3 6 1", "output": "1.0 4.0 4.0 5.5 5.5 5.0 6.0 5.0 " }, { "input": "85\n1 1 2 2 4 6 1 3 6 3 3 11 9 14 12 5 8 11 16 19 12 17 2 19 1 24 6 2 6 6 24 3 20 1 1 1 17 8 4 25 31 32 39 12 35 23 31 26 46 9 37 7 5 23 41 41 39 9 11 54 36 54 28 15 25 58 56 18 23 70 68 18 3 48 57 70 15 65 22 35 25 13 49 34", "output": "1.0 28.5 27.0 38.0 38.5 39.5 44.5 40.0 40.5 45.0 37.0 40.5 44.0 42.5 43.5 43.0 41.0 43.0 39.5 44.0 45.0 44.0 42.5 42.5 41.0 42.5 44.5 44.5 44.0 45.0 43.5 44.0 44.0 45.0 42.0 43.0 43.0 45.0 42.5 44.5 43.0 45.5 45.0 44.5 44.5 43.5 45.5 45.0 43.5 44.5 44.5 44.0 45.5 43.5 45.5 45.0 45.5 44.0 44.5 44.5 45.0 44.0 45.0 45.5 45.0 45.5 45.0 46.0 44.5 44.5 46.0 47.0 44.5 44.0 46.0 46.5 46.0 45.5 46.0 45.0 44.0 45.5 45.0 44.5 46.0 " }, { "input": "1", "output": "1.0 " }, { "input": "2\n1", "output": "1.0 2.0 " }, { "input": "10\n1 2 2 2 5 4 6 5 6", "output": "1.0 2.0 6.5 6.0 4.5 6.0 7.0 7.5 7.0 7.5 " } ]
1,468,928,479
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
5,939,200
n=int(input()) x=input().split(' ') x.insert(0, 0) x.insert(0, 0) for i in range(n+1): x[i]=int(x[i]) t=[0 for i in range(n+1)] ch=[1 for i in range (n+1)] z=tuple(x) while any(x[i]!=0 for i in range(2, n+1)): for i in range(2, n+1): if x[i]!=0: t[i]+=1 ch[x[i]]+=1 x[i]=z[x[i]] for i in range(1, n+1): print((n+2+t[i]-ch[i])/2, end=' ')
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Barney lives in country USC (United States of Charzeh). USC has *n* cities numbered from 1 through *n* and *n*<=-<=1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city he wants by following roads. Some girl has stolen Barney's heart, and Barney wants to find her. He starts looking for in the root of the tree and (since he is Barney Stinson not a random guy), he uses a random DFS to search in the cities. A pseudo code of this algorithm is as follows: As told before, Barney will start his journey in the root of the tree (equivalent to call dfs(1)). Now Barney needs to pack a backpack and so he wants to know more about his upcoming journey: for every city *i*, Barney wants to know the expected value of starting_time[i]. He's a friend of Jon Snow and knows nothing, that's why he asked for your help. Input Specification: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities in USC. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is the number of the parent city of city number *i* in the tree, meaning there is a road between cities numbered *p**i* and *i* in USC. Output Specification: In the first and only line of output print *n* numbers, where *i*-th number is the expected value of starting_time[i]. Your answer for each city will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Demo Input: ['7\n1 2 1 1 4 4\n', '12\n1 1 2 2 4 4 3 3 1 10 8\n'] Demo Output: ['1.0 4.0 5.0 3.5 4.5 5.0 5.0 \n', '1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 \n'] Note: none
```python n=int(input()) x=input().split(' ') x.insert(0, 0) x.insert(0, 0) for i in range(n+1): x[i]=int(x[i]) t=[0 for i in range(n+1)] ch=[1 for i in range (n+1)] z=tuple(x) while any(x[i]!=0 for i in range(2, n+1)): for i in range(2, n+1): if x[i]!=0: t[i]+=1 ch[x[i]]+=1 x[i]=z[x[i]] for i in range(1, n+1): print((n+2+t[i]-ch[i])/2, end=' ') ```
0
586
A
Alena's Schedule
PROGRAMMING
900
[ "implementation" ]
null
null
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks). The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not. Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university. Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home. Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university. The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces.
Print a single number — the number of pairs during which Alena stays at the university.
[ "5\n0 1 0 1 1\n", "7\n1 0 1 0 0 1 0\n", "1\n0\n" ]
[ "4\n", "4\n", "0\n" ]
In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.
500
[ { "input": "5\n0 1 0 1 1", "output": "4" }, { "input": "7\n1 0 1 0 0 1 0", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "2\n0 0", "output": "0" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n1 1", "output": "2" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "11\n0 0 0 0 0 0 0 0 0 0 1", "output": "1" }, { "input": "12\n1 0 0 0 0 0 0 0 0 0 0 0", "output": "1" }, { "input": "20\n1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0", "output": "16" }, { "input": "41\n1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 1", "output": "28" }, { "input": "63\n1 1 0 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 0", "output": "39" }, { "input": "80\n0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1", "output": "52" }, { "input": "99\n1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1", "output": "72" }, { "input": "100\n0 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 0", "output": "65" }, { "input": "11\n0 1 1 0 0 0 0 0 0 0 0", "output": "2" }, { "input": "11\n0 1 0 1 0 0 1 1 0 1 1", "output": "8" }, { "input": "11\n1 0 1 0 1 1 0 1 1 1 0", "output": "10" }, { "input": "11\n1 0 0 0 0 0 1 0 1 1 1", "output": "6" }, { "input": "22\n0 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0", "output": "7" }, { "input": "22\n0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1", "output": "16" }, { "input": "22\n1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0", "output": "11" }, { "input": "22\n1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 1", "output": "14" }, { "input": "33\n0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0", "output": "26" }, { "input": "33\n0 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 1 1 1 0 1", "output": "27" }, { "input": "33\n1 0 1 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 0", "output": "25" }, { "input": "33\n1 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 1 1", "output": "24" }, { "input": "44\n0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 0", "output": "19" }, { "input": "44\n0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1", "output": "32" }, { "input": "44\n1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0", "output": "23" }, { "input": "44\n1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1", "output": "32" }, { "input": "55\n0 1 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0", "output": "23" }, { "input": "55\n0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1", "output": "39" }, { "input": "55\n1 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0", "output": "32" }, { "input": "55\n1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 1", "output": "36" }, { "input": "66\n0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 0 0 0 0 0 1 0", "output": "41" }, { "input": "66\n0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 1", "output": "42" }, { "input": "66\n1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 0 0", "output": "46" }, { "input": "66\n1 0 1 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 1", "output": "46" }, { "input": "77\n0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 0", "output": "47" }, { "input": "77\n0 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1", "output": "44" }, { "input": "77\n1 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0", "output": "45" }, { "input": "77\n1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1", "output": "51" }, { "input": "88\n0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0", "output": "44" }, { "input": "88\n0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1", "output": "59" }, { "input": "88\n1 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0", "output": "53" }, { "input": "88\n1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 0 1", "output": "63" }, { "input": "99\n0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 0 1 1 0 0 0 0", "output": "56" }, { "input": "99\n0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1", "output": "58" }, { "input": "99\n1 1 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 1 1 1 0 0 1 0", "output": "65" }, { "input": "99\n1 1 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1", "output": "77" }, { "input": "90\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "90\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "90" }, { "input": "95\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "95\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "95" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" } ]
1,445,067,274
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; #define min(a,b) (a<b?a:b) int main() { // your code goes here int n,a[101],i,ans=0; cin>>n; for(i=1;i<=n;i++) { cin>>a[i]; } for(i=1;i<=n;i++) { if(a[i]==1) ans++; else if (a[i-1]==1 && a[i]==0 && a[i+1]==1) ans++; } cout<<ans<<endl; return 0; }
Title: Alena's Schedule Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks). The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not. Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university. Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home. Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university. The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces. Output Specification: Print a single number — the number of pairs during which Alena stays at the university. Demo Input: ['5\n0 1 0 1 1\n', '7\n1 0 1 0 0 1 0\n', '1\n0\n'] Demo Output: ['4\n', '4\n', '0\n'] Note: In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.
```python #include <bits/stdc++.h> using namespace std; #define min(a,b) (a<b?a:b) int main() { // your code goes here int n,a[101],i,ans=0; cin>>n; for(i=1;i<=n;i++) { cin>>a[i]; } for(i=1;i<=n;i++) { if(a[i]==1) ans++; else if (a[i-1]==1 && a[i]==0 && a[i+1]==1) ans++; } cout<<ans<<endl; return 0; } ```
-1
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b" }, { "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs" }, { "input": "1 1\namit am\namit", "output": "am" }, { "input": "1 1\na c\na", "output": "a" } ]
1,677,485,974
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n,m = map(int,input().split()) first = [] second = [] res = [] for i in range(m): a,b = map(str, input().split()) first.append(a) second.append(b) for i in input().split(): if i in first: if len(i) < len(second[first.index(i)]): res.append(i) else: res.append(second[first.index(i)]) else: if len(i) > len(second[first.index(i)]): res.append(second[first.index(i)]) else: res.append(i) print(*res)
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python n,m = map(int,input().split()) first = [] second = [] res = [] for i in range(m): a,b = map(str, input().split()) first.append(a) second.append(b) for i in input().split(): if i in first: if len(i) < len(second[first.index(i)]): res.append(i) else: res.append(second[first.index(i)]) else: if len(i) > len(second[first.index(i)]): res.append(second[first.index(i)]) else: res.append(i) print(*res) ```
0
675
A
Infinite Sequence
PROGRAMMING
1,100
[ "math" ]
null
null
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
[ "1 7 3\n", "10 10 0\n", "1 -4 5\n", "0 60 50\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
500
[ { "input": "1 7 3", "output": "YES" }, { "input": "10 10 0", "output": "YES" }, { "input": "1 -4 5", "output": "NO" }, { "input": "0 60 50", "output": "NO" }, { "input": "1 -4 -5", "output": "YES" }, { "input": "0 1 0", "output": "NO" }, { "input": "10 10 42", "output": "YES" }, { "input": "-1000000000 1000000000 -1", "output": "NO" }, { "input": "10 16 4", "output": "NO" }, { "input": "-1000000000 1000000000 5", "output": "YES" }, { "input": "1000000000 -1000000000 5", "output": "NO" }, { "input": "1000000000 -1000000000 0", "output": "NO" }, { "input": "1000000000 1000000000 0", "output": "YES" }, { "input": "115078364 -899474523 -1", "output": "YES" }, { "input": "-245436499 416383245 992", "output": "YES" }, { "input": "-719636354 536952440 2", "output": "YES" }, { "input": "-198350539 963391024 68337739", "output": "YES" }, { "input": "-652811055 875986516 1091", "output": "YES" }, { "input": "119057893 -516914539 -39748277", "output": "YES" }, { "input": "989140430 731276607 -36837689", "output": "YES" }, { "input": "677168390 494583489 -985071853", "output": "NO" }, { "input": "58090193 777423708 395693923", "output": "NO" }, { "input": "479823846 -403424770 -653472589", "output": "NO" }, { "input": "-52536829 -132023273 -736287999", "output": "NO" }, { "input": "-198893776 740026818 -547885271", "output": "NO" }, { "input": "-2 -2 -2", "output": "YES" }, { "input": "-2 -2 -1", "output": "YES" }, { "input": "-2 -2 0", "output": "YES" }, { "input": "-2 -2 1", "output": "YES" }, { "input": "-2 -2 2", "output": "YES" }, { "input": "-2 -1 -2", "output": "NO" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "-2 -1 0", "output": "NO" }, { "input": "-2 -1 1", "output": "YES" }, { "input": "-2 -1 2", "output": "NO" }, { "input": "-2 0 -2", "output": "NO" }, { "input": "-2 0 -1", "output": "NO" }, { "input": "-2 0 0", "output": "NO" }, { "input": "-2 0 1", "output": "YES" }, { "input": "-2 0 2", "output": "YES" }, { "input": "-2 1 -2", "output": "NO" }, { "input": "-2 1 -1", "output": "NO" }, { "input": "-2 1 0", "output": "NO" }, { "input": "-2 1 1", "output": "YES" }, { "input": "-2 1 2", "output": "NO" }, { "input": "-2 2 -2", "output": "NO" }, { "input": "-2 2 -1", "output": "NO" }, { "input": "-2 2 0", "output": "NO" }, { "input": "-2 2 1", "output": "YES" }, { "input": "-2 2 2", "output": "YES" }, { "input": "-1 -2 -2", "output": "NO" }, { "input": "-1 -2 -1", "output": "YES" }, { "input": "-1 -2 0", "output": "NO" }, { "input": "-1 -2 1", "output": "NO" }, { "input": "-1 -2 2", "output": "NO" }, { "input": "-1 -1 -2", "output": "YES" }, { "input": "-1 -1 -1", "output": "YES" }, { "input": "-1 -1 0", "output": "YES" }, { "input": "-1 -1 1", "output": "YES" }, { "input": "-1 -1 2", "output": "YES" }, { "input": "-1 0 -2", "output": "NO" }, { "input": "-1 0 -1", "output": "NO" }, { "input": "-1 0 0", "output": "NO" }, { "input": "-1 0 1", "output": "YES" }, { "input": "-1 0 2", "output": "NO" }, { "input": "-1 1 -2", "output": "NO" }, { "input": "-1 1 -1", "output": "NO" }, { "input": "-1 1 0", "output": "NO" }, { "input": "-1 1 1", "output": "YES" }, { "input": "-1 1 2", "output": "YES" }, { "input": "-1 2 -2", "output": "NO" }, { "input": "-1 2 -1", "output": "NO" }, { "input": "-1 2 0", "output": "NO" }, { "input": "-1 2 1", "output": "YES" }, { "input": "-1 2 2", "output": "NO" }, { "input": "0 -2 -2", "output": "YES" }, { "input": "0 -2 -1", "output": "YES" }, { "input": "0 -2 0", "output": "NO" }, { "input": "0 -2 1", "output": "NO" }, { "input": "0 -2 2", "output": "NO" }, { "input": "0 -1 -2", "output": "NO" }, { "input": "0 -1 -1", "output": "YES" }, { "input": "0 -1 0", "output": "NO" }, { "input": "0 -1 1", "output": "NO" }, { "input": "0 -1 2", "output": "NO" }, { "input": "0 0 -2", "output": "YES" }, { "input": "0 0 -1", "output": "YES" }, { "input": "0 0 0", "output": "YES" }, { "input": "0 0 1", "output": "YES" }, { "input": "0 0 2", "output": "YES" }, { "input": "0 1 -2", "output": "NO" }, { "input": "0 1 -1", "output": "NO" }, { "input": "0 1 0", "output": "NO" }, { "input": "0 1 1", "output": "YES" }, { "input": "0 1 2", "output": "NO" }, { "input": "0 2 -2", "output": "NO" }, { "input": "0 2 -1", "output": "NO" }, { "input": "0 2 0", "output": "NO" }, { "input": "0 2 1", "output": "YES" }, { "input": "0 2 2", "output": "YES" }, { "input": "1 -2 -2", "output": "NO" }, { "input": "1 -2 -1", "output": "YES" }, { "input": "1 -2 0", "output": "NO" }, { "input": "1 -2 1", "output": "NO" }, { "input": "1 -2 2", "output": "NO" }, { "input": "1 -1 -2", "output": "YES" }, { "input": "1 -1 -1", "output": "YES" }, { "input": "1 -1 0", "output": "NO" }, { "input": "1 -1 1", "output": "NO" }, { "input": "1 -1 2", "output": "NO" }, { "input": "1 0 -2", "output": "NO" }, { "input": "1 0 -1", "output": "YES" }, { "input": "1 0 0", "output": "NO" }, { "input": "1 0 1", "output": "NO" }, { "input": "1 0 2", "output": "NO" }, { "input": "1 1 -2", "output": "YES" }, { "input": "1 1 -1", "output": "YES" }, { "input": "1 1 0", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "1 1 2", "output": "YES" }, { "input": "1 2 -2", "output": "NO" }, { "input": "1 2 -1", "output": "NO" }, { "input": "1 2 0", "output": "NO" }, { "input": "1 2 1", "output": "YES" }, { "input": "1 2 2", "output": "NO" }, { "input": "2 -2 -2", "output": "YES" }, { "input": "2 -2 -1", "output": "YES" }, { "input": "2 -2 0", "output": "NO" }, { "input": "2 -2 1", "output": "NO" }, { "input": "2 -2 2", "output": "NO" }, { "input": "2 -1 -2", "output": "NO" }, { "input": "2 -1 -1", "output": "YES" }, { "input": "2 -1 0", "output": "NO" }, { "input": "2 -1 1", "output": "NO" }, { "input": "2 -1 2", "output": "NO" }, { "input": "2 0 -2", "output": "YES" }, { "input": "2 0 -1", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "2 0 1", "output": "NO" }, { "input": "2 0 2", "output": "NO" }, { "input": "2 1 -2", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "2 1 0", "output": "NO" }, { "input": "2 1 1", "output": "NO" }, { "input": "2 1 2", "output": "NO" }, { "input": "2 2 -2", "output": "YES" }, { "input": "2 2 -1", "output": "YES" }, { "input": "2 2 0", "output": "YES" }, { "input": "2 2 1", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "-1000000000 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 2", "output": "YES" }, { "input": "1000000000 -1000000000 -1", "output": "YES" }, { "input": "5 2 3", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "3 2 1", "output": "NO" }, { "input": "0 -5 -3", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "0 10 1", "output": "YES" }, { "input": "15 5 -5", "output": "YES" }, { "input": "2 1 1", "output": "NO" }, { "input": "20 10 0", "output": "NO" }, { "input": "20 15 5", "output": "NO" }, { "input": "1 6 1", "output": "YES" }, { "input": "1000000000 0 -1000000000", "output": "YES" }, { "input": "1 1 -5", "output": "YES" }, { "input": "4 6 1", "output": "YES" }, { "input": "-5 -10 -5", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "10 9 -1", "output": "YES" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "1 13 3", "output": "YES" }, { "input": "2 3 0", "output": "NO" }, { "input": "1 1 -1", "output": "YES" }, { "input": "5 -10 -5", "output": "YES" }, { "input": "5 3 1", "output": "NO" }, { "input": "1 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 1000000000", "output": "YES" } ]
1,689,937,091
2,147,483,647
PyPy 3-64
OK
TESTS
178
77
0
a, b, c = map(int, input().split()) d = b - a if a == b: print("YES") elif d > 0 and c > 0 and float(d / c).is_integer(): print("YES") elif d < 0 and c < 0 and float(d / c).is_integer(): print("YES") else: print("NO")
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help. Input Specification: The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. Output Specification: If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). Demo Input: ['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
```python a, b, c = map(int, input().split()) d = b - a if a == b: print("YES") elif d > 0 and c > 0 and float(d / c).is_integer(): print("YES") elif d < 0 and c < 0 and float(d / c).is_integer(): print("YES") else: print("NO") ```
3