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
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, { "input": "192", "output": "4 188" }, { "input": "86", "output": "4 82" }, { "input": "46220", "output": "4 46216" }, { "input": "57114", "output": "4 57110" }, { "input": "869", "output": "4 865" }, { "input": "738457", "output": "4 738453" }, { "input": "58113", "output": "6 58107" }, { "input": "4864", "output": "4 4860" }, { "input": "15", "output": "6 9" }, { "input": "74752", "output": "4 74748" }, { "input": "6073", "output": "4 6069" }, { "input": "1289", "output": "4 1285" }, { "input": "20", "output": "4 16" }, { "input": "58134", "output": "4 58130" }, { "input": "57756", "output": "4 57752" }, { "input": "765", "output": "6 759" }, { "input": "59", "output": "4 55" }, { "input": "991666", "output": "4 991662" }, { "input": "70761", "output": "4 70757" }, { "input": "13", "output": "4 9" }, { "input": "999999", "output": "4 999995" }, { "input": "17", "output": "8 9" }, { "input": "21", "output": "6 15" }, { "input": "19", "output": "4 15" }, { "input": "100007", "output": "6 100001" }, { "input": "999987", "output": "6 999981" }, { "input": "22", "output": "4 18" } ]
1,695,206,831
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
n = int(input()) def is_composite(num): if num < 4: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return True return False x = 4 y = n - x while is_composite(x) or is_composite(y): x += 1 y -= 1 print(x, y)
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers. Input Specification: The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). Output Specification: Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. Demo Input: ['12\n', '15\n', '23\n', '1000000\n'] Demo Output: ['4 8\n', '6 9\n', '8 15\n', '500000 500000\n'] Note: In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
```python n = int(input()) def is_composite(num): if num < 4: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return True return False x = 4 y = n - x while is_composite(x) or is_composite(y): x += 1 y -= 1 print(x, y) ```
0
95
B
Lucky Numbers
PROGRAMMING
1,800
[ "dp", "greedy" ]
B. Lucky Numbers
2
256
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer *n*. Help him to find the least super lucky number which is not less than *n*.
The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=10100000). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to *n*.
[ "4500\n", "47\n" ]
[ "4747\n", "47\n" ]
none
1,000
[ { "input": "4500", "output": "4747" }, { "input": "47", "output": "47" }, { "input": "1", "output": "47" }, { "input": "12", "output": "47" }, { "input": "4587", "output": "4747" }, { "input": "100", "output": "4477" }, { "input": "1007", "output": "4477" }, { "input": "99999999", "output": "4444477777" }, { "input": "49102094540227023300", "output": "74444444444777777777" }, { "input": "1000000000", "output": "4444477777" }, { "input": "777777", "output": "44447777" }, { "input": "99999999", "output": "4444477777" }, { "input": "474", "output": "4477" }, { "input": "85469", "output": "444777" }, { "input": "7474747", "output": "44447777" }, { "input": "2145226", "output": "44447777" }, { "input": "5556585", "output": "44447777" }, { "input": "87584777", "output": "4444477777" }, { "input": "77777777", "output": "4444477777" }, { "input": "1000000000", "output": "4444477777" }, { "input": "999999999", "output": "4444477777" }, { "input": "74477744", "output": "74477744" }, { "input": "444444444", "output": "4444477777" }, { "input": "467549754", "output": "4444477777" }, { "input": "147474747", "output": "4444477777" }, { "input": "555", "output": "4477" }, { "input": "100000", "output": "444777" }, { "input": "74777443", "output": "74777444" }, { "input": "4700007", "output": "44447777" }, { "input": "70070077", "output": "74444777" }, { "input": "123", "output": "4477" }, { "input": "7474", "output": "7474" }, { "input": "3696", "output": "4477" }, { "input": "5594108733309806863211189515406929423407691887690557101598403485", "output": "7444444444444444444444444444444447777777777777777777777777777777" }, { "input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777" }, { "input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777" }, { "input": "300315701225398103949172355218103087569515283105400017868730132769291700939035921405014640214190659140126383204458315111136164707153628616177467538307534664174018683245377348638677858006052356516328838399769950207054982712314494543889750490268253870160095357456864075250350735474301206523459172092665900965024129501630212966373988276932458849720393142004789869863743947961634907491797090041095838600303393556660079821519800685499052949978754418782241756597476926001413610822", "output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444" }, { "input": "474777447477447774447777477444444747747747447474", "output": "474777447477447774447777477444444747747747447474" }, { "input": "4610011341130234325130111223432762111322200032405402224411031600004377332320125004161111207316702630337013246237324411010232123224431343463152610127222227432331505230001434422203415026064601462701340036346273331432110074431135223142761441433403414301432300263254301342131314327333745711213130421310313153504022700431534463141461236322033420140324202221402036761452134031253152442133141307046425107520", "output": "4744444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "35881905331681060827588553219538774024143083787975", "output": "44444444444444444444444447777777777777777777777777" }, { "input": "221020945402270233", "output": "444444444777777777" }, { "input": "241925018843248944336317949908388280315030601139576419352009710", "output": "4444444444444444444444444444444477777777777777777777777777777777" }, { "input": "888999577", "output": "4444477777" }, { "input": "10", "output": "47" }, { "input": "7", "output": "47" }, { "input": "50", "output": "74" }, { "input": "70", "output": "74" }, { "input": "74700", "output": "444777" }, { "input": "1024", "output": "4477" }, { "input": "73", "output": "74" }, { "input": "74710000", "output": "74744477" }, { "input": "444000000", "output": "4444477777" }, { "input": "4", "output": "47" }, { "input": "1", "output": "47" }, { "input": "9", "output": "47" }, { "input": "99", "output": "4477" }, { "input": "48", "output": "74" }, { "input": "4747474749", "output": "4747474774" }, { "input": "4747474774", "output": "4747474774" }, { "input": "77777777", "output": "4444477777" }, { "input": "4777", "output": "7447" }, { "input": "7748", "output": "444777" }, { "input": "7773", "output": "444777" }, { "input": "19", "output": "47" }, { "input": "447777", "output": "474477" } ]
1,653,991,102
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
512,000
import math def main_function(): n = [int(u) for u in list(input())] if len(n) % 2 == 1: listy = ["4" for i in range(len(n) // 2 + 1)] + ["7" for i in range(len(n) // 2 + 1)] else: is_higher = False finish_as_min = False found_lower_than_7 = False half_len_n = len(n) // 2 listy = [] counter_7 = half_len_n counter_4 = half_len_n for ind in range(len(n)): if not found_lower_than_7: if n[ind] >= 7: if counter_7 <= 0: is_higher = True break else: if n[ind] > 7: is_higher = True break else: listy.append("7") counter_7 -= 1 elif n[ind] > 4: found_lower_than_7 = True if counter_7 > 0: listy.append("7") counter_7 -= 1 finish_as_min = True break else: is_higher = True break elif n[ind] == 4: found_lower_than_7 = True if counter_7 == 1: counter_7 -= 1 listy.append("7") finish_as_min = True break else: counter_4 -= 1 listy.append("4") else: found_lower_than_7 = True counter_4 -= 1 listy.append("4") finish_as_min = True break else: if n[ind] > 7: while listy[-1] != "4" or counter_7 <= 0: if listy[-1] == "7": counter_7 += 1 else: counter_4 += 1 listy.pop() else: listy.append("7") counter_7 -= 1 finish_as_min = True break elif n[ind] == 7: if counter_7 == 0: while listy[-1] != "4" or counter_7 <= 0: if listy[-1] == "7": counter_7 += 1 else: counter_4 += 1 listy.pop() else: listy.append("7") counter_7 -= 1 finish_as_min = True break else: listy.append("7") counter_7 -= 1 elif n[ind] < 4: if counter_4 > 0: listy.append("4") counter_4 -= 1 finish_as_min = True break else: counter_7 -= 1 listy.append("7") counter_7 -= 1 finish_as_min = True break elif n[ind] == 4: if counter_4 > 0: counter_4 -= 1 listy.append("4") else: counter_7 -= 1 listy.append("7") finish_as_min = True break else: if counter_7 > 0: listy.append("7") counter_7 -= 1 finish_as_min = True break else: while listy[-1] != "4" or counter_7 <= 0: if listy[-1] == "7": counter_7 += 1 else: counter_4 += 1 listy.pop() else: listy.append("7") counter_7 -= 1 finish_as_min = True break if is_higher: listy = ["4" for i in range(len(n) // 2 + 1)] + ["7" for i in range(len(n) // 2 + 1)] else: for i in range(counter_4): listy.append("4") for i in range(counter_7): listy.append("7") print("".join(listy)) main_function()
Title: Lucky Numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer *n*. Help him to find the least super lucky number which is not less than *n*. Input Specification: The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=10100000). This number doesn't have leading zeroes. Output Specification: Output the least super lucky number that is more than or equal to *n*. Demo Input: ['4500\n', '47\n'] Demo Output: ['4747\n', '47\n'] Note: none
```python import math def main_function(): n = [int(u) for u in list(input())] if len(n) % 2 == 1: listy = ["4" for i in range(len(n) // 2 + 1)] + ["7" for i in range(len(n) // 2 + 1)] else: is_higher = False finish_as_min = False found_lower_than_7 = False half_len_n = len(n) // 2 listy = [] counter_7 = half_len_n counter_4 = half_len_n for ind in range(len(n)): if not found_lower_than_7: if n[ind] >= 7: if counter_7 <= 0: is_higher = True break else: if n[ind] > 7: is_higher = True break else: listy.append("7") counter_7 -= 1 elif n[ind] > 4: found_lower_than_7 = True if counter_7 > 0: listy.append("7") counter_7 -= 1 finish_as_min = True break else: is_higher = True break elif n[ind] == 4: found_lower_than_7 = True if counter_7 == 1: counter_7 -= 1 listy.append("7") finish_as_min = True break else: counter_4 -= 1 listy.append("4") else: found_lower_than_7 = True counter_4 -= 1 listy.append("4") finish_as_min = True break else: if n[ind] > 7: while listy[-1] != "4" or counter_7 <= 0: if listy[-1] == "7": counter_7 += 1 else: counter_4 += 1 listy.pop() else: listy.append("7") counter_7 -= 1 finish_as_min = True break elif n[ind] == 7: if counter_7 == 0: while listy[-1] != "4" or counter_7 <= 0: if listy[-1] == "7": counter_7 += 1 else: counter_4 += 1 listy.pop() else: listy.append("7") counter_7 -= 1 finish_as_min = True break else: listy.append("7") counter_7 -= 1 elif n[ind] < 4: if counter_4 > 0: listy.append("4") counter_4 -= 1 finish_as_min = True break else: counter_7 -= 1 listy.append("7") counter_7 -= 1 finish_as_min = True break elif n[ind] == 4: if counter_4 > 0: counter_4 -= 1 listy.append("4") else: counter_7 -= 1 listy.append("7") finish_as_min = True break else: if counter_7 > 0: listy.append("7") counter_7 -= 1 finish_as_min = True break else: while listy[-1] != "4" or counter_7 <= 0: if listy[-1] == "7": counter_7 += 1 else: counter_4 += 1 listy.pop() else: listy.append("7") counter_7 -= 1 finish_as_min = True break if is_higher: listy = ["4" for i in range(len(n) // 2 + 1)] + ["7" for i in range(len(n) // 2 + 1)] else: for i in range(counter_4): listy.append("4") for i in range(counter_7): listy.append("7") print("".join(listy)) main_function() ```
0
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output": "4419" }, { "input": "bear", "output": "1" }, { "input": "a", "output": "0" }, { "input": "be", "output": "0" } ]
1,390,578,597
896
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
7
1,000
307,200
s = input() ans = 0 for i in range(len(s)): for j in range(1, len(s)+1): if 'bear' in s[i:j]: ans += len(s)-j+1 break print(ans)
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem. Input Specification: The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. Output Specification: Print a single number — the answer to the problem. Demo Input: ['bearbtear\n', 'bearaabearc\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
```python s = input() ans = 0 for i in range(len(s)): for j in range(1, len(s)+1): if 'bear' in s[i:j]: ans += len(s)-j+1 break print(ans) ```
0
0
none
none
none
0
[ "none" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
0
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { "input": "353 313 327 470 597 31", "output": "NO" }, { "input": "835 638 673 624 232 266", "output": "NO" }, { "input": "936 342 19 398 247 874", "output": "NO" }, { "input": "417 666 978 553 271 488", "output": "NO" }, { "input": "71 66 124 199 67 147", "output": "YES" }, { "input": "54 26 0 171 239 12", "output": "YES" }, { "input": "72 8 186 92 267 69", "output": "YES" }, { "input": "180 179 188 50 75 214", "output": "YES" }, { "input": "16 169 110 136 404 277", "output": "YES" }, { "input": "101 400 9 200 300 10", "output": "YES" }, { "input": "101 400 200 9 300 10", "output": "YES" }, { "input": "101 200 400 9 300 10", "output": "YES" }, { "input": "101 400 200 300 9 10", "output": "YES" }, { "input": "101 200 400 300 9 10", "output": "YES" }, { "input": "4 4 4 4 5 4", "output": "NO" }, { "input": "2 2 2 2 2 1", "output": "NO" }, { "input": "1000 1000 999 1000 1000 1000", "output": "NO" }, { "input": "129 1 10 29 8 111", "output": "NO" }, { "input": "1000 1000 1000 999 999 1000", "output": "YES" }, { "input": "101 200 300 400 9 10", "output": "YES" }, { "input": "101 400 200 300 10 9", "output": "YES" }, { "input": "101 200 400 300 10 9", "output": "YES" }, { "input": "101 200 300 400 10 9", "output": "YES" }, { "input": "101 200 300 10 400 9", "output": "YES" }, { "input": "1 1 1 1 1 5", "output": "NO" }, { "input": "8 1 1 3 3 0", "output": "NO" }, { "input": "1 1 2 2 3 3", "output": "YES" }, { "input": "1 2 2 5 2 5", "output": "NO" }, { "input": "1 2 3 6 6 6", "output": "NO" }, { "input": "36 91 7 86 51 89", "output": "NO" }, { "input": "10 1 1 1 23 24", "output": "NO" }, { "input": "1 1 1 10 23 24", "output": "NO" }, { "input": "20 10 1 2 3 44", "output": "NO" }, { "input": "7 0 14 11 8 6", "output": "NO" }, { "input": "100 496 1 1 1 1", "output": "NO" }, { "input": "5 4 2 5 11 3", "output": "NO" }, { "input": "1 3 7 8 8 9", "output": "YES" }, { "input": "1 3 4 5 18 19", "output": "YES" }, { "input": "5 5 1 2 2 15", "output": "NO" }, { "input": "2 1 0 0 0 5", "output": "NO" }, { "input": "1 6 6 1 20 2", "output": "NO" }, { "input": "2 10 0 0 0 0", "output": "NO" }, { "input": "1 1 3 1 1 11", "output": "NO" }, { "input": "10 10 1 1 1 37", "output": "NO" }, { "input": "1 1 0 0 0 4", "output": "NO" }, { "input": "1 1 10 1 1 28", "output": "NO" }, { "input": "1 5 5 5 6 8", "output": "YES" }, { "input": "0 2 3 4 4 5", "output": "YES" } ]
1,564,244,163
2,147,483,647
PyPy 3
OK
TESTS
53
218
14,848,000
class CodeforcesTask890ASolution: def __init__(self): self.result = '' self.scores = [] def read_input(self): self.scores = [int(x) for x in input().split(" ")] def process_task(self): result = False perms = [([5,2,1],[0,4,3]), ([1,3,0],[5,4,2]), ([4,1,2],[3,0,5]), ([2,3,0],[4,1,5]), ([4,5,3],[1,2,0]), ([3,4,1],[5,0,2]), ([3,5,2],[1,4,0]), ([0,4,2],[5,1,3]), ([3,0,1],[4,2,5]), ([4,3,5],[2,0,1]), ([4,0,3],[1,2,5]), ([1,2,5],[3,0,4]), ([3,5,1],[0,4,2]), ([3,2,4],[0,1,5]), ([2,5,1],[0,3,4]), ([2,3,4],[1,0,5]), ([0,1,5],[3,2,4]), ([5,4,1],[0,2,3]), ([5,2,3],[0,1,4]), ([4,1,0],[3,2,5]), ([4,1,0],[5,2,3]), ([2,3,1],[4,0,5]), ([4,0,1],[2,3,5]), ([2,4,5],[3,1,0]), ([1,5,0],[3,2,4]), ([3,0,1],[4,5,2]), ([2,0,3],[1,4,5]), ([0,3,1],[2,5,4]), ([5,2,3],[1,4,0]), ([1,0,4],[3,2,5]), ([0,2,3],[4,5,1]), ([0,3,1],[2,4,5]), ([4,1,0],[3,5,2]), ([5,1,2],[3,0,4]), ([1,4,2],[0,3,5]), ([5,3,4],[0,2,1]), ([5,3,2],[0,1,4]), ([2,5,3],[1,4,0]), ([5,2,4],[0,3,1]), ([5,1,3],[0,4,2]), ([5,1,4],[3,2,0]), ([4,1,0],[2,3,5]), ([3,4,5],[2,1,0]), ([5,1,0],[4,3,2]), ([1,0,4],[3,2,5]), ([5,3,1],[4,0,2]), ([3,0,4],[5,2,1]), ([0,3,2],[4,1,5]), ([0,4,1],[2,3,5]), ([5,4,0],[2,3,1]), ([1,5,0],[4,3,2]), ([1,2,3],[0,5,4]), ([4,5,0],[3,2,1]), ([0,2,5],[1,3,4]), ([1,0,4],[5,3,2]), ([4,0,3],[2,1,5]), ([2,5,4],[0,1,3]), ([5,0,2],[1,4,3]), ([4,2,5],[0,3,1]), ([2,5,1],[4,3,0]), ([1,3,4],[0,2,5]), ([4,1,2],[0,3,5]), ([5,3,1],[2,0,4]), ([3,4,1],[2,5,0]), ([4,5,2],[3,0,1]), ([4,3,1],[2,5,0]), ([5,2,4],[0,1,3]), ([5,2,3],[0,1,4]), ([2,3,1],[5,0,4]), ([2,4,3],[1,0,5]), ([0,2,3],[1,4,5]), ([1,3,5],[4,0,2]), ([3,2,4],[5,0,1]), ([0,3,2],[4,1,5]), ([3,1,0],[2,4,5]), ([5,4,2],[3,0,1]), ([2,0,1],[5,3,4]), ([5,3,4],[0,2,1]), ([1,3,0],[2,4,5]), ([0,4,3],[5,2,1]), ([5,0,4],[2,1,3]), ([4,2,3],[1,0,5]), ([5,0,2],[1,3,4]), ([0,4,5],[3,1,2]), ([4,3,1],[2,5,0]), ([1,5,3],[4,2,0]), ([3,2,5],[0,4,1]), ([3,2,0],[4,1,5]), ([5,3,0],[2,4,1]), ([4,1,5],[2,3,0]), ([5,2,0],[3,4,1]), ([0,4,1],[3,2,5]), ([1,0,5],[4,2,3]), ([2,1,0],[4,3,5]), ([1,0,5],[3,2,4]), ([2,4,0],[5,3,1]), ([4,2,5],[0,1,3]), ([4,1,5],[0,2,3]), ([5,1,0],[2,4,3]), ([1,3,4],[2,5,0]), ([5,1,4],[0,2,3]), ([4,0,2],[5,3,1]), ([5,1,0],[3,4,2]), ([0,1,5],[2,4,3]), ([1,2,4],[5,3,0]), ([3,2,1],[4,0,5]), ([0,1,4],[3,5,2]), ([2,3,4],[5,0,1]), ([5,4,1],[2,0,3]), ([3,4,1],[2,0,5]), ([1,0,5],[3,4,2]), ([5,3,0],[4,1,2]), ([5,0,4],[2,3,1]), ([0,2,1],[3,4,5]), ([1,2,4],[0,3,5]), ([1,5,4],[2,0,3]), ([1,5,3],[4,2,0]), ([0,3,5],[1,2,4]), ([3,2,0],[5,4,1]), ([0,3,4],[1,5,2]), ([2,1,5],[3,4,0]), ([4,1,5],[0,3,2]), ([1,0,3],[5,2,4]), ([3,1,5],[2,4,0]), ([2,4,0],[3,5,1]), ([2,3,5],[0,1,4]), ([2,0,5],[1,3,4]), ([0,2,1],[3,5,4]), ([4,2,3],[1,5,0]), ([1,2,3],[4,5,0]), ([2,1,5],[0,3,4]), ([3,1,5],[2,0,4]), ([1,5,0],[4,3,2]), ([2,1,3],[0,5,4]), ([3,4,5],[2,1,0]), ([4,3,0],[1,5,2]), ([5,3,1],[0,4,2]), ([4,2,1],[0,5,3]), ([4,1,0],[2,5,3]), ([2,3,4],[1,0,5]), ([4,2,0],[5,1,3]), ([0,4,5],[1,3,2]), ([5,4,0],[3,2,1]), ([0,3,4],[1,2,5]), ([5,4,1],[2,3,0]), ([5,0,4],[3,2,1]), ([4,1,5],[2,0,3]), ([2,1,4],[3,5,0]), ([5,4,3],[2,0,1]), ([0,2,5],[4,1,3]), ([1,5,2],[3,4,0]), ([2,3,1],[4,0,5]), ([5,4,1],[0,2,3]), ([0,2,4],[5,1,3]), ([0,1,2],[5,3,4]), ([5,2,0],[3,4,1]), ([0,3,4],[1,5,2]), ([3,5,1],[4,0,2]), ([3,1,2],[0,5,4]), ([0,5,3],[1,4,2]), ([5,4,2],[0,1,3]), ([5,1,0],[4,3,2]), ([3,1,4],[5,2,0]), ([2,1,5],[3,4,0]), ([2,3,1],[0,4,5]), ([3,2,1],[0,4,5]), ([2,5,4],[0,1,3]), ([2,1,5],[0,4,3]), ([2,3,1],[5,4,0]), ([3,2,4],[5,0,1]), ([4,2,5],[3,1,0]), ([2,0,3],[1,5,4]), ([2,1,0],[4,5,3]), ([2,4,0],[1,3,5]), ([4,5,3],[0,2,1]), ([5,1,2],[4,3,0]), ([1,0,2],[5,3,4]), ([4,3,2],[5,0,1]), ([4,3,5],[1,2,0]), ([1,5,4],[3,0,2]), ([1,4,2],[5,0,3]), ([2,3,5],[4,0,1]), ([4,0,1],[3,2,5]), ([1,4,0],[3,5,2]), ([3,2,1],[4,5,0]), ([1,2,4],[0,5,3]), ([3,2,1],[5,0,4]), ([0,4,5],[1,3,2]), ([1,3,2],[5,0,4]), ([5,4,3],[1,2,0]), ([3,5,4],[2,1,0]), ([4,3,0],[1,5,2]), ([0,1,5],[2,3,4]), ([5,4,2],[1,3,0]), ([4,2,1],[0,3,5]), ([5,3,1],[4,0,2]), ([5,2,3],[1,0,4]), ([2,0,4],[5,3,1]), ([2,3,1],[0,4,5]), ([5,0,2],[4,3,1]), ([0,1,4],[5,2,3]), ([5,3,1],[2,0,4]), ([1,5,3],[4,2,0]), ([3,4,1],[2,0,5]), ([0,3,2],[5,4,1]), ([5,0,1],[2,3,4]), ([1,2,4],[0,3,5]), ([1,5,2],[4,3,0]), ([3,5,0],[4,2,1]), ([4,0,2],[3,5,1]), ([1,4,5],[0,3,2]), ([1,0,2],[4,3,5]), ([5,0,1],[4,3,2]), ([2,0,5],[4,1,3]), ([4,3,5],[0,2,1]), ([4,5,0],[2,1,3]), ([2,5,1],[4,3,0]), ([0,3,5],[1,4,2]), ([0,2,1],[5,3,4]), ([2,5,3],[0,1,4]), ([2,3,4],[0,1,5]), ([3,0,5],[2,4,1]), ([0,1,2],[4,3,5]), ([3,0,2],[1,5,4]), ([1,3,0],[4,2,5]), ([5,3,2],[0,1,4]), ([0,1,5],[2,3,4]), ([0,1,3],[2,4,5]), ([4,5,2],[0,1,3]), ([0,2,5],[4,3,1]), ([3,5,2],[0,4,1]), ([5,0,1],[2,3,4]), ([5,1,0],[3,4,2]), ([0,1,2],[3,5,4]), ([1,5,0],[3,2,4]), ([1,0,4],[3,5,2]), ([3,4,0],[1,5,2]), ([5,0,3],[2,4,1]), ([2,4,0],[1,5,3]), ([3,5,2],[0,1,4]), ([3,0,5],[4,2,1]), ([5,1,0],[4,2,3]), ([5,2,4],[3,0,1]), ([4,2,1],[5,0,3]), ([0,3,5],[4,2,1]), ([2,3,0],[4,5,1]), ([0,4,3],[1,2,5]), ([2,5,1],[4,3,0]), ([5,1,2],[3,0,4]), ([3,2,1],[4,0,5]), ([2,0,4],[5,3,1]), ([0,4,3],[2,5,1]), ([4,0,1],[5,2,3]), ([0,5,2],[4,1,3]), ([3,4,2],[5,1,0]), ([4,1,0],[2,5,3]), ([4,3,0],[2,1,5]), ([5,4,3],[0,1,2]), ([2,0,3],[4,1,5]), ([5,3,4],[2,0,1]), ([5,1,3],[2,0,4]), ([5,0,1],[4,3,2]), ([3,5,4],[0,1,2]), ([5,3,4],[1,2,0]), ([2,5,4],[1,0,3]), ([3,5,4],[0,1,2]), ([5,3,0],[1,4,2]), ([5,2,0],[1,3,4]), ([2,3,4],[0,5,1]), ([0,4,3],[2,5,1]), ([4,5,1],[3,2,0]), ([4,3,2],[1,0,5]), ([4,1,2],[5,0,3]), ([0,4,5],[1,3,2]), ([5,0,3],[4,2,1]), ([1,2,3],[5,4,0]), ([3,4,2],[1,0,5]), ([3,0,5],[4,1,2]), ([0,4,3],[2,5,1]), ([2,3,5],[1,4,0]), ([2,1,0],[5,3,4]), ([5,4,2],[1,3,0]), ([4,2,1],[0,5,3]), ([1,5,2],[4,0,3]), ([0,5,1],[2,3,4]), ([0,1,5],[4,3,2]), ([2,3,5],[4,0,1]), ([3,5,0],[1,2,4]), ([3,1,2],[4,0,5]), ([2,4,0],[5,1,3]), ([1,2,4],[5,0,3]), ([4,0,3],[5,2,1]), ([4,2,5],[0,1,3]), ([3,0,1],[4,5,2]), ([3,0,5],[2,4,1]), ([4,0,1],[3,5,2]), ([2,1,4],[0,3,5]), ([0,4,1],[3,5,2]), ([0,3,4],[2,1,5]), ([5,4,0],[3,1,2]), ([5,4,1],[3,2,0]), ([2,1,0],[4,3,5]), ([2,3,1],[4,5,0]), ([4,3,1],[2,5,0]), ([5,1,4],[2,3,0]), ([4,2,1],[5,0,3]), ([3,5,1],[0,2,4]), ([2,1,4],[3,0,5]), ([0,3,4],[2,5,1]), ([4,5,3],[1,2,0]), ([3,0,5],[2,1,4]), ([3,5,2],[1,0,4]), ([0,5,2],[1,3,4]), ([5,1,3],[4,0,2]), ([4,5,1],[3,0,2]), ([1,0,3],[5,2,4]), ([2,4,5],[1,3,0]), ([3,5,4],[2,0,1]), ([2,1,4],[5,0,3]), ([2,3,4],[1,5,0]), ([1,0,2],[5,3,4]), ([4,3,1],[2,0,5]), ([0,1,2],[5,4,3]), ([3,2,5],[4,0,1]), ([4,5,3],[1,0,2]), ([0,1,2],[3,4,5]), ([4,1,0],[3,2,5]), ([1,4,3],[2,0,5]), ([3,5,0],[2,1,4]), ([3,1,2],[0,5,4]), ([1,2,0],[5,4,3]), ([2,4,0],[1,3,5]), ([1,4,3],[0,2,5]), ([1,4,2],[5,0,3]), ([0,5,1],[4,2,3]), ([1,0,4],[2,5,3]), ([5,1,2],[3,4,0]), ([4,3,5],[0,2,1]), ([2,4,5],[0,1,3]), ([4,0,2],[5,1,3]), ([0,2,1],[4,3,5]), ([2,1,4],[3,0,5]), ([2,3,0],[5,4,1]), ([4,0,2],[1,3,5]), ([2,0,5],[3,1,4]), ([0,3,2],[4,1,5]), ([0,4,3],[2,1,5]), ([3,1,2],[5,0,4]), ([4,1,0],[5,2,3]), ([1,4,2],[5,0,3]), ([3,2,5],[4,1,0]), ([0,3,5],[4,1,2]), ([5,3,2],[1,4,0]), ([5,2,4],[3,0,1]), ([3,0,4],[2,1,5]), ([2,3,1],[5,0,4]), ([0,3,4],[2,1,5]), ([0,2,4],[3,5,1]), ([5,2,1],[0,4,3]), ([5,4,0],[1,2,3]), ([1,2,0],[5,4,3]), ([1,2,4],[3,5,0]), ([1,5,2],[4,3,0]), ([2,3,1],[5,0,4]), ([1,0,5],[3,4,2]), ([5,3,4],[2,0,1]), ([0,5,2],[3,4,1]), ([1,3,4],[5,2,0]), ([4,2,0],[1,5,3]), ([4,2,3],[5,0,1]), ([0,3,1],[2,5,4]), ([0,5,4],[3,1,2]), ([4,2,3],[1,5,0]), ([1,0,5],[3,2,4]), ([3,4,1],[2,0,5]), ([1,2,5],[0,3,4]), ([0,1,3],[2,4,5]), ([1,5,4],[2,3,0]), ([1,3,2],[0,5,4]), ([5,2,3],[0,1,4]), ([5,0,4],[1,3,2]), ([0,2,4],[1,3,5]), ([2,4,3],[1,0,5]), ([3,0,4],[2,1,5]), ([4,0,2],[3,5,1]), ([3,1,2],[5,4,0]), ([5,4,1],[0,3,2]), ([5,0,4],[1,3,2]), ([4,0,2],[1,5,3]), ([5,0,3],[2,1,4]), ([2,3,4],[1,5,0]), ([5,0,2],[4,3,1]), ([4,0,3],[2,5,1]), ([4,2,1],[0,3,5]), ([4,1,0],[5,2,3]), ([2,3,5],[4,1,0]), ([5,0,2],[4,3,1]), ([4,1,0],[3,5,2]), ([4,0,3],[1,5,2]), ([0,2,3],[5,4,1]), ([3,5,2],[0,4,1]), ([1,3,4],[0,5,2]), ([3,2,1],[4,0,5]), ([3,4,5],[0,1,2]), ([1,5,4],[0,3,2]), ([0,4,5],[3,2,1]), ([5,4,2],[0,3,1]), ([2,0,3],[4,1,5]), ([2,5,1],[4,0,3]), ([3,5,0],[4,2,1]), ([0,1,3],[4,5,2]), ([0,2,4],[5,3,1]), ([3,1,5],[4,2,0]), ([3,1,0],[2,5,4]), ([5,4,2],[1,0,3]), ([5,2,0],[3,1,4]), ([0,4,1],[5,3,2]), ([5,3,4],[2,0,1]), ([0,5,2],[4,3,1]), ([2,4,1],[5,0,3]), ([4,2,5],[3,0,1]), ([1,3,0],[4,2,5]), ([1,2,3],[4,0,5]), ([5,1,2],[0,4,3]), ([3,1,0],[2,4,5]), ([1,0,3],[4,2,5]), ([3,1,2],[5,4,0]), ([0,5,1],[3,2,4]), ([4,0,5],[1,2,3]), ([0,2,1],[3,5,4]), ([4,0,2],[3,1,5]), ([0,2,4],[3,1,5]), ([3,4,5],[0,1,2]), ([2,1,4],[0,5,3]), ([5,1,4],[2,3,0]), ([4,2,5],[1,3,0]), ([5,0,2],[1,4,3]), ([1,3,5],[0,4,2]), ([2,5,3],[1,0,4]), ([3,1,2],[5,0,4]), ([3,1,5],[0,4,2]), ([3,1,5],[2,0,4]), ([0,1,4],[5,3,2]), ([4,5,2],[0,1,3]), ([0,4,2],[3,1,5]), ([2,5,0],[4,3,1]), ([2,3,0],[4,5,1]), ([0,5,2],[4,1,3]), ([2,3,4],[0,5,1]), ([0,3,5],[4,1,2]), ([4,5,3],[2,1,0]), ([3,1,4],[0,2,5]), ([0,1,4],[3,2,5]), ([5,3,4],[0,1,2]), ([0,4,5],[2,3,1]), ([0,3,4],[2,1,5]), ([1,4,5],[2,0,3]), ([2,4,0],[3,1,5]), ([0,5,2],[4,3,1]), ([5,0,1],[4,2,3]), ([5,3,4],[1,0,2]), ([0,2,5],[1,4,3]), ([2,1,3],[4,0,5]), ([5,1,3],[2,4,0]), ([4,3,0],[1,2,5]), ([3,0,5],[2,1,4]), ([4,0,3],[5,1,2]), ([4,1,0],[3,2,5]), ([1,4,5],[3,0,2]), ([3,5,1],[0,2,4]), ([3,2,5],[0,1,4]), ([4,2,1],[0,3,5]), ([1,2,4],[5,3,0]), ([2,4,0],[5,3,1]), ([0,3,1],[4,2,5]), ([0,4,2],[5,1,3]), ([3,5,1],[2,4,0]), ([3,1,5],[2,4,0]), ([2,5,3],[1,4,0]), ([2,4,0],[5,3,1]), ([3,2,0],[4,5,1]), ([4,2,3],[1,5,0]), ([5,0,4],[3,1,2]), ([5,4,1],[2,3,0]), ([0,5,4],[2,3,1]), ([3,5,1],[4,0,2]), ([3,5,1],[0,2,4]), ([1,2,0],[3,5,4]), ([3,0,2],[4,5,1]), ([3,4,1],[0,5,2]), ([0,3,4],[2,5,1]), ([5,1,4],[0,3,2]), ([2,4,5],[3,1,0]), ([0,5,4],[3,2,1]), ([4,2,5],[1,0,3]), ([0,2,5],[3,4,1]), ([2,1,0],[3,5,4]), ([4,1,0],[3,5,2]), ([1,0,5],[4,3,2]), ([2,4,3],[1,5,0]), ([5,2,0],[4,1,3]), ([3,5,0],[4,2,1]), ([3,0,2],[4,1,5]), ([3,5,0],[4,2,1]), ([2,4,3],[0,1,5]), ([1,4,2],[3,0,5]), ([3,4,5],[1,0,2]), ([0,5,1],[3,4,2]), ([5,2,1],[0,3,4]), ([0,2,5],[4,3,1]), ([1,2,0],[3,4,5]), ([0,2,4],[1,5,3]), ([4,5,2],[3,1,0]), ([5,3,2],[0,1,4]), ([2,3,0],[4,5,1]), ([4,1,0],[2,5,3]), ([5,4,0],[1,2,3]), ([2,5,3],[1,4,0]), ([3,0,2],[5,1,4]), ([1,2,5],[4,3,0]), ([5,4,1],[3,2,0]), ([2,0,5],[1,4,3]), ([3,2,0],[4,1,5]), ([5,3,2],[4,0,1]), ([0,2,5],[1,3,4]), ([0,3,5],[4,1,2]), ([5,1,0],[4,2,3]), ([2,5,3],[4,0,1]), ([5,2,4],[1,3,0]), ([5,4,0],[3,1,2]), ([0,5,3],[4,1,2]), ([4,5,3],[1,0,2]), ([2,0,3],[5,4,1]), ([1,0,5],[2,3,4]), ([2,3,0],[1,5,4]), ([1,2,4],[5,0,3]), ([4,0,1],[3,5,2]), ([4,2,0],[5,3,1]), ([4,1,3],[2,0,5]), ([1,3,2],[4,5,0]), ([1,5,0],[4,2,3]), ([5,4,2],[0,3,1]), ([2,1,0],[5,4,3]), ([4,0,3],[1,2,5]), ([5,0,4],[2,3,1]), ([4,3,1],[5,2,0]), ([4,3,5],[1,0,2]), ([5,3,0],[4,1,2]), ([2,3,0],[5,1,4]), ([0,5,3],[1,2,4]), ([0,2,1],[5,4,3]), ([4,1,2],[5,0,3]), ([2,4,0],[1,3,5]), ([3,5,1],[2,0,4]), ([5,4,2],[0,1,3]), ([2,5,3],[0,1,4]), ([0,5,2],[1,3,4]), ([4,1,2],[0,3,5]), ([1,5,3],[2,4,0]), ([3,5,1],[4,2,0]), ([5,2,4],[0,1,3]), ([4,1,5],[0,3,2]), ([2,4,0],[1,3,5]), ([3,5,2],[0,4,1]), ([2,3,4],[5,1,0]), ([1,0,4],[3,5,2]), ([3,1,5],[4,2,0]), ([2,4,1],[3,0,5]), ([0,4,1],[3,2,5]), ([0,4,1],[2,3,5]), ([5,0,4],[3,1,2]), ([2,1,3],[4,5,0]), ([4,1,0],[2,3,5]), ([0,2,5],[3,4,1]), ([3,0,4],[1,5,2]), ([5,1,2],[4,0,3]), ([5,0,1],[3,2,4]), ([5,2,4],[3,0,1]), ([1,4,5],[3,0,2]), ([4,3,5],[2,0,1]), ([5,1,4],[3,2,0]), ([2,5,0],[4,3,1]), ([4,5,1],[0,2,3]), ([4,1,0],[2,5,3]), ([2,5,0],[3,1,4]), ([4,5,0],[1,3,2]), ([1,2,5],[4,3,0]), ([2,3,5],[4,1,0]), ([1,4,5],[0,2,3]), ([1,4,2],[3,5,0]), ([5,1,2],[3,0,4]), ([0,5,2],[1,3,4]), ([0,1,5],[2,4,3]), ([4,3,5],[2,1,0]), ([5,4,2],[1,3,0]), ([0,1,4],[2,3,5]), ([3,5,2],[0,1,4]), ([1,3,4],[5,2,0]), ([0,1,2],[3,5,4]), ([3,1,4],[5,2,0]), ([4,5,3],[0,2,1]), ([4,0,1],[5,2,3]), ([0,3,4],[5,2,1]), ([4,3,5],[1,0,2]), ([4,0,1],[2,3,5]), ([0,5,1],[2,3,4]), ([1,2,3],[0,4,5]), ([3,2,1],[5,4,0]), ([5,2,1],[4,3,0]), ([2,0,1],[3,4,5]), ([5,3,0],[1,2,4]), ([2,1,4],[0,3,5]), ([1,5,3],[2,4,0]), ([2,3,0],[4,5,1]), ([4,3,5],[0,1,2]), ([5,3,1],[0,2,4]), ([2,5,0],[3,1,4]), ([5,4,1],[2,3,0]), ([1,4,5],[2,3,0]), ([0,5,3],[1,4,2]), ([3,4,5],[2,1,0]), ([4,5,2],[1,0,3]), ([2,0,1],[4,3,5]), ([2,1,3],[0,5,4]), ([2,5,0],[4,3,1]), ([1,4,2],[0,3,5]), ([0,2,5],[3,4,1]), ([2,5,1],[3,4,0]), ([4,2,5],[1,0,3]), ([0,3,5],[2,4,1]), ([2,0,3],[1,4,5]), ([2,1,0],[4,5,3]), ([5,4,1],[3,0,2]), ([2,3,5],[0,4,1]), ([0,4,5],[1,3,2]), ([0,4,2],[1,5,3]), ([3,4,0],[1,5,2]), ([3,4,0],[5,2,1]), ([3,0,1],[4,5,2]), ([5,1,4],[2,3,0]), ([5,0,1],[4,2,3]), ([1,4,3],[2,5,0]), ([0,5,1],[4,3,2]), ([2,4,0],[5,3,1]), ([2,1,5],[4,0,3]), ([5,1,4],[3,2,0]), ([2,5,0],[4,3,1]), ([5,0,1],[3,4,2]), ([2,5,3],[0,1,4]), ([3,5,0],[2,4,1]), ([1,2,0],[4,3,5]), ([4,1,0],[2,5,3]), ([2,0,3],[5,4,1]), ([0,3,1],[5,2,4]), ([5,3,2],[0,1,4]), ([0,4,1],[3,2,5]), ([5,0,3],[2,4,1]), ([0,1,4],[2,3,5]), ([4,5,2],[3,1,0]), ([3,4,1],[2,5,0]), ([3,5,2],[0,1,4]), ([3,0,4],[5,2,1]), ([1,0,4],[3,5,2]), ([0,3,2],[5,4,1]), ([1,5,2],[3,4,0]), ([1,0,2],[3,4,5]), ([3,0,4],[5,1,2]), ([2,0,3],[5,1,4]), ([4,3,5],[0,1,2]), ([1,5,4],[3,0,2]), ([0,2,4],[3,5,1]), ([0,1,4],[3,5,2]), ([5,3,0],[1,4,2]), ([2,3,5],[1,4,0]), ([3,5,4],[1,0,2]), ([0,1,5],[2,3,4]), ([1,0,4],[3,2,5]), ([0,5,1],[3,4,2]), ([5,2,3],[4,1,0]), ([5,0,2],[1,3,4]), ([0,4,2],[3,5,1]), ([3,1,5],[0,2,4]), ([4,5,3],[2,1,0]), ([3,4,2],[0,1,5]), ([3,1,0],[2,4,5]), ([4,1,2],[3,0,5]), ([5,1,2],[0,4,3]), ([5,1,0],[3,4,2]), ([3,0,4],[1,2,5]), ([0,5,4],[1,2,3]), ([2,1,4],[5,0,3]), ([2,1,5],[3,4,0]), ([5,0,4],[3,2,1]), ([1,3,0],[2,5,4]), ([4,3,0],[1,5,2]), ([0,3,2],[5,4,1]), ([4,0,1],[5,2,3]), ([5,4,3],[0,2,1]), ([5,0,1],[3,4,2]), ([0,5,1],[3,2,4]), ([5,3,1],[2,0,4]), ([1,0,3],[5,2,4]), ([3,5,2],[1,0,4]), ([5,2,0],[1,3,4]), ([2,1,4],[3,5,0]), ([0,2,1],[4,3,5]), ([5,2,1],[3,4,0]), ([4,5,3],[1,0,2]), ([0,1,5],[2,4,3]), ([1,3,4],[2,5,0]), ([2,5,1],[4,0,3]), ([1,0,4],[2,3,5]), ([1,3,0],[5,2,4]), ([3,5,1],[0,2,4]), ([2,1,5],[3,4,0]), ([3,1,4],[2,5,0]), ([2,3,0],[5,1,4]), ([1,4,5],[2,0,3]), ([1,2,3],[5,4,0]), ([5,0,2],[3,4,1]), ([1,0,5],[2,3,4]), ([0,1,5],[4,2,3]), ([1,0,3],[5,2,4]), ([1,4,0],[3,2,5]), ([4,1,5],[2,0,3]), ([1,2,0],[4,3,5]), ([0,2,4],[5,3,1]), ([1,2,0],[5,3,4]), ([1,3,4],[5,0,2]), ([4,0,2],[3,5,1]), ([4,2,0],[3,5,1]), ([2,3,5],[0,4,1]), ([1,0,3],[2,4,5]), ([0,3,5],[1,4,2]), ([0,3,5],[2,4,1]), ([4,1,2],[0,5,3]), ([2,4,5],[0,3,1]), ([0,3,4],[1,5,2]), ([2,3,1],[0,5,4]), ([2,0,1],[5,3,4]), ([2,0,1],[5,3,4]), ([2,4,3],[0,5,1]), ([3,4,1],[0,5,2]), ([1,4,5],[0,3,2]), ([4,0,5],[2,1,3]), ([2,4,5],[3,0,1]), ([1,3,2],[4,0,5]), ([0,1,3],[2,4,5]), ([3,2,5],[4,0,1]), ([4,0,5],[2,3,1]), ([1,2,0],[5,4,3]), ([4,2,0],[1,3,5]), ([0,1,3],[2,4,5]), ([0,5,3],[1,4,2]), ([4,2,0],[3,1,5]), ([0,2,4],[1,3,5]), ([0,2,4],[5,1,3]), ([4,2,1],[0,5,3]), ([4,3,2],[1,5,0]), ([1,0,5],[4,2,3]), ([3,0,5],[4,2,1]), ([2,5,1],[4,3,0]), ([4,0,1],[3,2,5]), ([5,3,0],[1,2,4]), ([5,1,3],[2,0,4]), ([2,5,4],[0,3,1]), ([1,5,0],[2,4,3]), ([2,5,4],[3,1,0]), ([1,0,3],[2,4,5]), ([0,3,4],[2,5,1]), ([2,0,3],[1,4,5]), ([4,3,5],[2,0,1]), ([4,3,2],[1,0,5]), ([0,3,4],[1,5,2]), ([2,5,4],[3,0,1]), ([4,2,0],[3,1,5]), ([4,3,2],[5,0,1]), ([3,2,1],[4,5,0]), ([4,2,3],[5,1,0]), ([1,5,2],[3,0,4]), ([1,3,4],[2,0,5]), ([0,4,3],[2,1,5]), ([2,0,3],[4,5,1]), ([4,5,1],[3,2,0]), ([5,0,4],[3,2,1]), ([3,5,2],[4,1,0]), ([2,0,3],[1,5,4]), ([3,5,0],[4,1,2]), ([4,0,5],[1,3,2]), ([3,2,4],[5,1,0]), ([1,0,4],[3,2,5]), ([3,1,5],[0,4,2]), ([3,1,0],[2,5,4]), ([0,5,4],[3,2,1]), ([5,1,3],[2,0,4]), ([3,4,1],[0,2,5]), ([2,5,1],[0,4,3]), ([3,2,5],[0,4,1]), ([2,4,3],[1,5,0]), ([0,4,5],[3,2,1]), ([4,0,2],[1,3,5]), ([2,1,0],[4,3,5]), ([2,3,4],[0,5,1]), ([0,4,5],[1,3,2]), ([0,4,3],[5,1,2]), ([2,1,3],[0,4,5]), ([0,3,5],[1,2,4]), ([3,5,2],[1,4,0]), ([5,2,3],[0,1,4]), ([2,3,1],[0,4,5]), ([1,3,5],[0,2,4]), ([1,5,2],[3,0,4]), ([0,1,4],[2,5,3]), ([1,3,0],[4,5,2]), ([1,4,5],[3,0,2]), ([2,5,4],[0,1,3]), ([3,4,2],[1,0,5]), ([5,2,1],[4,0,3]), ([4,1,2],[5,3,0]), ([1,4,3],[2,5,0]), ([5,1,0],[3,4,2]), ([3,1,4],[2,0,5]), ([3,4,5],[1,0,2]), ([1,4,5],[2,0,3]), ([5,4,3],[0,1,2]), ([3,0,1],[4,2,5]), ([2,1,3],[4,5,0]), ([4,0,2],[3,1,5]), ([2,0,5],[1,4,3]), ([4,3,0],[5,1,2]), ([3,0,5],[2,1,4]), ([1,0,4],[5,2,3]), ([1,4,0],[3,5,2]), ([2,4,1],[5,0,3]), ([5,3,2],[1,4,0]), ([4,1,3],[2,0,5]), ([2,4,0],[5,3,1]), ([3,4,2],[1,0,5]), ([3,2,0],[4,1,5]), ([0,2,5],[3,1,4]), ([3,0,2],[5,1,4]), ([4,3,0],[5,1,2]), ([5,2,1],[3,4,0]), ([5,2,4],[3,1,0]), ([0,3,5],[1,2,4]), ([3,2,0],[4,1,5]), ([0,2,5],[4,1,3]), ([0,4,3],[5,2,1]), ([5,3,0],[1,4,2]), ([4,3,1],[5,0,2]), ([5,0,4],[1,3,2]), ([2,3,0],[4,1,5]), ([3,2,1],[5,4,0]), ([0,2,5],[3,4,1]), ([5,1,2],[3,4,0]), ([0,1,3],[4,5,2]), ([5,0,2],[3,4,1]), ([2,4,3],[1,5,0]), ([0,5,2],[4,3,1]), ([2,3,1],[5,0,4]), ([5,0,3],[4,1,2]), ([3,1,4],[2,0,5]), ([5,0,4],[3,2,1]), ([5,3,1],[0,2,4]), ([2,0,5],[4,3,1]), ([2,5,0],[4,3,1]), ([1,3,0],[5,2,4]), ([1,0,4],[2,3,5]), ([0,1,2],[5,4,3]), ([1,0,4],[3,5,2]), ([3,2,0],[4,5,1]), ([4,3,2],[1,5,0]), ([5,2,4],[1,0,3]), ([5,1,2],[3,4,0]), ([2,5,0],[3,1,4]), ([4,0,1],[3,2,5]), ([3,0,4],[2,1,5]), ([2,1,0],[3,4,5]), ([3,1,5],[2,0,4]), ([1,3,5],[0,2,4]), ([5,1,3],[4,2,0]), ([0,4,3],[1,5,2]), ([1,3,2],[0,4,5]), ([0,4,5],[1,2,3]), ([2,3,5],[4,1,0]), ([4,3,0],[5,1,2]), ([0,5,2],[1,3,4]), ([0,5,2],[4,3,1]), ([2,4,3],[5,0,1]), ([4,0,1],[5,3,2]), ([4,3,0],[2,5,1]), ([3,4,2],[1,0,5]), ([2,5,4],[3,1,0]), ([0,1,2],[4,3,5]), ([5,2,0],[1,4,3]), ([2,0,3],[5,4,1]), ([1,2,0],[5,3,4]), ([3,0,4],[1,2,5]), ([0,1,5],[2,3,4]), ([4,2,0],[3,1,5]), ([2,3,4],[5,0,1]), ([4,2,1],[5,0,3]), ([2,0,3],[1,5,4]), ([1,3,4],[0,2,5]), ([3,1,2],[0,4,5]), ([5,1,4],[2,3,0]), ([5,2,1],[0,3,4]), ([1,4,5],[3,2,0]), ([0,3,2],[4,5,1]), ([3,5,0],[1,4,2]), ([5,4,2],[3,1,0]), ([5,2,1],[4,0,3]), ([3,0,1],[5,2,4]), ([4,2,3],[0,1,5]), ([3,2,1],[4,0,5]), ([0,2,5],[3,4,1]), ([0,5,1],[2,3,4]), ([3,0,2],[5,4,1]), ([4,0,3],[1,2,5]), ([1,2,5],[4,3,0]), ([3,1,5],[4,2,0]), ([3,0,1],[4,5,2]), ([0,2,1],[4,5,3]), ([4,3,5],[2,0,1]), ([5,4,2],[3,1,0]), ([3,4,0],[5,1,2]), ([3,1,5],[2,0,4]), ([5,1,4],[2,0,3]), ([0,1,2],[4,5,3]), ([3,2,1],[0,4,5]), ([1,3,2],[4,5,0]), ([1,4,2],[5,0,3]), ([5,0,1],[2,3,4]), ([1,4,3],[0,5,2]), ([4,2,3],[0,5,1]), ([1,4,5],[0,3,2]), ([4,2,3],[5,0,1]), ([3,4,2],[0,5,1]), ([1,0,2],[4,3,5]), ([4,1,3],[0,2,5]), ([3,0,2],[5,4,1]), ([1,5,0],[3,4,2]), ([5,0,4],[3,1,2]), ([2,4,0],[3,1,5]), ([4,3,1],[2,5,0]), ([3,5,1],[4,0,2]), ([3,4,5],[1,0,2]), ([3,1,2],[5,0,4]), ([5,4,1],[2,0,3]), ([1,3,0],[5,4,2]), ([2,0,1],[4,5,3]), ([0,5,3],[1,4,2]), ([1,5,4],[2,0,3]), ([0,2,5],[4,3,1]), ([3,5,4],[1,2,0]), ([0,3,4],[2,5,1]), ([5,0,4],[3,1,2]), ([2,0,4],[3,1,5]), ([4,2,3],[0,1,5]), ([3,4,0],[2,1,5]), ([3,4,5],[0,1,2]), ([0,3,4],[5,2,1]), ([5,2,3],[4,0,1]), ([4,1,2],[0,5,3]), ([3,4,2],[5,1,0]), ([3,5,0],[4,2,1]), ([4,5,3],[1,2,0]), ([3,4,2],[0,1,5]), ([1,5,0],[4,3,2]), ([0,5,4],[3,2,1]), ([3,2,4],[5,1,0]), ([2,0,1],[5,4,3]), ([4,5,3],[2,1,0]), ([5,0,3],[1,2,4]), ([2,5,1],[4,3,0]), ([2,3,1],[5,0,4]), ([4,3,5],[2,1,0]), ([0,3,1],[5,2,4]), ([0,4,2],[5,3,1]), ([3,4,1],[0,5,2]), ([2,4,0],[3,5,1]), ([2,3,5],[0,4,1]), ([4,5,2],[3,0,1]), ([1,5,0],[4,3,2]), ([4,2,1],[0,5,3]), ([2,0,4],[1,5,3]), ([4,5,1],[3,0,2]), ([3,5,4],[1,2,0]), ([5,2,3],[4,0,1]), ([3,4,0],[5,1,2]), ([4,3,1],[0,2,5]), ([5,2,3],[1,0,4]), ([4,5,1],[3,2,0]), ([5,0,4],[1,2,3]), ([2,4,0],[1,5,3]), ([2,4,5],[3,0,1]), ([1,5,2],[3,4,0]), ([2,3,0],[4,1,5]), ([4,3,2],[1,0,5]), ([0,1,4],[5,3,2]), ([1,4,3],[2,5,0]), ([0,1,4],[5,2,3]), ([4,2,5],[1,3,0]), ([5,4,0],[1,3,2]), ([0,1,2],[4,3,5]), ([4,3,0],[2,5,1]), ([4,5,2],[1,0,3]), ([0,1,3],[2,5,4]), ([5,1,0],[4,3,2]), ([1,5,0],[3,2,4]), ([2,3,1],[0,4,5]), ([4,5,3],[2,0,1]), ([4,1,3],[2,0,5]), ([0,2,4],[1,5,3]), ([4,0,1],[3,2,5]), ([0,3,2],[1,4,5]), ([3,0,5],[1,2,4]), ([5,1,0],[4,3,2]), ([4,2,5],[1,3,0]), ([5,2,0],[4,3,1]), ([3,5,2],[4,0,1]), ([5,4,2],[1,3,0]), ([1,2,5],[4,3,0]), ([4,0,2],[1,5,3]), ([0,2,3],[5,1,4]), ([1,3,0],[5,4,2]), ([1,3,5],[0,2,4]), ([2,1,0],[4,3,5]), ([3,2,5],[1,4,0]), ([4,2,5],[0,1,3]), ([3,0,2],[4,1,5]), ([1,5,4],[2,0,3]), ([3,0,5],[4,1,2]), ([3,4,0],[2,1,5]), ([2,0,5],[3,1,4]), ([4,1,5],[2,3,0]), ([4,3,1],[0,2,5]), ([2,5,0],[3,4,1]), ([3,4,2],[5,0,1]), ([2,0,5],[1,4,3]), ([0,1,2],[4,3,5]), ([5,1,0],[3,2,4]), ([1,4,0],[5,3,2]), ([2,3,4],[1,0,5]), ([2,0,4],[1,3,5]), ([1,3,5],[4,0,2]), ([3,4,0],[5,1,2]), ([5,3,0],[2,1,4]), ([4,0,5],[3,1,2]), ([4,0,5],[1,3,2]), ([3,5,0],[1,4,2]), ([5,0,4],[1,3,2]), ([5,3,2],[4,1,0]), ([1,5,4],[3,2,0]), ([0,5,2],[4,3,1]), ([1,3,2],[4,5,0]), ([3,4,1],[0,2,5]), ([1,2,4],[3,5,0]), ([0,5,2],[4,3,1]), ([2,0,1],[5,3,4]), ([1,5,2],[3,0,4]), ([1,4,0],[2,3,5]), ([1,5,0],[3,4,2]), ([5,1,0],[2,3,4]), ([5,1,2],[4,0,3]), ([1,2,0],[4,3,5]), ([1,5,0],[2,3,4]), ([1,0,2],[4,5,3]), ([1,3,4],[2,5,0]), ([4,3,5],[1,0,2]), ([3,4,1],[0,2,5]), ([3,2,0],[1,5,4]), ([1,5,3],[4,2,0]), ([1,3,0],[2,5,4]), ([1,0,2],[4,5,3]), ([4,0,5],[3,1,2]), ([5,2,1],[3,4,0]), ([4,0,2],[5,1,3]), ([1,2,3],[0,4,5]), ([1,0,4],[3,2,5]), ([5,1,2],[0,4,3]), ([5,4,1],[3,2,0]), ([0,4,2],[5,3,1]), ([3,2,0],[5,4,1]), ([2,4,1],[3,5,0]), ([0,4,5],[2,3,1]), ([0,5,2],[3,1,4]), ([4,2,3],[5,0,1]), ([1,2,0],[5,4,3]), ([3,1,5],[2,0,4]), ([2,1,4],[3,0,5]), ([4,3,1],[5,0,2]), ([3,5,0],[4,1,2]), ([2,3,4],[0,5,1]), ([4,5,2],[1,3,0]), ([2,0,3],[1,4,5]), ([3,0,4],[5,2,1]), ([1,4,5],[0,2,3]), ([1,0,4],[5,2,3]), ([2,0,3],[4,5,1]), ([4,0,2],[5,1,3]), ([2,3,0],[1,4,5]), ([4,0,3],[2,1,5]), ([4,0,3],[2,5,1]), ([5,4,0],[3,2,1]), ([1,4,5],[3,0,2]), ([2,1,0],[3,5,4]), ([0,2,5],[3,1,4]), ([0,4,5],[1,3,2]), ([3,2,5],[4,0,1]), ([1,4,0],[5,2,3]), ([5,1,4],[0,3,2]), ([4,1,0],[3,2,5]), ([4,1,0],[3,2,5]), ([0,4,3],[2,5,1]), ([4,0,5],[2,3,1]), ([0,5,1],[4,3,2]), ([3,2,5],[0,1,4]), ([0,4,1],[5,2,3]), ([0,2,4],[1,3,5]), ([0,1,2],[4,3,5]), ([0,4,1],[2,5,3]), ([3,0,2],[5,1,4]), ([0,1,5],[4,3,2]), ([2,1,3],[0,5,4]), ([2,1,5],[3,4,0]), ([5,4,0],[2,3,1]), ([5,4,1],[3,2,0]), ([3,4,2],[1,0,5]), ([1,2,4],[5,0,3]), ([0,4,1],[2,3,5]), ([2,3,5],[1,4,0]), ([2,0,5],[3,4,1]), ([0,5,2],[3,4,1]), ([4,5,1],[3,2,0]), ([0,3,4],[2,1,5]), ([5,4,3],[0,2,1]), ([1,0,3],[5,4,2]), ([5,3,1],[2,4,0]), ([5,3,1],[2,4,0]), ([5,0,4],[1,2,3]), ([3,1,0],[5,2,4]), ([0,1,5],[4,2,3]), ([0,5,4],[1,2,3]), ([2,5,1],[3,0,4]), ([5,0,2],[1,4,3]), ([0,4,5],[1,3,2]), ([4,1,0],[2,5,3]), ([2,3,5],[0,4,1]), ([3,2,4],[0,1,5]), ([3,5,2],[4,1,0]), ([0,1,5],[4,2,3]), ([3,1,0],[2,4,5]), ([5,0,3],[4,2,1]), ([2,1,5],[3,0,4]), ([1,2,0],[5,4,3]), ([4,1,2],[0,3,5]), ([3,1,0],[2,5,4]), ([4,0,5],[1,2,3]), ([5,4,0],[3,1,2]), ([1,0,5],[2,3,4]), ([1,3,4],[5,0,2]), ([0,4,3],[2,1,5]), ([0,4,2],[5,1,3]), ([3,5,1],[2,0,4]), ([5,0,2],[1,3,4]), ([1,0,4],[2,3,5]), ([2,4,3],[0,5,1]), ([1,0,5],[4,2,3]), ([4,5,0],[1,2,3]), ([4,1,2],[5,3,0]), ([1,2,3],[5,0,4]), ([5,0,3],[4,1,2]), ([2,5,0],[4,3,1]), ([3,5,2],[1,4,0]), ([3,0,2],[1,4,5]), ([3,4,0],[1,5,2]), ([5,1,2],[3,4,0]), ([0,5,3],[2,4,1]), ([1,0,5],[2,3,4]), ([1,5,4],[0,3,2]), ([5,4,0],[1,3,2]), ([0,2,1],[5,3,4]), ([2,0,1],[4,3,5]), ([2,3,1],[0,5,4]), ([5,4,2],[1,0,3]), ([1,5,2],[0,3,4]), ([0,3,2],[4,1,5]), ([4,3,2],[1,5,0]), ([2,3,5],[1,4,0]), ([1,0,2],[3,5,4]), ([1,0,2],[3,5,4]), ([1,2,5],[3,0,4]), ([1,3,4],[2,5,0]), ([3,0,5],[1,4,2]), ([0,5,2],[1,3,4]), ([0,1,3],[4,5,2]), ([5,3,1],[4,0,2]), ([4,2,3],[5,0,1]), ([1,5,2],[3,0,4]), ([3,1,0],[4,2,5]), ([3,0,4],[2,1,5]), ([0,3,2],[1,5,4]), ([1,5,3],[0,4,2]), ([0,5,1],[3,2,4]), ([5,2,1],[3,0,4]), ([2,3,1],[0,4,5]), ([1,0,5],[3,2,4]), ([1,2,5],[0,4,3]), ([1,3,5],[2,4,0]), ([2,3,5],[0,1,4]), ([5,2,1],[4,3,0]), ([4,2,0],[1,5,3]), ([1,0,2],[3,4,5]), ([5,2,1],[3,4,0]), ([2,5,0],[3,1,4]), ([2,4,5],[3,0,1]), ([3,0,4],[1,5,2]), ([1,4,2],[3,0,5]), ([3,2,1],[0,5,4]), ([5,0,4],[3,2,1]), ([4,2,5],[0,3,1]), ([5,3,4],[1,2,0]), ([4,5,1],[0,3,2]), ([0,1,4],[3,2,5]), ([2,1,5],[3,4,0]), ([2,1,4],[0,3,5]), ([5,0,2],[1,4,3]), ([1,0,5],[3,2,4]), ([5,4,0],[2,3,1]), ([5,3,2],[4,1,0]), ([1,3,5],[2,0,4]), ([3,5,2],[0,1,4]), ([2,4,3],[1,5,0]), ([4,5,0],[3,1,2]), ([0,5,4],[1,2,3]), ([1,3,5],[2,0,4]), ([1,5,3],[0,4,2]), ([1,0,5],[4,3,2]), ([2,5,0],[1,3,4]), ([5,0,3],[2,1,4]), ([5,4,3],[1,2,0]), ([3,2,4],[1,5,0]), ([5,4,1],[0,3,2]), ([1,2,4],[5,0,3]), ([1,5,2],[0,4,3]), ([5,4,1],[3,2,0]), ([0,4,1],[5,2,3]), ([2,5,4],[1,0,3]), ([1,5,3],[2,4,0]), ([4,3,2],[0,1,5]), ([4,5,0],[3,2,1]), ([4,0,5],[1,2,3]), ([0,1,3],[5,2,4]), ([5,0,3],[4,1,2]), ([1,3,4],[2,0,5]), ([5,2,1],[3,4,0]), ([2,5,3],[1,4,0]), ([2,4,3],[5,1,0]), ([3,2,5],[0,4,1]), ([1,2,4],[3,0,5]), ([5,2,0],[1,3,4]), ([4,1,2],[0,3,5]), ([4,3,5],[0,2,1]), ([5,1,2],[0,4,3]), ([4,3,1],[0,2,5]), ([3,0,4],[5,1,2]), ([5,1,3],[0,2,4]), ([0,1,2],[5,4,3]), ([3,5,1],[4,2,0]), ([0,2,3],[4,1,5]), ([4,5,3],[1,0,2]), ([4,1,5],[0,2,3]), ([5,3,0],[2,4,1]), ([2,3,1],[0,5,4]), ([0,2,1],[5,4,3]), ([3,1,4],[5,2,0]), ([0,5,3],[1,2,4]), ([5,2,3],[4,0,1]), ([5,3,2],[0,4,1]), ([3,1,0],[5,2,4]), ([0,1,3],[2,4,5]), ([2,4,0],[1,5,3]), ([5,3,2],[0,4,1]), ([4,2,3],[5,0,1]), ([2,0,5],[3,4,1]), ([1,5,4],[2,0,3]), ([5,4,2],[1,3,0]), ([2,1,5],[3,0,4]), ([3,1,2],[4,5,0]), ([1,0,5],[4,3,2]), ([0,3,2],[1,5,4]), ([5,4,3],[0,2,1]), ([2,1,3],[5,0,4]), ([5,2,3],[4,0,1]), ([1,4,2],[3,5,0]), ([4,5,0],[1,3,2]), ([3,0,1],[2,5,4]), ([0,1,3],[2,4,5]), ([2,5,1],[4,0,3]), ([0,5,2],[3,1,4]), ([1,5,0],[2,4,3]), ([3,5,1],[2,0,4]), ([1,5,4],[3,0,2]), ([1,5,3],[2,0,4]), ([0,2,3],[5,4,1]), ([1,0,3],[5,2,4]), ([2,0,1],[5,4,3]), ([4,3,2],[5,0,1]), ([2,1,0],[3,5,4]), ([1,0,4],[3,2,5]), ([4,0,1],[5,3,2]), ([4,3,5],[1,2,0]), ([3,0,4],[5,2,1]), ([0,4,2],[3,1,5]), ([0,2,5],[3,4,1]), ([3,4,1],[0,5,2]), ([2,0,5],[4,3,1]), ([1,0,3],[2,5,4]), ([2,0,3],[5,1,4]), ([4,5,2],[0,3,1]), ([0,5,4],[2,1,3]), ([0,2,1],[4,5,3]), ([5,1,3],[4,0,2]), ([5,0,4],[1,3,2]), ([3,5,1],[0,4,2]), ([5,4,3],[2,1,0]), ([0,1,4],[3,2,5]), ([0,5,3],[2,4,1]), ([5,2,1],[0,3,4]), ([3,5,2],[0,1,4]), ([1,5,4],[2,0,3]), ([5,2,3],[1,4,0]), ([4,1,2],[5,0,3]), ([5,0,4],[1,2,3]), ([2,5,0],[3,4,1]), ([3,0,1],[2,5,4]), ([3,4,0],[2,5,1]), ([5,2,4],[0,1,3]), ([5,0,2],[1,4,3]), ([5,4,2],[0,3,1]), ([2,5,1],[0,3,4]), ([3,1,5],[4,0,2]), ([2,4,0],[5,3,1]), ([2,3,0],[1,5,4]), ([0,2,3],[5,1,4]), ([0,1,3],[5,4,2]), ([0,3,5],[2,1,4]), ([4,5,0],[1,2,3]), ([1,0,2],[4,3,5]), ([0,3,1],[4,2,5]), ([1,5,3],[0,2,4]), ([4,5,3],[1,0,2]), ([2,4,3],[5,0,1]), ([5,4,0],[2,3,1]), ([4,0,3],[1,2,5]), ([1,3,0],[2,5,4]), ([1,5,4],[3,0,2]), ([5,2,3],[1,0,4]), ([5,4,3],[1,0,2]), ([5,0,2],[3,1,4]), ([5,3,0],[2,4,1]), ([3,4,5],[1,2,0]), ([1,5,3],[4,2,0]), ([0,1,4],[5,3,2]), ([1,5,2],[0,4,3]), ([1,0,2],[3,4,5]), ([3,5,0],[2,4,1]), ([0,2,5],[3,4,1]), ([3,5,1],[2,0,4]), ([0,4,1],[3,5,2]), ([2,3,0],[4,5,1]), ([4,2,1],[5,0,3]), ([5,2,3],[4,0,1]), ([2,5,0],[1,3,4]), ([2,5,3],[0,4,1]), ([5,2,0],[4,3,1]), ([3,2,5],[0,1,4]), ([4,0,1],[5,2,3]), ([5,4,2],[0,3,1]), ([2,5,0],[4,3,1]), ([5,0,2],[4,3,1]), ([5,0,2],[1,3,4]), ([2,1,5],[4,3,0]), ([0,4,1],[3,5,2]), ([2,3,5],[0,1,4]), ([3,4,2],[1,0,5]), ([2,0,5],[3,1,4]), ([2,1,4],[0,5,3]), ([5,2,1],[3,0,4]), ([0,4,1],[5,3,2]), ([1,2,4],[5,0,3]), ([4,5,0],[1,2,3]), ([3,4,2],[5,1,0]), ([5,2,3],[0,4,1]), ([2,3,4],[5,1,0]), ([5,2,4],[3,1,0]), ([3,0,4],[1,5,2]), ([0,2,1],[4,5,3]), ([1,2,0],[4,5,3]), ([3,1,5],[2,0,4]), ([1,5,2],[4,3,0]), ([0,4,2],[3,1,5]), ([0,4,3],[5,1,2]), ([4,3,1],[5,2,0]), ([4,2,1],[5,3,0]), ([4,5,1],[3,0,2]), ([1,3,5],[0,4,2]), ([4,3,5],[0,2,1]), ([0,5,1],[2,4,3]), ([4,3,5],[2,1,0]), ([2,3,1],[0,5,4]), ([4,5,3],[2,1,0]), ([3,1,5],[0,2,4]), ([4,1,2],[5,3,0]), ([4,1,3],[5,2,0]), ([4,3,0],[5,2,1]), ([5,0,4],[3,1,2]), ([4,0,3],[1,2,5]), ([2,1,3],[4,0,5]), ([3,5,4],[2,0,1]), ([2,1,3],[0,4,5]), ([1,4,0],[2,3,5]), ([4,1,3],[0,2,5]), ([2,0,4],[5,1,3]), ([4,1,2],[5,3,0]), ([0,2,3],[4,1,5]), ([3,1,2],[5,4,0]), ([1,0,2],[5,3,4]), ([2,5,4],[1,3,0]), ([1,2,4],[3,0,5]), ([4,2,0],[3,5,1]), ([5,3,1],[4,0,2]), ([2,0,1],[4,3,5]), ([2,0,5],[4,1,3]), ([1,0,3],[5,4,2]), ([1,2,4],[3,0,5]), ([2,1,3],[5,0,4]), ([3,4,0],[1,5,2]), ([3,5,1],[0,4,2]), ([5,3,0],[1,2,4]), ([5,3,2],[1,4,0]), ([3,2,4],[0,5,1]), ([3,4,2],[5,0,1]), ([1,5,3],[2,4,0]), ([3,1,2],[0,5,4]), ([4,3,1],[0,2,5]), ([4,1,3],[2,0,5]), ([1,0,4],[3,5,2]), ([2,3,1],[4,0,5]), ([2,3,0],[5,1,4]), ([0,4,1],[3,5,2]), ([2,0,4],[5,1,3]), ([4,1,0],[3,2,5]), ([0,1,4],[3,2,5]), ([5,1,4],[2,0,3]), ([2,3,5],[4,1,0]), ([2,4,0],[3,5,1]), ([0,2,3],[1,4,5]), ([1,4,3],[5,2,0]), ([1,0,2],[4,3,5]), ([3,0,2],[1,4,5]), ([5,4,1],[3,2,0]), ([5,0,3],[2,1,4]), ([5,2,3],[1,4,0]), ([3,0,4],[5,2,1]), ([3,1,5],[0,4,2]), ([4,3,1],[5,2,0]), ([5,0,3],[2,4,1]), ([5,2,4],[0,1,3]), ([1,0,5],[2,4,3]), ([3,1,4],[0,5,2]), ([0,2,1],[5,4,3]), ([0,5,4],[1,3,2]), ([2,5,4],[3,0,1]), ([4,0,2],[5,3,1]), ([5,0,3],[4,2,1]), ([3,2,1],[5,0,4]), ([0,3,2],[5,4,1]), ([3,5,1],[4,0,2]), ([5,4,0],[1,3,2]), ([5,0,4],[1,2,3]), ([3,4,0],[1,2,5]), ([3,2,4],[5,1,0]), ([2,3,1],[0,4,5]), ([5,0,1],[2,3,4]), ([5,2,4],[0,3,1]), ([5,1,3],[0,2,4]), ([4,0,2],[3,5,1]), ([1,2,0],[4,5,3]), ([1,3,5],[2,4,0]), ([4,2,0],[1,5,3]), ([2,1,5],[0,4,3]), ([3,5,0],[1,4,2]), ([4,0,3],[1,5,2]), ([1,3,0],[4,2,5]), ([2,0,1],[5,4,3]), ([3,1,0],[5,2,4]), ([1,2,4],[3,5,0]), ([1,3,4],[0,5,2]), ([1,3,4],[0,2,5]), ([3,4,2],[1,5,0]), ([4,1,5],[3,0,2]), ([0,1,4],[5,2,3]), ([4,3,0],[2,1,5]), ([5,0,1],[2,3,4]), ([0,1,5],[2,3,4]), ([3,4,1],[0,5,2]), ([4,1,2],[0,5,3]), ([2,5,1],[0,4,3]), ([4,1,0],[2,3,5]), ([5,3,0],[1,2,4]), ([5,3,4],[0,2,1]), ([3,1,4],[0,2,5]), ([2,3,1],[0,4,5]), ([3,2,5],[0,4,1]), ([3,1,0],[4,5,2]), ([4,2,0],[3,5,1]), ([5,4,3],[1,2,0]), ([1,4,5],[0,2,3]), ([4,5,3],[2,1,0]), ([3,1,4],[5,0,2]), ([0,2,3],[5,1,4]), ([2,1,3],[5,0,4]), ([1,5,3],[2,0,4]), ([3,0,5],[2,1,4]), ([5,3,0],[4,1,2]), ([0,5,2],[4,3,1]), ([2,1,4],[3,0,5]), ([2,4,0],[1,3,5]), ([2,5,1],[4,3,0]), ([1,2,0],[4,3,5]), ([3,4,5],[1,2,0]), ([0,3,2],[4,5,1]), ([3,1,0],[4,2,5]), ([0,2,5],[1,3,4]), ([1,5,4],[0,2,3]), ([2,1,5],[4,0,3]), ([0,2,4],[3,5,1]), ([4,5,1],[2,0,3]), ([3,2,1],[0,4,5]), ([5,2,3],[1,4,0]), ([3,4,1],[2,0,5]), ([2,3,1],[5,0,4]), ([1,0,2],[5,3,4]), ([4,0,1],[3,5,2]), ([1,0,4],[3,5,2]), ([3,0,4],[5,2,1]), ([1,0,3],[4,2,5]), ([5,3,2],[4,0,1]), ([3,5,0],[1,2,4]), ([1,5,2],[0,4,3]), ([3,2,5],[4,1,0]), ([5,1,3],[0,4,2]), ([1,4,3],[0,2,5]), ([3,5,1],[2,4,0]), ([0,3,1],[2,4,5]), ([2,4,1],[5,0,3]), ([2,4,3],[5,0,1]), ([1,5,3],[2,4,0]), ([2,3,5],[4,1,0]), ([5,0,1],[4,2,3]), ([5,1,3],[4,0,2]), ([4,5,1],[0,2,3]), ([3,0,5],[2,1,4]), ([0,3,5],[2,4,1]), ([5,0,3],[2,1,4]), ([2,4,0],[5,3,1]), ([3,5,4],[2,1,0]), ([3,4,2],[1,0,5]), ([4,2,0],[5,1,3]), ([3,2,0],[4,1,5]), ([3,2,5],[1,0,4]), ([3,0,2],[1,5,4]), ([2,4,0],[1,3,5]), ([1,4,3],[2,5,0]), ([2,1,3],[0,5,4]), ([4,5,3],[2,1,0]), ([5,4,1],[2,3,0]), ([5,0,2],[1,4,3]), ([2,0,1],[5,3,4]), ([1,3,2],[0,5,4]), ([3,0,2],[4,1,5]), ([0,3,2],[1,4,5]), ([0,1,3],[2,4,5]), ([2,0,3],[4,1,5]), ([5,0,4],[2,1,3]), ([5,2,0],[4,3,1]), ([2,5,4],[0,3,1]), ([0,3,5],[2,1,4]), ([1,0,3],[5,4,2]), ([3,4,2],[1,0,5]), ([0,3,1],[4,5,2]), ([3,0,4],[2,1,5]), ([2,1,0],[3,4,5]), ([5,0,2],[4,1,3]), ([2,4,3],[1,5,0]), ([4,1,0],[3,2,5]), ([5,3,0],[1,2,4]), ([4,3,2],[0,5,1]), ([1,3,2],[4,0,5]), ([1,5,2],[4,0,3]), ([1,0,4],[2,5,3]), ([0,5,1],[4,3,2]), ([3,2,0],[4,1,5]), ([3,4,1],[5,2,0]), ([0,4,3],[2,1,5]), ([3,0,2],[4,1,5]), ([4,1,2],[5,0,3]), ([4,2,5],[1,0,3]), ([4,5,0],[3,1,2]), ([5,3,4],[1,2,0]), ([3,2,4],[1,5,0]), ([5,3,2],[4,1,0]), ([1,3,5],[0,2,4]), ([5,3,4],[1,2,0]), ([2,0,5],[4,1,3]), ([4,5,1],[2,3,0]), ([0,3,4],[5,2,1]), ([1,0,2],[4,5,3]), ([5,0,3],[1,2,4]), ([0,1,5],[4,2,3]), ([3,5,2],[0,4,1]), ([4,1,3],[5,0,2]), ([5,2,0],[1,3,4]), ([2,3,0],[4,5,1]), ([3,1,5],[2,4,0]), ([0,3,4],[1,2,5]), ([0,1,2],[4,3,5]), ([5,0,2],[4,3,1]), ([4,1,3],[5,2,0]), ([4,1,0],[2,3,5]), ([2,0,4],[3,1,5]), ([3,2,5],[4,0,1]), ([0,5,2],[4,3,1]), ([3,5,4],[0,2,1]), ([3,2,1],[4,0,5]), ([5,4,3],[2,1,0]), ([5,4,2],[0,3,1]), ([1,2,5],[4,3,0]), ([3,2,5],[4,1,0]), ([5,0,2],[1,4,3]), ([3,0,5],[2,4,1]), ([5,2,4],[1,3,0]), ([1,2,5],[4,0,3]), ([0,2,3],[5,1,4]), ([2,3,4],[1,0,5]), ([5,3,0],[4,2,1]), ([4,0,3],[2,1,5]), ([5,3,2],[1,4,0]), ([5,0,1],[3,2,4]), ([1,5,2],[3,0,4]), ([3,5,0],[2,1,4]), ([4,5,1],[3,2,0]), ([1,5,3],[2,0,4]), ([2,1,4],[5,3,0]), ([5,0,1],[2,3,4]), ([1,4,2],[3,5,0]), ([0,4,3],[5,2,1]), ([0,2,5],[3,1,4]), ([5,2,4],[1,3,0]), ([0,5,3],[1,4,2]), ([4,0,1],[2,3,5]), ([2,1,4],[5,3,0]), ([1,5,3],[2,4,0]), ([0,1,5],[4,3,2]), ([4,1,3],[0,2,5]), ([1,3,4],[2,0,5]), ([4,3,2],[1,0,5]), ([2,0,5],[3,4,1]), ([0,2,1],[4,5,3]), ([1,0,3],[4,5,2]), ([1,3,0],[2,4,5]), ([5,0,4],[1,2,3]), ([4,5,0],[1,3,2]), ([1,4,5],[3,2,0]), ([4,1,3],[5,2,0]), ([5,1,3],[2,0,4]), ([2,4,0],[1,5,3]), ([0,2,4],[5,1,3]), ([0,3,2],[1,5,4]), ([4,2,5],[0,3,1]), ([2,1,0],[4,3,5]), ([3,2,4],[5,1,0]), ([2,5,1],[3,0,4]), ([0,3,5],[2,1,4]), ([4,5,0],[1,2,3]), ([0,2,5],[1,4,3]), ([1,2,3],[4,5,0]), ([2,3,4],[0,5,1]), ([2,4,5],[3,1,0]), ([3,1,4],[0,5,2]), ([0,4,2],[1,5,3]), ([3,2,5],[0,4,1]), ([4,3,5],[1,2,0]), ([0,4,1],[3,5,2]), ([2,3,4],[5,1,0]), ([0,1,3],[5,4,2]), ([1,4,3],[0,2,5]), ([5,0,4],[1,3,2]), ([3,2,0],[4,5,1]), ([3,5,1],[4,0,2]), ([3,4,5],[0,2,1]), ([3,5,0],[2,1,4]), ([1,5,3],[4,2,0]), ([5,2,1],[4,0,3]), ([2,3,1],[4,5,0]), ([1,3,2],[0,5,4]), ([0,2,3],[1,5,4]), ([3,2,4],[5,1,0]), ([4,2,0],[5,1,3]), ([2,1,3],[0,5,4]), ([2,4,0],[5,3,1]), ([5,0,4],[3,1,2]), ([0,5,1],[4,3,2]), ([4,3,5],[1,0,2]), ([3,1,2],[0,5,4]), ([2,3,0],[5,4,1]), ([5,4,1],[2,3,0]), ([5,2,4],[3,0,1]), ([5,1,0],[3,4,2]), ([5,3,2],[4,0,1]), ([2,1,5],[3,0,4]), ([4,3,0],[1,5,2]), ([3,0,4],[1,2,5]), ([5,2,0],[1,3,4]), ([0,2,3],[1,4,5]), ([2,5,4],[3,0,1]), ([3,4,0],[2,1,5]), ([0,5,3],[2,4,1]), ([3,0,2],[5,4,1]), ([3,5,4],[0,1,2]), ([5,4,1],[2,0,3]), ([3,5,2],[4,0,1]), ([4,0,2],[1,3,5]), ([4,3,2],[1,0,5]), ([5,4,3],[2,1,0]), ([4,2,3],[5,0,1]), ([2,0,3],[1,5,4]), ([4,1,0],[3,5,2]), ([2,0,4],[3,1,5]), ([4,1,2],[3,5,0]), ([3,0,4],[5,1,2]), ([1,2,4],[5,3,0]), ([2,5,4],[3,0,1]), ([0,2,1],[4,3,5]), ([3,4,5],[1,0,2]), ([4,0,2],[1,5,3]), ([5,2,1],[4,3,0]), ([5,0,1],[4,2,3]), ([4,1,2],[5,0,3]), ([1,0,2],[3,4,5]), ([2,5,4],[0,1,3]), ([1,0,4],[2,5,3]), ([3,0,4],[5,1,2]), ([3,0,5],[1,4,2]), ([2,5,1],[4,3,0]), ([0,3,4],[2,5,1]), ([3,0,1],[2,4,5]), ([3,1,5],[0,4,2]), ([4,0,5],[3,2,1]), ([0,1,4],[3,2,5]), ([5,3,2],[4,0,1]), ([1,0,3],[2,5,4]), ([4,0,2],[3,5,1]), ([0,2,1],[5,3,4]), ([4,0,3],[1,5,2]), ([0,1,3],[2,4,5]), ([2,0,1],[3,5,4]), ([0,4,2],[3,1,5]), ([4,2,3],[0,5,1]), ([3,1,5],[2,0,4]), ([1,5,0],[3,2,4]), ([2,5,1],[3,0,4]), ([5,0,1],[4,2,3]), ([1,5,0],[2,3,4]), ([3,4,2],[5,0,1]), ([3,4,0],[1,5,2]), ([0,5,2],[1,4,3]), ([5,4,2],[0,3,1]), ([2,0,3],[1,5,4]), ([4,2,1],[3,0,5]), ([1,5,3],[0,2,4]), ([3,4,0],[2,5,1]), ([4,1,0],[5,2,3]), ([4,2,5],[3,1,0]), ([4,1,0],[3,5,2]), ([2,1,0],[4,3,5]), ([0,3,2],[1,4,5]), ([5,4,3],[1,2,0]), ([5,3,4],[1,2,0]), ([0,4,3],[5,2,1]), ([1,0,5],[4,2,3]), ([4,3,5],[2,0,1]), ([2,4,0],[1,3,5]), ([0,1,3],[4,2,5]), ([0,4,2],[3,5,1]), ([2,1,5],[3,0,4]), ([3,0,2],[5,4,1]), ([4,5,1],[3,2,0]), ([1,0,4],[3,2,5]), ([0,2,1],[4,5,3]), ([1,0,4],[3,2,5]), ([1,5,4],[2,3,0]), ([3,0,1],[4,5,2]), ([5,4,1],[3,0,2]), ([2,0,5],[4,3,1]), ([1,3,2],[5,0,4]), ([4,1,0],[5,3,2]), ([0,4,1],[5,3,2]), ([0,3,4],[5,1,2]), ([0,5,1],[2,4,3]), ([0,3,5],[2,1,4]), ([2,0,5],[1,3,4]), ([1,0,3],[2,4,5]), ([4,0,2],[5,1,3]), ([3,5,4],[2,1,0]), ([5,1,2],[4,3,0]), ([4,5,1],[3,0,2]), ([5,4,1],[0,2,3]), ([1,3,4],[0,2,5]), ([0,5,1],[2,3,4]), ([0,3,5],[2,4,1]), ([1,5,0],[4,3,2]), ([3,0,2],[1,5,4]), ([5,4,3],[1,2,0]), ([5,3,2],[1,4,0]), ([1,4,5],[0,2,3]), ([5,4,0],[1,2,3]), ([1,4,3],[0,5,2]), ([0,2,1],[5,3,4]), ([5,0,3],[2,1,4]), ([1,0,3],[2,5,4]), ([5,1,3],[4,2,0]), ([1,2,5],[4,3,0]), ([2,4,3],[5,1,0]), ([5,4,0],[3,1,2]), ([4,2,5],[0,3,1]), ([1,2,3],[5,0,4]), ([2,4,3],[5,0,1]), ([3,5,2],[0,4,1]), ([4,1,3],[2,5,0]), ([3,0,2],[4,5,1]), ([0,4,2],[5,3,1]), ([3,1,0],[4,2,5]), ([3,4,0],[1,5,2]), ([2,3,5],[4,0,1]), ([4,0,5],[2,1,3]), ([2,4,3],[0,5,1]), ([0,3,4],[5,1,2]), ([5,0,3],[2,1,4]), ([2,1,0],[4,5,3]), ([4,3,5],[0,1,2]), ([2,5,0],[3,4,1]), ([4,5,0],[1,2,3]), ([0,5,2],[1,4,3]), ([3,4,2],[1,5,0]), ([5,0,3],[2,1,4]), ([1,5,0],[2,4,3]), ([4,3,0],[5,2,1]), ([4,1,2],[0,3,5]), ([3,2,4],[5,0,1]), ([2,3,5],[1,4,0]), ([1,3,4],[2,0,5]), ([2,1,5],[3,0,4]), ([5,1,4],[0,3,2]), ([2,1,0],[4,5,3]), ([4,5,0],[3,2,1]), ([3,5,2],[0,4,1]), ([1,2,4],[5,0,3]), ([5,3,2],[1,0,4]), ([5,2,1],[4,3,0]), ([1,3,4],[2,5,0]), ([4,3,2],[1,5,0]), ([3,0,5],[4,1,2]), ([4,0,5],[3,2,1]), ([5,3,1],[4,0,2]), ([4,0,2],[1,5,3]), ([3,0,2],[5,4,1]), ([1,0,5],[3,4,2]), ([0,3,2],[5,1,4]), ([4,1,3],[2,0,5]), ([0,1,4],[3,5,2]), ([5,4,1],[3,2,0]), ([3,0,2],[1,5,4]), ([0,4,3],[1,2,5]), ([5,2,0],[4,1,3]), ([5,3,0],[4,1,2]), ([3,1,2],[0,5,4]), ([3,1,2],[4,0,5]), ([5,1,4],[0,3,2]), ([2,1,0],[4,3,5]), ([0,3,4],[1,5,2]), ([4,3,1],[2,0,5]), ([4,5,1],[3,0,2]), ([0,1,3],[2,4,5]), ([3,0,4],[5,2,1]), ([1,0,3],[2,4,5]), ([1,2,0],[4,3,5]), ([2,1,4],[3,0,5]), ([2,1,0],[4,3,5]), ([3,2,1],[0,5,4]), ([5,4,2],[1,3,0]), ([3,1,2],[4,5,0]), ([2,4,0],[1,3,5]), ([1,0,4],[2,5,3]), ([5,3,4],[2,1,0]), ([0,1,3],[4,2,5]), ([3,5,4],[1,2,0]), ([4,5,3],[1,2,0]), ([3,4,1],[2,0,5]), ([2,0,1],[4,3,5]), ([1,2,4],[5,0,3]), ([0,2,1],[3,4,5]), ([4,3,5],[2,0,1]), ([5,2,4],[0,3,1]), ([2,5,0],[1,4,3]), ([4,5,1],[3,2,0]), ([2,1,0],[5,3,4]), ([0,1,2],[5,4,3]), ([4,0,5],[3,1,2]), ([4,0,1],[2,3,5]), ([5,1,2],[0,3,4]), ([5,0,4],[2,1,3]), ([0,2,1],[4,5,3]), ([3,4,1],[0,5,2]), ([0,5,4],[3,1,2]), ([2,3,5],[0,1,4]), ([2,5,3],[1,0,4]), ([3,0,5],[1,2,4]), ([3,4,0],[2,5,1]), ([5,0,1],[3,4,2]), ([1,4,3],[0,5,2]), ([2,0,5],[4,3,1]), ([4,3,2],[1,5,0]), ([1,3,4],[2,0,5]), ([0,3,1],[5,4,2]), ([4,0,5],[2,1,3]), ([3,5,0],[1,2,4]), ([1,4,2],[0,5,3]), ([4,0,5],[1,2,3]), ([1,2,5],[0,4,3]), ([2,4,0],[1,5,3]), ([2,3,4],[5,1,0]), ([0,1,4],[5,3,2]), ([0,2,5],[3,4,1]), ([1,2,5],[4,0,3]), ([4,2,0],[1,5,3]), ([3,2,4],[0,5,1]), ([4,2,5],[0,3,1]), ([0,1,5],[4,2,3]), ([2,4,5],[0,3,1]), ([1,2,3],[4,5,0]), ([5,3,1],[0,4,2]), ([3,4,1],[5,0,2]), ([0,1,3],[2,5,4]), ([0,3,5],[1,4,2]), ([1,2,5],[3,0,4]), ([1,5,3],[4,2,0]), ([1,3,0],[4,2,5]), ([5,2,1],[0,4,3]), ([5,4,2],[3,0,1]), ([3,0,2],[4,5,1]), ([3,0,2],[4,5,1]), ([3,2,5],[0,1,4]), ([0,2,5],[3,1,4]), ([4,1,5],[2,0,3]), ([0,3,1],[5,4,2]), ([5,0,1],[4,2,3]), ([1,3,5],[0,4,2]), ([5,4,3],[0,1,2]), ([0,3,1],[5,4,2]), ([0,4,5],[1,3,2]), ([1,4,2],[3,0,5]), ([5,1,2],[0,4,3]), ([3,5,0],[1,4,2]), ([2,0,3],[4,5,1]), ([5,0,4],[3,1,2]), ([3,2,1],[4,5,0]), ([2,3,1],[4,0,5]), ([0,1,5],[4,2,3]), ([1,2,3],[0,4,5]), ([1,5,3],[2,0,4]), ([3,5,0],[2,4,1]), ([5,3,4],[2,0,1]), ([4,0,1],[3,2,5]), ([3,4,2],[5,0,1]), ([3,1,2],[0,5,4]), ([5,1,2],[0,3,4]), ([5,2,1],[3,4,0]), ([0,2,1],[4,5,3]), ([3,2,5],[4,0,1]), ([4,0,3],[5,1,2]), ([4,3,5],[0,2,1]), ([3,4,0],[1,2,5]), ([2,0,5],[3,4,1]), ([2,1,3],[0,5,4]), ([2,4,5],[3,1,0]), ([0,1,5],[4,2,3]), ([4,0,1],[2,5,3]), ([3,5,4],[1,0,2]), ([0,2,3],[4,1,5]), ([5,3,4],[1,2,0]), ([4,1,5],[0,2,3]), ([2,1,5],[0,3,4]), ([0,5,4],[3,2,1]), ([1,4,0],[3,2,5]), ([2,0,4],[5,1,3]), ([4,3,0],[5,2,1]), ([4,5,3],[1,0,2]), ([1,2,0],[3,4,5]), ([4,2,3],[5,0,1]), ([2,3,0],[5,1,4]), ([5,0,4],[2,3,1]), ([5,0,2],[1,4,3]), ([0,3,4],[1,5,2]), ([5,3,2],[4,1,0]), ([1,5,2],[4,0,3]), ([1,0,4],[3,2,5]), ([0,2,1],[5,3,4]), ([2,0,3],[1,4,5]), ([0,1,3],[5,4,2]), ([0,5,3],[2,4,1]), ([5,0,1],[4,3,2]), ([4,2,0],[1,3,5]), ([0,5,3],[1,2,4]), ([3,5,0],[2,1,4]), ([2,4,1],[5,3,0]), ([3,2,5],[4,0,1]), ([0,5,1],[3,4,2]), ([5,0,1],[2,3,4]), ([0,3,2],[5,1,4]), ([4,2,3],[0,1,5]), ([3,2,5],[4,0,1]), ([3,5,0],[1,4,2]), ([5,2,3],[1,0,4]), ([0,1,3],[5,2,4]), ([5,2,3],[1,0,4]), ([0,4,2],[5,3,1]), ([1,3,4],[5,0,2]), ([3,1,5],[0,2,4]), ([3,2,4],[1,5,0]), ([4,5,3],[1,0,2]), ([2,3,1],[5,4,0]), ([4,0,3],[5,1,2]), ([0,2,3],[5,1,4]), ([5,4,2],[3,1,0]), ([4,3,5],[0,2,1]), ([4,5,2],[3,1,0]), ([1,3,4],[0,5,2]), ([2,3,0],[1,4,5]), ([3,2,1],[0,4,5]), ([2,0,4],[5,1,3]), ([0,1,2],[5,4,3]), ([1,0,3],[4,5,2]), ([4,0,5],[3,1,2]), ([5,2,3],[0,4,1]), ([3,1,4],[0,5,2]), ([3,1,5],[0,4,2]), ([5,2,0],[3,4,1]), ([2,0,5],[3,1,4]), ([1,3,2],[4,0,5]), ([5,0,4],[2,3,1]), ([1,3,0],[2,4,5]), ([4,1,2],[5,3,0]), ([2,0,4],[5,1,3]), ([5,0,3],[4,2,1]), ([0,4,3],[2,5,1]), ([1,2,5],[0,3,4]), ([0,2,1],[4,3,5]), ([0,5,2],[1,3,4]), ([2,3,5],[1,4,0]), ([4,3,5],[0,1,2]), ([2,3,0],[1,4,5]), ([4,2,0],[5,3,1]), ([0,1,5],[3,2,4]), ([5,4,1],[3,0,2]), ([5,2,4],[1,0,3]), ([1,5,2],[4,0,3]), ([5,3,0],[2,1,4]), ([1,4,5],[2,3,0]), ([2,0,4],[3,1,5]), ([5,3,0],[2,1,4]), ([4,5,1],[0,3,2]), ([2,5,3],[1,4,0]), ([2,3,1],[4,0,5]), ([5,0,1],[2,4,3]), ([3,5,0],[1,4,2]), ([4,2,5],[0,3,1]), ([3,1,0],[2,5,4]), ([1,2,3],[5,0,4]), ([3,1,5],[2,4,0]), ([4,2,1],[3,0,5]), ([2,5,1],[4,3,0]), ([1,3,5],[2,0,4]), ([4,1,3],[5,2,0]), ([3,0,5],[4,2,1]), ([1,4,2],[0,5,3]), ([4,5,3],[2,0,1]), ([4,5,1],[3,2,0]), ([2,3,4],[1,5,0]), ([4,5,0],[3,2,1]), ([3,2,4],[5,0,1]), ([1,2,5],[4,0,3]), ([4,0,1],[3,5,2]), ([0,2,5],[4,3,1]), ([1,4,3],[2,5,0]), ([0,2,3],[5,1,4]), ([1,2,0],[4,5,3]), ([4,3,1],[0,5,2]), ([2,0,1],[5,4,3]), ([0,2,3],[4,1,5]), ([3,0,2],[1,5,4]), ([0,5,1],[3,2,4]), ([1,3,2],[0,4,5]), ([3,4,2],[1,0,5]), ([2,1,0],[3,4,5]), ([3,0,4],[5,1,2]), ([5,0,2],[1,4,3]), ([5,1,0],[4,2,3]), ([1,4,5],[2,3,0]), ([4,3,5],[2,1,0]), ([4,1,5],[0,2,3]), ([3,5,4],[1,2,0]), ([1,0,2],[4,5,3]), ([0,4,3],[1,5,2]), ([4,2,5],[3,0,1]), ([4,2,1],[0,5,3]), ([2,5,3],[0,4,1]), ([3,5,2],[1,0,4]), ([3,2,5],[0,4,1]), ([4,0,2],[3,5,1]), ([5,3,1],[4,2,0]), ([0,1,4],[5,2,3]), ([4,1,3],[0,2,5]), ([5,0,3],[1,4,2]), ([2,5,3],[1,4,0]), ([4,3,1],[0,5,2]), ([2,5,1],[3,4,0]), ([0,5,4],[1,2,3]), ([5,3,2],[0,4,1]), ([3,0,5],[2,1,4]), ([4,5,2],[0,3,1]), ([1,0,3],[2,4,5]), ([0,1,2],[3,4,5]), ([5,2,3],[0,1,4]), ([1,2,3],[5,0,4]), ([5,1,2],[4,0,3]), ([1,5,2],[3,0,4]), ([3,2,4],[0,1,5]), ([1,3,4],[2,0,5]), ([4,2,5],[1,3,0]), ([1,4,0],[3,2,5]), ([3,4,5],[2,0,1]), ([3,4,5],[0,1,2]), ([3,4,2],[1,5,0]), ([5,2,0],[4,1,3]), ([5,1,2],[3,4,0]), ([2,4,3],[0,5,1]), ([0,5,2],[3,1,4]), ([2,0,3],[1,4,5]), ([5,2,4],[3,1,0]), ([2,5,3],[4,1,0]), ([3,5,0],[2,4,1]), ([0,1,3],[2,5,4]), ([4,1,0],[5,2,3]), ([5,2,4],[1,3,0]), ([0,1,2],[3,4,5]), ([2,1,3],[0,4,5]), ([4,5,3],[2,0,1]), ([1,3,4],[5,2,0]), ([4,2,3],[0,5,1]), ([0,3,5],[1,4,2]), ([2,5,4],[3,0,1]), ([1,3,4],[2,5,0]), ([3,4,2],[1,0,5]), ([4,5,0],[3,1,2]), ([4,0,3],[2,1,5]), ([2,0,3],[1,4,5]), ([2,5,0],[4,1,3]), ([4,1,3],[0,2,5]), ([0,4,1],[3,5,2]), ([4,1,5],[0,3,2]), ([0,1,5],[4,2,3]), ([5,4,1],[3,2,0]), ([1,0,5],[3,2,4]), ([0,5,4],[2,1,3]), ([3,5,1],[0,4,2]), ([5,4,0],[1,3,2]), ([1,0,4],[5,3,2]), ([4,1,3],[5,2,0]), ([4,0,2],[3,5,1]), ([3,5,2],[0,1,4]), ([0,5,3],[4,1,2]), ([5,0,2],[1,4,3]), ([4,0,1],[5,2,3]), ([5,0,4],[2,1,3]), ([1,2,5],[4,0,3]), ([0,5,2],[4,1,3]), ([0,2,3],[1,4,5]), ([3,4,5],[1,0,2]), ([2,0,1],[3,4,5]), ([3,4,0],[1,2,5]), ([1,0,4],[5,2,3]), ([4,2,5],[3,0,1]), ([3,1,2],[0,4,5]), ([0,3,5],[1,4,2]), ([2,0,4],[1,5,3]), ([0,1,2],[3,4,5]), ([3,5,1],[2,4,0]), ([3,4,1],[5,2,0]), ([5,3,2],[0,1,4]), ([0,1,4],[2,3,5]), ([1,2,4],[5,0,3]), ([4,3,1],[2,5,0]), ([0,4,3],[5,2,1]), ([4,1,5],[0,2,3]), ([1,5,4],[2,0,3]), ([3,5,2],[0,1,4]), ([3,2,5],[0,1,4]), ([4,0,2],[5,1,3]), ([0,3,2],[4,1,5]), ([5,0,1],[3,2,4]), ([1,2,4],[0,5,3]), ([5,4,3],[0,1,2]), ([1,2,5],[3,4,0]), ([0,3,4],[2,1,5]), ([3,5,2],[1,0,4]), ([4,0,1],[5,3,2]), ([2,0,1],[5,4,3]), ([3,4,1],[0,2,5]), ([2,5,4],[0,3,1]), ([3,1,4],[5,0,2]), ([5,3,0],[2,1,4]), ([2,4,3],[0,1,5]), ([3,0,4],[2,5,1]), ([2,1,5],[3,4,0]), ([0,2,3],[5,4,1]), ([0,2,4],[3,1,5]), ([1,3,0],[5,2,4]), ([1,0,5],[2,3,4]), ([1,0,3],[5,4,2]), ([3,1,0],[4,2,5]), ([2,0,1],[4,5,3]), ([0,1,4],[5,3,2]), ([3,2,0],[1,5,4]), ([2,0,1],[5,4,3]), ([2,0,3],[1,5,4]), ([4,1,2],[0,5,3]), ([4,3,1],[5,0,2]), ([2,5,1],[3,0,4]), ([2,4,0],[1,5,3]), ([0,3,1],[4,5,2]), ([4,5,2],[1,3,0]), ([1,5,2],[0,4,3]), ([0,3,2],[1,5,4]), ([3,0,4],[1,2,5]), ([5,1,4],[2,3,0]), ([1,5,2],[3,0,4]), ([0,5,1],[2,3,4]), ([1,2,0],[5,4,3]), ([3,4,5],[2,1,0]), ([2,1,4],[3,0,5]), ([3,4,5],[1,0,2]), ([4,0,1],[3,5,2]), ([2,4,3],[0,5,1]), ([5,4,3],[2,0,1]), ([4,5,0],[3,2,1]), ([2,0,1],[4,3,5]), ([4,2,3],[1,0,5]), ([4,3,5],[1,2,0]), ([4,5,1],[2,0,3]), ([2,4,1],[5,3,0]), ([4,3,5],[0,2,1]), ([3,5,1],[4,0,2]), ([3,5,1],[4,0,2]), ([2,1,5],[0,4,3]), ([0,3,1],[4,2,5]), ([5,3,1],[4,0,2]), ([1,2,4],[3,5,0]), ([5,1,3],[0,2,4]), ([2,4,5],[0,1,3]), ([0,1,5],[3,2,4]), ([2,3,4],[5,1,0]), ([4,2,5],[0,3,1]), ([0,1,3],[4,5,2]), ([5,4,1],[3,0,2]), ([2,3,1],[5,4,0]), ([1,0,3],[2,5,4]), ([1,2,4],[5,0,3]), ([0,4,2],[5,1,3]), ([1,3,5],[0,4,2]), ([2,0,1],[5,3,4]), ([0,3,4],[1,2,5]), ([0,1,5],[4,3,2]), ([1,3,2],[5,4,0]), ([0,3,1],[4,5,2]), ([3,4,5],[0,2,1]), ([3,5,4],[0,1,2]), ([3,2,4],[1,0,5]), ([3,0,1],[4,5,2]), ([2,1,0],[3,5,4]), ([3,2,0],[1,5,4]), ([3,1,5],[0,4,2]), ([3,1,5],[4,2,0]), ([1,0,4],[3,5,2]), ([1,5,4],[2,3,0]), ([3,4,0],[1,2,5]), ([1,5,3],[4,2,0]), ([3,2,5],[1,4,0]), ([0,1,5],[3,4,2]), ([3,2,0],[1,4,5]), ([4,2,3],[5,1,0]), ([0,3,1],[2,4,5]), ([0,3,2],[4,1,5]), ([5,4,0],[2,3,1]), ([4,1,2],[5,0,3]), ([1,3,4],[0,5,2]), ([2,1,4],[0,3,5]), ([3,5,4],[2,0,1]), ([0,4,5],[2,1,3]), ([0,2,1],[4,5,3]), ([2,3,0],[4,1,5]), ([1,0,4],[5,2,3]), ([5,3,2],[1,4,0]), ([1,4,0],[2,3,5]), ([1,5,0],[2,4,3]), ([1,2,5],[3,0,4]), ([3,1,5],[4,0,2]), ([1,4,2],[5,0,3]), ([1,5,0],[4,3,2]), ([0,2,1],[4,5,3]), ([5,0,1],[3,4,2]), ([5,2,1],[3,4,0]), ([4,1,3],[0,2,5]), ([2,4,3],[5,0,1]), ([4,1,0],[2,5,3]), ([3,2,5],[1,4,0]), ([2,0,4],[5,1,3]), ([2,4,3],[0,1,5]), ([2,0,5],[3,4,1]), ([4,1,3],[5,2,0]), ([5,3,4],[1,2,0]), ([4,3,2],[0,1,5]), ([2,3,0],[1,5,4]), ([4,2,1],[3,0,5]), ([4,3,0],[5,1,2]), ([4,2,1],[0,5,3]), ([5,3,1],[0,2,4]), ([0,3,5],[4,2,1]), ([5,2,4],[3,1,0]), ([0,5,3],[1,4,2]), ([2,5,3],[1,4,0]), ([0,4,3],[1,2,5]), ([3,0,1],[4,2,5]), ([5,0,4],[1,3,2]), ([4,3,0],[2,1,5]), ([1,5,0],[2,3,4]), ([1,0,5],[2,3,4]), ([2,1,5],[0,3,4]), ([2,1,3],[0,4,5]), ([3,4,2],[5,0,1]), ([0,3,2],[5,4,1]), ([2,0,1],[4,5,3]), ([4,5,1],[3,2,0]), ([5,2,3],[4,1,0]), ([3,2,1],[4,5,0]), ([0,5,4],[1,2,3]), ([2,1,0],[5,3,4]), ([3,0,2],[5,4,1]), ([0,4,1],[2,5,3]), ([5,4,2],[0,3,1]), ([5,3,2],[4,1,0]), ([0,3,2],[4,5,1]), ([0,1,2],[3,4,5]), ([3,4,1],[0,2,5]), ([0,4,3],[2,1,5]), ([1,5,0],[2,3,4]), ([1,0,5],[3,4,2]), ([0,5,2],[3,4,1]), ([5,0,3],[2,1,4]), ([2,0,3],[5,4,1]), ([2,5,1],[0,3,4]), ([2,4,1],[0,3,5]), ([3,0,5],[2,1,4]), ([5,3,4],[2,1,0]), ([5,1,2],[0,3,4]), ([4,0,5],[3,1,2]), ([1,5,3],[4,2,0]), ([2,4,1],[0,5,3]), ([2,3,4],[0,1,5]), ([0,5,2],[1,3,4]), ([5,0,2],[1,3,4]), ([2,3,1],[0,4,5]), ([3,1,5],[0,2,4]), ([5,0,4],[1,3,2]), ([3,5,0],[4,2,1]), ([4,3,5],[1,2,0]), ([1,0,5],[3,4,2]), ([0,5,1],[2,3,4]), ([2,5,3],[1,4,0]), ([3,1,2],[0,5,4]), ([0,4,5],[1,3,2]), ([4,2,1],[3,5,0]), ([4,1,2],[0,5,3]), ([4,2,0],[3,5,1]), ([2,0,1],[5,3,4]), ([1,2,3],[0,5,4]), ([2,1,3],[5,4,0]), ([1,0,3],[5,2,4]), ([5,0,2],[1,4,3]), ([4,2,5],[0,3,1]), ([0,5,2],[3,1,4]), ([1,3,0],[4,5,2]), ([3,0,4],[2,5,1]), ([3,2,5],[4,1,0]), ([2,0,3],[5,1,4]), ([4,0,5],[1,2,3]), ([1,4,5],[0,2,3]), ([0,1,2],[4,5,3]), ([3,4,5],[0,2,1]), ([4,1,2],[0,3,5]), ([0,3,1],[4,2,5]), ([1,0,2],[4,3,5]), ([0,1,3],[5,2,4]), ([2,1,3],[5,4,0]), ([4,2,5],[1,3,0]), ([2,3,1],[4,0,5]), ([1,4,3],[2,5,0]), ([2,4,5],[0,1,3]), ([4,2,1],[3,0,5]), ([3,0,2],[5,4,1]), ([1,0,4],[2,5,3]), ([0,3,2],[5,1,4]), ([5,4,3],[1,0,2]), ([5,0,3],[1,2,4]), ([3,1,4],[2,5,0]), ([5,0,4],[1,3,2]), ([5,3,2],[0,1,4]), ([3,0,5],[2,1,4]), ([4,1,0],[3,5,2]), ([1,4,3],[2,0,5]), ([0,1,4],[3,2,5]), ([5,4,0],[1,3,2]), ([2,5,1],[3,4,0]), ([3,1,0],[4,5,2]), ([5,4,3],[0,1,2]), ([1,2,4],[3,5,0]), ([3,1,4],[0,2,5]), ([4,3,2],[0,1,5]), ([4,0,2],[3,5,1]), ([0,2,4],[3,1,5]), ([1,4,5],[2,3,0]), ([1,0,3],[2,4,5]), ([0,2,1],[3,4,5]), ([4,1,2],[3,0,5]), ([0,3,5],[4,1,2]), ([0,2,1],[3,4,5]), ([1,4,5],[0,3,2]), ([1,2,5],[3,4,0]), ([3,5,1],[2,0,4]), ([4,0,5],[1,2,3]), ([3,1,2],[0,4,5]), ([2,5,3],[1,4,0]), ([0,4,3],[5,1,2]), ([2,0,3],[4,5,1]), ([0,2,3],[5,4,1]), ([5,3,4],[2,0,1]), ([1,3,0],[5,2,4]), ([2,5,4],[0,1,3]), ([5,2,3],[4,0,1]), ([4,5,3],[2,0,1]), ([3,4,5],[2,0,1]), ([4,3,1],[5,2,0]), ([5,1,2],[3,4,0]), ([4,2,1],[0,5,3]), ([3,5,4],[2,0,1]), ([4,2,1],[5,3,0]), ([4,1,0],[2,5,3]), ([2,0,4],[5,1,3]), ([3,0,1],[2,4,5]), ([4,2,1],[0,3,5]), ([5,2,1],[0,4,3]), ([5,2,1],[4,3,0]), ([5,4,3],[1,2,0]), ([4,1,2],[0,3,5]), ([3,2,0],[4,1,5]), ([5,3,4],[2,1,0]), ([5,0,1],[4,3,2]), ([1,3,2],[0,5,4]), ([1,3,2],[4,0,5]), ([2,0,5],[4,3,1]), ([5,0,4],[2,3,1]), ([1,3,5],[2,0,4]), ([3,1,0],[2,4,5]), ([0,5,3],[1,2,4]), ([3,1,5],[4,2,0]), ([2,3,4],[0,1,5]), ([2,4,0],[3,1,5]), ([2,3,5],[1,4,0]), ([0,4,2],[5,3,1]), ([5,2,1],[3,4,0]), ([4,3,1],[0,2,5]), ([2,5,4],[1,0,3]), ([4,3,5],[1,0,2]), ([1,5,3],[0,2,4]), ([4,2,0],[5,1,3]), ([1,5,4],[0,3,2]), ([4,0,5],[2,1,3]), ([0,5,1],[3,4,2]), ([0,3,4],[2,1,5]), ([3,5,1],[2,4,0]), ([1,4,2],[0,5,3]), ([4,1,2],[5,0,3]), ([3,1,4],[2,0,5]), ([3,1,5],[2,4,0]), ([5,1,0],[2,4,3]), ([0,3,1],[4,2,5]), ([4,3,2],[0,1,5]), ([3,2,4],[1,5,0]), ([4,3,2],[5,0,1]), ([3,0,5],[1,4,2]), ([2,4,3],[5,0,1]), ([3,2,4],[0,1,5]), ([2,3,1],[5,4,0]), ([2,1,3],[4,5,0]), ([3,4,1],[5,2,0]), ([1,5,4],[0,2,3]), ([5,1,0],[3,2,4]), ([1,4,0],[3,2,5]), ([2,0,4],[1,5,3]), ([1,5,3],[0,4,2]), ([0,2,1],[5,3,4]), ([1,0,2],[5,3,4]), ([1,5,4],[3,2,0]), ([0,1,4],[5,2,3]), ([3,4,1],[0,5,2]), ([2,3,1],[5,0,4]), ([0,4,2],[5,3,1]), ([1,0,3],[5,2,4]), ([5,2,1],[3,4,0]), ([1,2,5],[0,3,4]), ([4,0,3],[5,2,1]), ([1,5,2],[3,4,0]), ([3,2,5],[0,4,1]), ([2,4,5],[1,0,3]), ([1,0,5],[3,4,2]), ([3,1,5],[2,0,4]), ([1,5,3],[4,2,0]), ([1,3,2],[0,5,4]), ([0,2,3],[4,1,5]), ([5,3,1],[0,2,4]), ([4,2,5],[3,1,0]), ([0,4,2],[3,5,1]), ([1,0,3],[5,2,4]), ([3,5,2],[0,1,4]), ([1,0,2],[4,3,5]), ([1,2,3],[5,0,4]), ([5,4,0],[3,1,2]), ([3,5,4],[1,0,2]), ([4,1,0],[2,5,3]), ([1,0,5],[4,3,2]), ([5,2,0],[4,1,3]), ([2,5,4],[0,1,3]), ([1,3,0],[2,5,4]), ([0,4,1],[3,5,2]), ([1,3,0],[4,5,2]), ([0,3,5],[4,1,2]), ([1,2,0],[3,5,4]), ([5,2,4],[1,0,3]), ([4,3,1],[5,0,2]), ([2,3,1],[0,4,5]), ([2,1,3],[4,5,0]), ([1,0,5],[3,4,2]), ([1,2,5],[4,0,3]), ([2,0,3],[5,1,4]), ([3,0,4],[2,1,5]), ([1,2,3],[4,0,5]), ([2,3,0],[1,4,5]), ([4,0,3],[5,1,2]), ([5,2,3],[1,4,0]), ([4,3,0],[2,1,5]), ([2,5,1],[0,4,3]), ([2,5,0],[3,1,4]), ([4,0,5],[1,3,2]), ([3,2,5],[0,4,1]), ([2,4,0],[1,3,5]), ([3,2,0],[5,1,4]), ([1,5,2],[3,4,0]), ([2,0,3],[1,5,4]), ([3,0,1],[4,5,2]), ([5,0,1],[4,3,2]), ([2,5,0],[4,3,1]), ([2,1,3],[5,0,4]), ([5,2,0],[1,3,4]), ([5,0,4],[3,2,1]), ([1,2,0],[5,3,4]), ([0,5,1],[2,3,4]), ([5,3,2],[4,1,0]), ([2,4,1],[0,3,5]), ([0,4,1],[2,3,5]), ([0,4,1],[2,3,5]), ([0,5,2],[4,1,3]), ([2,4,0],[1,5,3]), ([4,2,1],[0,5,3]), ([2,3,0],[4,1,5]), ([2,4,0],[3,1,5]), ([4,2,3],[5,0,1]), ([0,3,4],[5,2,1]), ([3,1,0],[2,5,4]), ([5,0,1],[2,4,3]), ([0,1,5],[3,2,4]), ([3,4,0],[5,2,1]), ([3,2,1],[5,0,4]), ([2,1,4],[5,3,0]), ([2,1,4],[3,5,0]), ([3,4,1],[5,2,0]), ([1,3,5],[2,0,4]), ([3,5,1],[0,4,2]), ([1,5,2],[3,0,4]), ([3,0,4],[2,5,1]), ([3,5,4],[2,1,0]), ([2,3,5],[0,1,4]), ([0,1,5],[2,3,4]), ([5,0,2],[3,4,1]), ([0,4,2],[1,5,3]), ([2,5,4],[3,0,1]), ([4,1,2],[5,0,3]), ([0,4,5],[2,3,1]), ([1,3,4],[5,2,0]), ([3,4,1],[5,0,2]), ([1,0,5],[2,3,4]), ([1,5,3],[2,4,0]), ([2,3,1],[0,5,4]), ([0,4,5],[3,2,1]), ([4,3,0],[2,1,5]), ([3,4,5],[2,0,1]), ([5,1,4],[2,0,3]), ([0,5,3],[2,1,4]), ([4,1,3],[5,2,0]), ([3,5,2],[4,0,1]), ([0,3,4],[2,1,5]), ([0,4,2],[1,3,5]), ([0,2,1],[5,3,4]), ([5,1,0],[2,3,4]), ([2,5,0],[1,4,3]), ([5,1,3],[0,2,4]), ([3,5,0],[4,2,1]), ([2,4,1],[5,3,0]), ([1,2,0],[4,3,5]), ([5,4,2],[3,1,0]), ([2,3,5],[0,4,1]), ([4,5,0],[3,2,1]), ([0,4,5],[2,1,3]), ([1,4,5],[0,2,3]), ([2,3,1],[5,0,4]), ([1,3,5],[0,2,4]), ([4,0,5],[3,1,2]), ([3,1,5],[0,4,2]), ([4,1,2],[5,0,3]), ([4,0,2],[5,3,1]), ([0,2,3],[1,5,4]), ([1,0,2],[3,5,4]), ([5,4,3],[0,1,2]), ([0,4,3],[1,5,2]), ([1,5,2],[0,3,4]), ([5,2,4],[1,3,0]), ([0,3,5],[4,1,2]), ([4,2,5],[0,3,1]), ([4,3,5],[1,2,0]), ([0,5,1],[4,3,2]), ([4,2,0],[1,5,3]), ([4,3,2],[5,0,1]), ([2,3,1],[5,4,0]), ([5,4,1],[0,2,3]), ([2,3,4],[1,5,0]), ([5,1,4],[3,0,2]), ([5,2,0],[4,1,3]), ([5,1,3],[2,0,4]), ([5,1,4],[3,2,0]), ([5,3,4],[1,0,2]), ([3,1,0],[5,4,2]), ([1,4,2],[3,0,5]), ([1,5,0],[4,3,2]), ([5,4,1],[0,3,2]), ([2,0,3],[1,5,4]), ([0,1,3],[4,2,5]), ([4,5,0],[3,2,1]), ([4,0,2],[1,5,3]), ([1,0,4],[2,5,3]), ([0,4,2],[5,3,1]), ([5,3,4],[2,1,0]), ([4,5,2],[3,0,1]), ([2,4,0],[3,1,5]), ([4,5,2],[1,3,0]), ([1,4,2],[0,5,3]), ([0,5,1],[4,3,2]), ([0,4,3],[2,1,5]), ([1,5,0],[3,2,4]), ([0,2,3],[5,1,4]), ([0,4,5],[1,3,2]), ([0,4,3],[1,2,5]), ([1,3,5],[2,4,0]), ([0,2,1],[4,3,5]), ([0,4,3],[2,5,1]), ([3,4,0],[2,1,5]), ([2,0,3],[1,5,4]), ([0,3,4],[1,2,5]), ([2,4,1],[5,0,3]), ([5,3,1],[2,0,4]), ([3,4,0],[5,2,1]), ([2,0,1],[4,5,3]), ([5,2,3],[1,4,0]), ([3,4,2],[0,5,1]), ([0,2,4],[5,3,1]), ([2,0,4],[3,5,1]), ([4,3,0],[2,5,1]), ([3,5,1],[4,0,2]), ([5,3,4],[0,1,2]), ([0,1,3],[2,4,5]), ([4,1,0],[5,2,3]), ([3,2,4],[0,5,1]), ([5,3,0],[2,4,1]), ([3,0,5],[2,4,1]), ([4,2,1],[5,3,0]), ([2,4,1],[3,5,0]), ([3,4,0],[1,2,5]), ([3,2,4],[0,5,1]), ([0,1,3],[2,5,4]), ([1,5,2],[3,4,0]), ([5,4,3],[1,2,0]), ([5,3,4],[0,2,1]), ([3,4,5],[0,2,1]), ([4,5,0],[2,1,3]), ([1,3,4],[2,5,0]), ([0,1,4],[5,3,2]), ([2,4,1],[3,0,5]), ([2,0,1],[3,5,4]), ([5,3,2],[4,1,0]), ([3,0,2],[1,4,5]), ([5,0,3],[2,1,4]), ([5,1,3],[0,4,2]), ([3,0,4],[1,2,5]), ([3,2,1],[5,0,4]), ([3,2,5],[0,1,4]), ([3,4,2],[0,5,1]), ([4,2,5],[1,3,0]), ([4,3,0],[2,1,5]), ([0,3,5],[4,1,2]), ([1,0,3],[4,5,2]), ([5,3,4],[1,2,0]), ([3,5,4],[0,1,2]), ([2,4,5],[0,3,1]), ([0,2,3],[5,4,1]), ([5,4,3],[1,0,2]), ([0,3,5],[4,2,1]), ([5,1,4],[0,2,3]), ([0,5,3],[2,1,4]), ([0,2,1],[5,4,3]), ([4,2,3],[1,0,5]), ([0,1,4],[2,5,3]), ([5,1,0],[2,3,4]), ([3,1,2],[0,5,4]), ([0,5,1],[3,4,2]), ([1,4,3],[5,0,2]), ([4,1,3],[2,0,5]), ([5,4,0],[2,3,1]), ([5,1,2],[3,0,4]), ([1,2,3],[0,5,4]), ([2,5,3],[0,1,4]), ([1,2,0],[5,4,3]), ([3,2,4],[0,1,5]), ([4,2,1],[5,0,3]), ([2,1,5],[0,3,4]), ([0,2,3],[5,4,1]), ([4,0,1],[2,5,3]), ([0,2,5],[3,1,4]), ([2,0,1],[4,5,3]), ([0,4,3],[2,5,1]), ([1,4,2],[5,3,0]), ([5,3,0],[2,1,4]), ([5,0,3],[2,1,4]), ([5,4,0],[1,2,3]), ([3,4,5],[2,0,1]), ([0,3,4],[1,5,2]), ([5,1,4],[3,2,0]), ([3,4,0],[2,5,1]), ([3,0,2],[4,1,5]), ([5,2,3],[0,1,4]), ([2,0,4],[3,5,1]), ([2,0,4],[5,3,1]), ([5,4,2],[3,0,1]), ([2,5,0],[4,1,3]), ([1,0,4],[3,5,2]), ([4,0,1],[2,3,5]), ([1,5,4],[3,2,0]), ([1,2,3],[4,5,0]), ([1,4,2],[5,0,3]), ([1,4,3],[5,0,2]), ([4,0,1],[3,2,5]), ([3,0,5],[1,2,4]), ([3,2,4],[5,1,0]), ([4,0,1],[2,5,3]), ([5,2,3],[4,0,1]), ([1,0,5],[2,4,3]), ([2,1,0],[3,5,4]), ([1,5,0],[4,2,3]), ([0,4,2],[3,1,5]), ([2,3,4],[5,0,1]), ([2,4,3],[5,1,0]), ([1,2,0],[5,4,3]), ([4,3,0],[5,2,1]), ([4,5,3],[0,1,2]), ([4,3,5],[2,0,1]), ([3,1,2],[4,0,5]), ([1,2,0],[4,5,3]), ([4,1,0],[3,5,2]), ([5,3,2],[0,1,4]), ([4,5,3],[1,2,0]), ([4,0,1],[5,3,2]), ([3,5,4],[0,2,1]), ([2,4,5],[0,1,3]), ([4,1,5],[3,2,0]), ([2,1,0],[3,4,5]), ([5,3,1],[0,2,4]), ([0,2,5],[3,1,4]), ([3,2,4],[0,5,1]), ([3,0,4],[1,2,5]), ([0,1,5],[4,2,3]), ([5,0,4],[3,2,1]), ([5,3,2],[0,1,4]), ([5,0,4],[2,3,1]), ([1,4,0],[2,3,5]), ([4,1,0],[2,3,5]), ([1,4,2],[0,3,5]), ([5,2,1],[3,0,4]), ([4,1,0],[2,3,5]), ([5,0,1],[4,3,2]), ([2,4,5],[1,0,3]), ([2,3,0],[5,4,1]), ([1,0,4],[3,5,2]), ([4,2,5],[0,3,1]), ([4,0,1],[2,5,3]), ([4,0,3],[2,5,1]), ([5,0,4],[3,1,2]), ([3,4,0],[1,5,2]), ([3,4,2],[0,1,5]), ([4,2,5],[0,1,3]), ([5,3,1],[0,2,4]), ([4,3,2],[1,0,5]), ([0,5,1],[2,4,3]), ([5,1,0],[3,4,2]), ([1,3,2],[4,5,0]), ([4,3,0],[5,2,1]), ([0,1,3],[5,2,4]), ([0,3,4],[2,5,1]), ([3,4,5],[0,1,2]), ([4,0,5],[3,2,1]), ([1,0,2],[5,4,3]), ([1,4,3],[5,2,0]), ([5,0,1],[4,2,3]), ([1,4,3],[0,2,5]), ([3,2,4],[1,5,0]), ([0,2,3],[4,1,5]), ([5,2,1],[4,0,3]), ([1,0,2],[5,4,3]), ([1,3,0],[5,4,2]), ([1,0,5],[2,3,4]), ([0,2,5],[1,4,3]), ([0,1,3],[4,2,5]), ([3,2,4],[1,0,5]), ([2,1,0],[4,3,5]), ([2,1,4],[3,5,0]), ([1,0,4],[2,3,5]), ([3,2,1],[5,4,0]), ([1,4,5],[2,3,0]), ([1,5,4],[2,0,3]), ([4,3,5],[2,0,1]), ([4,3,5],[0,1,2]), ([1,3,4],[2,5,0]), ([3,0,2],[4,1,5]), ([5,0,4],[2,1,3]), ([0,3,2],[5,4,1]), ([5,4,2],[3,1,0]), ([4,3,2],[0,5,1]), ([1,0,3],[5,4,2]), ([0,2,3],[1,4,5]), ([3,0,1],[5,4,2]), ([3,4,2],[0,1,5]), ([2,0,5],[1,4,3]), ([3,2,5],[4,0,1]), ([1,2,4],[5,3,0]), ([4,0,1],[2,5,3]), ([5,3,0],[4,2,1]), ([0,4,2],[3,5,1]), ([2,5,3],[1,4,0])] for x in perms: first = x[0] second = x[1] if sum([self.scores[y] for y in first]) == sum([self.scores[y] for y in second]): result = True break if result: self.result = "YES" else: self.result = "NO" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask890ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result())
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. Input Specification: The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants Output Specification: Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['1 3 2 1 2 1\n', '1 1 1 1 1 99\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
```python class CodeforcesTask890ASolution: def __init__(self): self.result = '' self.scores = [] def read_input(self): self.scores = [int(x) for x in input().split(" ")] def process_task(self): result = False perms = [([5,2,1],[0,4,3]), ([1,3,0],[5,4,2]), ([4,1,2],[3,0,5]), ([2,3,0],[4,1,5]), ([4,5,3],[1,2,0]), ([3,4,1],[5,0,2]), ([3,5,2],[1,4,0]), ([0,4,2],[5,1,3]), ([3,0,1],[4,2,5]), ([4,3,5],[2,0,1]), ([4,0,3],[1,2,5]), ([1,2,5],[3,0,4]), ([3,5,1],[0,4,2]), ([3,2,4],[0,1,5]), ([2,5,1],[0,3,4]), ([2,3,4],[1,0,5]), ([0,1,5],[3,2,4]), ([5,4,1],[0,2,3]), ([5,2,3],[0,1,4]), ([4,1,0],[3,2,5]), ([4,1,0],[5,2,3]), ([2,3,1],[4,0,5]), ([4,0,1],[2,3,5]), ([2,4,5],[3,1,0]), ([1,5,0],[3,2,4]), ([3,0,1],[4,5,2]), ([2,0,3],[1,4,5]), ([0,3,1],[2,5,4]), ([5,2,3],[1,4,0]), ([1,0,4],[3,2,5]), ([0,2,3],[4,5,1]), ([0,3,1],[2,4,5]), ([4,1,0],[3,5,2]), ([5,1,2],[3,0,4]), ([1,4,2],[0,3,5]), ([5,3,4],[0,2,1]), ([5,3,2],[0,1,4]), ([2,5,3],[1,4,0]), ([5,2,4],[0,3,1]), ([5,1,3],[0,4,2]), ([5,1,4],[3,2,0]), ([4,1,0],[2,3,5]), ([3,4,5],[2,1,0]), ([5,1,0],[4,3,2]), ([1,0,4],[3,2,5]), ([5,3,1],[4,0,2]), ([3,0,4],[5,2,1]), ([0,3,2],[4,1,5]), ([0,4,1],[2,3,5]), ([5,4,0],[2,3,1]), ([1,5,0],[4,3,2]), ([1,2,3],[0,5,4]), ([4,5,0],[3,2,1]), ([0,2,5],[1,3,4]), ([1,0,4],[5,3,2]), ([4,0,3],[2,1,5]), ([2,5,4],[0,1,3]), ([5,0,2],[1,4,3]), ([4,2,5],[0,3,1]), ([2,5,1],[4,3,0]), ([1,3,4],[0,2,5]), ([4,1,2],[0,3,5]), ([5,3,1],[2,0,4]), ([3,4,1],[2,5,0]), ([4,5,2],[3,0,1]), ([4,3,1],[2,5,0]), ([5,2,4],[0,1,3]), ([5,2,3],[0,1,4]), ([2,3,1],[5,0,4]), ([2,4,3],[1,0,5]), ([0,2,3],[1,4,5]), ([1,3,5],[4,0,2]), ([3,2,4],[5,0,1]), ([0,3,2],[4,1,5]), ([3,1,0],[2,4,5]), ([5,4,2],[3,0,1]), ([2,0,1],[5,3,4]), ([5,3,4],[0,2,1]), ([1,3,0],[2,4,5]), ([0,4,3],[5,2,1]), ([5,0,4],[2,1,3]), ([4,2,3],[1,0,5]), ([5,0,2],[1,3,4]), ([0,4,5],[3,1,2]), ([4,3,1],[2,5,0]), ([1,5,3],[4,2,0]), ([3,2,5],[0,4,1]), ([3,2,0],[4,1,5]), ([5,3,0],[2,4,1]), ([4,1,5],[2,3,0]), ([5,2,0],[3,4,1]), ([0,4,1],[3,2,5]), ([1,0,5],[4,2,3]), ([2,1,0],[4,3,5]), ([1,0,5],[3,2,4]), ([2,4,0],[5,3,1]), ([4,2,5],[0,1,3]), ([4,1,5],[0,2,3]), ([5,1,0],[2,4,3]), ([1,3,4],[2,5,0]), ([5,1,4],[0,2,3]), ([4,0,2],[5,3,1]), ([5,1,0],[3,4,2]), ([0,1,5],[2,4,3]), ([1,2,4],[5,3,0]), ([3,2,1],[4,0,5]), ([0,1,4],[3,5,2]), ([2,3,4],[5,0,1]), ([5,4,1],[2,0,3]), ([3,4,1],[2,0,5]), ([1,0,5],[3,4,2]), ([5,3,0],[4,1,2]), ([5,0,4],[2,3,1]), ([0,2,1],[3,4,5]), ([1,2,4],[0,3,5]), ([1,5,4],[2,0,3]), ([1,5,3],[4,2,0]), ([0,3,5],[1,2,4]), ([3,2,0],[5,4,1]), ([0,3,4],[1,5,2]), ([2,1,5],[3,4,0]), ([4,1,5],[0,3,2]), ([1,0,3],[5,2,4]), ([3,1,5],[2,4,0]), ([2,4,0],[3,5,1]), ([2,3,5],[0,1,4]), ([2,0,5],[1,3,4]), ([0,2,1],[3,5,4]), ([4,2,3],[1,5,0]), ([1,2,3],[4,5,0]), ([2,1,5],[0,3,4]), ([3,1,5],[2,0,4]), ([1,5,0],[4,3,2]), ([2,1,3],[0,5,4]), ([3,4,5],[2,1,0]), ([4,3,0],[1,5,2]), ([5,3,1],[0,4,2]), ([4,2,1],[0,5,3]), ([4,1,0],[2,5,3]), ([2,3,4],[1,0,5]), ([4,2,0],[5,1,3]), ([0,4,5],[1,3,2]), ([5,4,0],[3,2,1]), ([0,3,4],[1,2,5]), ([5,4,1],[2,3,0]), ([5,0,4],[3,2,1]), ([4,1,5],[2,0,3]), ([2,1,4],[3,5,0]), ([5,4,3],[2,0,1]), ([0,2,5],[4,1,3]), ([1,5,2],[3,4,0]), ([2,3,1],[4,0,5]), ([5,4,1],[0,2,3]), ([0,2,4],[5,1,3]), ([0,1,2],[5,3,4]), ([5,2,0],[3,4,1]), ([0,3,4],[1,5,2]), ([3,5,1],[4,0,2]), ([3,1,2],[0,5,4]), ([0,5,3],[1,4,2]), ([5,4,2],[0,1,3]), ([5,1,0],[4,3,2]), ([3,1,4],[5,2,0]), ([2,1,5],[3,4,0]), ([2,3,1],[0,4,5]), ([3,2,1],[0,4,5]), ([2,5,4],[0,1,3]), ([2,1,5],[0,4,3]), ([2,3,1],[5,4,0]), ([3,2,4],[5,0,1]), ([4,2,5],[3,1,0]), ([2,0,3],[1,5,4]), ([2,1,0],[4,5,3]), ([2,4,0],[1,3,5]), ([4,5,3],[0,2,1]), ([5,1,2],[4,3,0]), ([1,0,2],[5,3,4]), ([4,3,2],[5,0,1]), ([4,3,5],[1,2,0]), ([1,5,4],[3,0,2]), ([1,4,2],[5,0,3]), ([2,3,5],[4,0,1]), ([4,0,1],[3,2,5]), ([1,4,0],[3,5,2]), ([3,2,1],[4,5,0]), ([1,2,4],[0,5,3]), ([3,2,1],[5,0,4]), ([0,4,5],[1,3,2]), ([1,3,2],[5,0,4]), ([5,4,3],[1,2,0]), ([3,5,4],[2,1,0]), ([4,3,0],[1,5,2]), ([0,1,5],[2,3,4]), ([5,4,2],[1,3,0]), ([4,2,1],[0,3,5]), ([5,3,1],[4,0,2]), ([5,2,3],[1,0,4]), ([2,0,4],[5,3,1]), ([2,3,1],[0,4,5]), ([5,0,2],[4,3,1]), ([0,1,4],[5,2,3]), ([5,3,1],[2,0,4]), ([1,5,3],[4,2,0]), ([3,4,1],[2,0,5]), ([0,3,2],[5,4,1]), ([5,0,1],[2,3,4]), ([1,2,4],[0,3,5]), ([1,5,2],[4,3,0]), ([3,5,0],[4,2,1]), ([4,0,2],[3,5,1]), ([1,4,5],[0,3,2]), ([1,0,2],[4,3,5]), ([5,0,1],[4,3,2]), ([2,0,5],[4,1,3]), ([4,3,5],[0,2,1]), ([4,5,0],[2,1,3]), ([2,5,1],[4,3,0]), ([0,3,5],[1,4,2]), ([0,2,1],[5,3,4]), ([2,5,3],[0,1,4]), ([2,3,4],[0,1,5]), ([3,0,5],[2,4,1]), ([0,1,2],[4,3,5]), ([3,0,2],[1,5,4]), ([1,3,0],[4,2,5]), ([5,3,2],[0,1,4]), ([0,1,5],[2,3,4]), ([0,1,3],[2,4,5]), ([4,5,2],[0,1,3]), ([0,2,5],[4,3,1]), ([3,5,2],[0,4,1]), ([5,0,1],[2,3,4]), ([5,1,0],[3,4,2]), ([0,1,2],[3,5,4]), ([1,5,0],[3,2,4]), ([1,0,4],[3,5,2]), ([3,4,0],[1,5,2]), ([5,0,3],[2,4,1]), ([2,4,0],[1,5,3]), ([3,5,2],[0,1,4]), ([3,0,5],[4,2,1]), ([5,1,0],[4,2,3]), ([5,2,4],[3,0,1]), ([4,2,1],[5,0,3]), ([0,3,5],[4,2,1]), ([2,3,0],[4,5,1]), ([0,4,3],[1,2,5]), ([2,5,1],[4,3,0]), ([5,1,2],[3,0,4]), ([3,2,1],[4,0,5]), ([2,0,4],[5,3,1]), ([0,4,3],[2,5,1]), ([4,0,1],[5,2,3]), ([0,5,2],[4,1,3]), ([3,4,2],[5,1,0]), ([4,1,0],[2,5,3]), ([4,3,0],[2,1,5]), ([5,4,3],[0,1,2]), ([2,0,3],[4,1,5]), ([5,3,4],[2,0,1]), ([5,1,3],[2,0,4]), ([5,0,1],[4,3,2]), ([3,5,4],[0,1,2]), ([5,3,4],[1,2,0]), ([2,5,4],[1,0,3]), ([3,5,4],[0,1,2]), ([5,3,0],[1,4,2]), ([5,2,0],[1,3,4]), ([2,3,4],[0,5,1]), ([0,4,3],[2,5,1]), ([4,5,1],[3,2,0]), ([4,3,2],[1,0,5]), ([4,1,2],[5,0,3]), ([0,4,5],[1,3,2]), ([5,0,3],[4,2,1]), ([1,2,3],[5,4,0]), ([3,4,2],[1,0,5]), ([3,0,5],[4,1,2]), ([0,4,3],[2,5,1]), ([2,3,5],[1,4,0]), ([2,1,0],[5,3,4]), ([5,4,2],[1,3,0]), ([4,2,1],[0,5,3]), ([1,5,2],[4,0,3]), ([0,5,1],[2,3,4]), ([0,1,5],[4,3,2]), ([2,3,5],[4,0,1]), ([3,5,0],[1,2,4]), ([3,1,2],[4,0,5]), ([2,4,0],[5,1,3]), ([1,2,4],[5,0,3]), ([4,0,3],[5,2,1]), ([4,2,5],[0,1,3]), ([3,0,1],[4,5,2]), ([3,0,5],[2,4,1]), ([4,0,1],[3,5,2]), ([2,1,4],[0,3,5]), ([0,4,1],[3,5,2]), ([0,3,4],[2,1,5]), ([5,4,0],[3,1,2]), ([5,4,1],[3,2,0]), ([2,1,0],[4,3,5]), ([2,3,1],[4,5,0]), ([4,3,1],[2,5,0]), ([5,1,4],[2,3,0]), ([4,2,1],[5,0,3]), ([3,5,1],[0,2,4]), ([2,1,4],[3,0,5]), ([0,3,4],[2,5,1]), ([4,5,3],[1,2,0]), ([3,0,5],[2,1,4]), ([3,5,2],[1,0,4]), ([0,5,2],[1,3,4]), ([5,1,3],[4,0,2]), ([4,5,1],[3,0,2]), ([1,0,3],[5,2,4]), ([2,4,5],[1,3,0]), ([3,5,4],[2,0,1]), ([2,1,4],[5,0,3]), ([2,3,4],[1,5,0]), ([1,0,2],[5,3,4]), ([4,3,1],[2,0,5]), ([0,1,2],[5,4,3]), ([3,2,5],[4,0,1]), ([4,5,3],[1,0,2]), ([0,1,2],[3,4,5]), ([4,1,0],[3,2,5]), ([1,4,3],[2,0,5]), ([3,5,0],[2,1,4]), ([3,1,2],[0,5,4]), ([1,2,0],[5,4,3]), ([2,4,0],[1,3,5]), ([1,4,3],[0,2,5]), ([1,4,2],[5,0,3]), ([0,5,1],[4,2,3]), ([1,0,4],[2,5,3]), ([5,1,2],[3,4,0]), ([4,3,5],[0,2,1]), ([2,4,5],[0,1,3]), ([4,0,2],[5,1,3]), ([0,2,1],[4,3,5]), ([2,1,4],[3,0,5]), ([2,3,0],[5,4,1]), ([4,0,2],[1,3,5]), ([2,0,5],[3,1,4]), ([0,3,2],[4,1,5]), ([0,4,3],[2,1,5]), ([3,1,2],[5,0,4]), ([4,1,0],[5,2,3]), ([1,4,2],[5,0,3]), ([3,2,5],[4,1,0]), ([0,3,5],[4,1,2]), ([5,3,2],[1,4,0]), ([5,2,4],[3,0,1]), ([3,0,4],[2,1,5]), ([2,3,1],[5,0,4]), ([0,3,4],[2,1,5]), ([0,2,4],[3,5,1]), ([5,2,1],[0,4,3]), ([5,4,0],[1,2,3]), ([1,2,0],[5,4,3]), ([1,2,4],[3,5,0]), ([1,5,2],[4,3,0]), ([2,3,1],[5,0,4]), ([1,0,5],[3,4,2]), ([5,3,4],[2,0,1]), ([0,5,2],[3,4,1]), ([1,3,4],[5,2,0]), ([4,2,0],[1,5,3]), ([4,2,3],[5,0,1]), ([0,3,1],[2,5,4]), ([0,5,4],[3,1,2]), ([4,2,3],[1,5,0]), ([1,0,5],[3,2,4]), ([3,4,1],[2,0,5]), ([1,2,5],[0,3,4]), ([0,1,3],[2,4,5]), ([1,5,4],[2,3,0]), ([1,3,2],[0,5,4]), ([5,2,3],[0,1,4]), ([5,0,4],[1,3,2]), ([0,2,4],[1,3,5]), ([2,4,3],[1,0,5]), ([3,0,4],[2,1,5]), ([4,0,2],[3,5,1]), ([3,1,2],[5,4,0]), ([5,4,1],[0,3,2]), ([5,0,4],[1,3,2]), ([4,0,2],[1,5,3]), ([5,0,3],[2,1,4]), ([2,3,4],[1,5,0]), ([5,0,2],[4,3,1]), ([4,0,3],[2,5,1]), ([4,2,1],[0,3,5]), ([4,1,0],[5,2,3]), ([2,3,5],[4,1,0]), ([5,0,2],[4,3,1]), ([4,1,0],[3,5,2]), ([4,0,3],[1,5,2]), ([0,2,3],[5,4,1]), ([3,5,2],[0,4,1]), ([1,3,4],[0,5,2]), ([3,2,1],[4,0,5]), ([3,4,5],[0,1,2]), ([1,5,4],[0,3,2]), ([0,4,5],[3,2,1]), ([5,4,2],[0,3,1]), ([2,0,3],[4,1,5]), ([2,5,1],[4,0,3]), ([3,5,0],[4,2,1]), ([0,1,3],[4,5,2]), ([0,2,4],[5,3,1]), ([3,1,5],[4,2,0]), ([3,1,0],[2,5,4]), ([5,4,2],[1,0,3]), ([5,2,0],[3,1,4]), ([0,4,1],[5,3,2]), ([5,3,4],[2,0,1]), ([0,5,2],[4,3,1]), ([2,4,1],[5,0,3]), ([4,2,5],[3,0,1]), ([1,3,0],[4,2,5]), ([1,2,3],[4,0,5]), ([5,1,2],[0,4,3]), ([3,1,0],[2,4,5]), ([1,0,3],[4,2,5]), ([3,1,2],[5,4,0]), ([0,5,1],[3,2,4]), ([4,0,5],[1,2,3]), ([0,2,1],[3,5,4]), ([4,0,2],[3,1,5]), ([0,2,4],[3,1,5]), ([3,4,5],[0,1,2]), ([2,1,4],[0,5,3]), ([5,1,4],[2,3,0]), ([4,2,5],[1,3,0]), ([5,0,2],[1,4,3]), ([1,3,5],[0,4,2]), ([2,5,3],[1,0,4]), ([3,1,2],[5,0,4]), ([3,1,5],[0,4,2]), ([3,1,5],[2,0,4]), ([0,1,4],[5,3,2]), ([4,5,2],[0,1,3]), ([0,4,2],[3,1,5]), ([2,5,0],[4,3,1]), ([2,3,0],[4,5,1]), ([0,5,2],[4,1,3]), ([2,3,4],[0,5,1]), ([0,3,5],[4,1,2]), ([4,5,3],[2,1,0]), ([3,1,4],[0,2,5]), ([0,1,4],[3,2,5]), ([5,3,4],[0,1,2]), ([0,4,5],[2,3,1]), ([0,3,4],[2,1,5]), ([1,4,5],[2,0,3]), ([2,4,0],[3,1,5]), ([0,5,2],[4,3,1]), ([5,0,1],[4,2,3]), ([5,3,4],[1,0,2]), ([0,2,5],[1,4,3]), ([2,1,3],[4,0,5]), ([5,1,3],[2,4,0]), ([4,3,0],[1,2,5]), ([3,0,5],[2,1,4]), ([4,0,3],[5,1,2]), ([4,1,0],[3,2,5]), ([1,4,5],[3,0,2]), ([3,5,1],[0,2,4]), ([3,2,5],[0,1,4]), ([4,2,1],[0,3,5]), ([1,2,4],[5,3,0]), ([2,4,0],[5,3,1]), ([0,3,1],[4,2,5]), ([0,4,2],[5,1,3]), ([3,5,1],[2,4,0]), ([3,1,5],[2,4,0]), ([2,5,3],[1,4,0]), ([2,4,0],[5,3,1]), ([3,2,0],[4,5,1]), ([4,2,3],[1,5,0]), ([5,0,4],[3,1,2]), ([5,4,1],[2,3,0]), ([0,5,4],[2,3,1]), ([3,5,1],[4,0,2]), ([3,5,1],[0,2,4]), ([1,2,0],[3,5,4]), ([3,0,2],[4,5,1]), ([3,4,1],[0,5,2]), ([0,3,4],[2,5,1]), ([5,1,4],[0,3,2]), ([2,4,5],[3,1,0]), ([0,5,4],[3,2,1]), ([4,2,5],[1,0,3]), ([0,2,5],[3,4,1]), ([2,1,0],[3,5,4]), ([4,1,0],[3,5,2]), ([1,0,5],[4,3,2]), ([2,4,3],[1,5,0]), ([5,2,0],[4,1,3]), ([3,5,0],[4,2,1]), ([3,0,2],[4,1,5]), ([3,5,0],[4,2,1]), ([2,4,3],[0,1,5]), ([1,4,2],[3,0,5]), ([3,4,5],[1,0,2]), ([0,5,1],[3,4,2]), ([5,2,1],[0,3,4]), ([0,2,5],[4,3,1]), ([1,2,0],[3,4,5]), ([0,2,4],[1,5,3]), ([4,5,2],[3,1,0]), ([5,3,2],[0,1,4]), ([2,3,0],[4,5,1]), ([4,1,0],[2,5,3]), ([5,4,0],[1,2,3]), ([2,5,3],[1,4,0]), ([3,0,2],[5,1,4]), ([1,2,5],[4,3,0]), ([5,4,1],[3,2,0]), ([2,0,5],[1,4,3]), ([3,2,0],[4,1,5]), ([5,3,2],[4,0,1]), ([0,2,5],[1,3,4]), ([0,3,5],[4,1,2]), ([5,1,0],[4,2,3]), ([2,5,3],[4,0,1]), ([5,2,4],[1,3,0]), ([5,4,0],[3,1,2]), ([0,5,3],[4,1,2]), ([4,5,3],[1,0,2]), ([2,0,3],[5,4,1]), ([1,0,5],[2,3,4]), ([2,3,0],[1,5,4]), ([1,2,4],[5,0,3]), ([4,0,1],[3,5,2]), ([4,2,0],[5,3,1]), ([4,1,3],[2,0,5]), ([1,3,2],[4,5,0]), ([1,5,0],[4,2,3]), ([5,4,2],[0,3,1]), ([2,1,0],[5,4,3]), ([4,0,3],[1,2,5]), ([5,0,4],[2,3,1]), ([4,3,1],[5,2,0]), ([4,3,5],[1,0,2]), ([5,3,0],[4,1,2]), ([2,3,0],[5,1,4]), ([0,5,3],[1,2,4]), ([0,2,1],[5,4,3]), ([4,1,2],[5,0,3]), ([2,4,0],[1,3,5]), ([3,5,1],[2,0,4]), ([5,4,2],[0,1,3]), ([2,5,3],[0,1,4]), ([0,5,2],[1,3,4]), ([4,1,2],[0,3,5]), ([1,5,3],[2,4,0]), ([3,5,1],[4,2,0]), ([5,2,4],[0,1,3]), ([4,1,5],[0,3,2]), ([2,4,0],[1,3,5]), ([3,5,2],[0,4,1]), ([2,3,4],[5,1,0]), ([1,0,4],[3,5,2]), ([3,1,5],[4,2,0]), ([2,4,1],[3,0,5]), ([0,4,1],[3,2,5]), ([0,4,1],[2,3,5]), ([5,0,4],[3,1,2]), ([2,1,3],[4,5,0]), ([4,1,0],[2,3,5]), ([0,2,5],[3,4,1]), ([3,0,4],[1,5,2]), ([5,1,2],[4,0,3]), ([5,0,1],[3,2,4]), ([5,2,4],[3,0,1]), ([1,4,5],[3,0,2]), ([4,3,5],[2,0,1]), ([5,1,4],[3,2,0]), ([2,5,0],[4,3,1]), ([4,5,1],[0,2,3]), ([4,1,0],[2,5,3]), ([2,5,0],[3,1,4]), ([4,5,0],[1,3,2]), ([1,2,5],[4,3,0]), ([2,3,5],[4,1,0]), ([1,4,5],[0,2,3]), ([1,4,2],[3,5,0]), ([5,1,2],[3,0,4]), ([0,5,2],[1,3,4]), ([0,1,5],[2,4,3]), ([4,3,5],[2,1,0]), ([5,4,2],[1,3,0]), ([0,1,4],[2,3,5]), ([3,5,2],[0,1,4]), ([1,3,4],[5,2,0]), ([0,1,2],[3,5,4]), ([3,1,4],[5,2,0]), ([4,5,3],[0,2,1]), ([4,0,1],[5,2,3]), ([0,3,4],[5,2,1]), ([4,3,5],[1,0,2]), ([4,0,1],[2,3,5]), ([0,5,1],[2,3,4]), ([1,2,3],[0,4,5]), ([3,2,1],[5,4,0]), ([5,2,1],[4,3,0]), ([2,0,1],[3,4,5]), ([5,3,0],[1,2,4]), ([2,1,4],[0,3,5]), ([1,5,3],[2,4,0]), ([2,3,0],[4,5,1]), ([4,3,5],[0,1,2]), ([5,3,1],[0,2,4]), ([2,5,0],[3,1,4]), ([5,4,1],[2,3,0]), ([1,4,5],[2,3,0]), ([0,5,3],[1,4,2]), ([3,4,5],[2,1,0]), ([4,5,2],[1,0,3]), ([2,0,1],[4,3,5]), ([2,1,3],[0,5,4]), ([2,5,0],[4,3,1]), ([1,4,2],[0,3,5]), ([0,2,5],[3,4,1]), ([2,5,1],[3,4,0]), ([4,2,5],[1,0,3]), ([0,3,5],[2,4,1]), ([2,0,3],[1,4,5]), ([2,1,0],[4,5,3]), ([5,4,1],[3,0,2]), ([2,3,5],[0,4,1]), ([0,4,5],[1,3,2]), ([0,4,2],[1,5,3]), ([3,4,0],[1,5,2]), ([3,4,0],[5,2,1]), ([3,0,1],[4,5,2]), ([5,1,4],[2,3,0]), ([5,0,1],[4,2,3]), ([1,4,3],[2,5,0]), ([0,5,1],[4,3,2]), ([2,4,0],[5,3,1]), ([2,1,5],[4,0,3]), ([5,1,4],[3,2,0]), ([2,5,0],[4,3,1]), ([5,0,1],[3,4,2]), ([2,5,3],[0,1,4]), ([3,5,0],[2,4,1]), ([1,2,0],[4,3,5]), ([4,1,0],[2,5,3]), ([2,0,3],[5,4,1]), ([0,3,1],[5,2,4]), ([5,3,2],[0,1,4]), ([0,4,1],[3,2,5]), ([5,0,3],[2,4,1]), ([0,1,4],[2,3,5]), ([4,5,2],[3,1,0]), ([3,4,1],[2,5,0]), ([3,5,2],[0,1,4]), ([3,0,4],[5,2,1]), ([1,0,4],[3,5,2]), ([0,3,2],[5,4,1]), ([1,5,2],[3,4,0]), ([1,0,2],[3,4,5]), ([3,0,4],[5,1,2]), ([2,0,3],[5,1,4]), ([4,3,5],[0,1,2]), ([1,5,4],[3,0,2]), ([0,2,4],[3,5,1]), ([0,1,4],[3,5,2]), ([5,3,0],[1,4,2]), ([2,3,5],[1,4,0]), ([3,5,4],[1,0,2]), ([0,1,5],[2,3,4]), ([1,0,4],[3,2,5]), ([0,5,1],[3,4,2]), ([5,2,3],[4,1,0]), ([5,0,2],[1,3,4]), ([0,4,2],[3,5,1]), ([3,1,5],[0,2,4]), ([4,5,3],[2,1,0]), ([3,4,2],[0,1,5]), ([3,1,0],[2,4,5]), ([4,1,2],[3,0,5]), ([5,1,2],[0,4,3]), ([5,1,0],[3,4,2]), ([3,0,4],[1,2,5]), ([0,5,4],[1,2,3]), ([2,1,4],[5,0,3]), ([2,1,5],[3,4,0]), ([5,0,4],[3,2,1]), ([1,3,0],[2,5,4]), ([4,3,0],[1,5,2]), ([0,3,2],[5,4,1]), ([4,0,1],[5,2,3]), ([5,4,3],[0,2,1]), ([5,0,1],[3,4,2]), ([0,5,1],[3,2,4]), ([5,3,1],[2,0,4]), ([1,0,3],[5,2,4]), ([3,5,2],[1,0,4]), ([5,2,0],[1,3,4]), ([2,1,4],[3,5,0]), ([0,2,1],[4,3,5]), ([5,2,1],[3,4,0]), ([4,5,3],[1,0,2]), ([0,1,5],[2,4,3]), ([1,3,4],[2,5,0]), ([2,5,1],[4,0,3]), ([1,0,4],[2,3,5]), ([1,3,0],[5,2,4]), ([3,5,1],[0,2,4]), ([2,1,5],[3,4,0]), ([3,1,4],[2,5,0]), ([2,3,0],[5,1,4]), ([1,4,5],[2,0,3]), ([1,2,3],[5,4,0]), ([5,0,2],[3,4,1]), ([1,0,5],[2,3,4]), ([0,1,5],[4,2,3]), ([1,0,3],[5,2,4]), ([1,4,0],[3,2,5]), ([4,1,5],[2,0,3]), ([1,2,0],[4,3,5]), ([0,2,4],[5,3,1]), ([1,2,0],[5,3,4]), ([1,3,4],[5,0,2]), ([4,0,2],[3,5,1]), ([4,2,0],[3,5,1]), ([2,3,5],[0,4,1]), ([1,0,3],[2,4,5]), ([0,3,5],[1,4,2]), ([0,3,5],[2,4,1]), ([4,1,2],[0,5,3]), ([2,4,5],[0,3,1]), ([0,3,4],[1,5,2]), ([2,3,1],[0,5,4]), ([2,0,1],[5,3,4]), ([2,0,1],[5,3,4]), ([2,4,3],[0,5,1]), ([3,4,1],[0,5,2]), ([1,4,5],[0,3,2]), ([4,0,5],[2,1,3]), ([2,4,5],[3,0,1]), ([1,3,2],[4,0,5]), ([0,1,3],[2,4,5]), ([3,2,5],[4,0,1]), ([4,0,5],[2,3,1]), ([1,2,0],[5,4,3]), ([4,2,0],[1,3,5]), ([0,1,3],[2,4,5]), ([0,5,3],[1,4,2]), ([4,2,0],[3,1,5]), ([0,2,4],[1,3,5]), ([0,2,4],[5,1,3]), ([4,2,1],[0,5,3]), ([4,3,2],[1,5,0]), ([1,0,5],[4,2,3]), ([3,0,5],[4,2,1]), ([2,5,1],[4,3,0]), ([4,0,1],[3,2,5]), ([5,3,0],[1,2,4]), ([5,1,3],[2,0,4]), ([2,5,4],[0,3,1]), ([1,5,0],[2,4,3]), ([2,5,4],[3,1,0]), ([1,0,3],[2,4,5]), ([0,3,4],[2,5,1]), ([2,0,3],[1,4,5]), ([4,3,5],[2,0,1]), ([4,3,2],[1,0,5]), ([0,3,4],[1,5,2]), ([2,5,4],[3,0,1]), ([4,2,0],[3,1,5]), ([4,3,2],[5,0,1]), ([3,2,1],[4,5,0]), ([4,2,3],[5,1,0]), ([1,5,2],[3,0,4]), ([1,3,4],[2,0,5]), ([0,4,3],[2,1,5]), ([2,0,3],[4,5,1]), ([4,5,1],[3,2,0]), ([5,0,4],[3,2,1]), ([3,5,2],[4,1,0]), ([2,0,3],[1,5,4]), ([3,5,0],[4,1,2]), ([4,0,5],[1,3,2]), ([3,2,4],[5,1,0]), ([1,0,4],[3,2,5]), ([3,1,5],[0,4,2]), ([3,1,0],[2,5,4]), ([0,5,4],[3,2,1]), ([5,1,3],[2,0,4]), ([3,4,1],[0,2,5]), ([2,5,1],[0,4,3]), ([3,2,5],[0,4,1]), ([2,4,3],[1,5,0]), ([0,4,5],[3,2,1]), ([4,0,2],[1,3,5]), ([2,1,0],[4,3,5]), ([2,3,4],[0,5,1]), ([0,4,5],[1,3,2]), ([0,4,3],[5,1,2]), ([2,1,3],[0,4,5]), ([0,3,5],[1,2,4]), ([3,5,2],[1,4,0]), ([5,2,3],[0,1,4]), ([2,3,1],[0,4,5]), ([1,3,5],[0,2,4]), ([1,5,2],[3,0,4]), ([0,1,4],[2,5,3]), ([1,3,0],[4,5,2]), ([1,4,5],[3,0,2]), ([2,5,4],[0,1,3]), ([3,4,2],[1,0,5]), ([5,2,1],[4,0,3]), ([4,1,2],[5,3,0]), ([1,4,3],[2,5,0]), ([5,1,0],[3,4,2]), ([3,1,4],[2,0,5]), ([3,4,5],[1,0,2]), ([1,4,5],[2,0,3]), ([5,4,3],[0,1,2]), ([3,0,1],[4,2,5]), ([2,1,3],[4,5,0]), ([4,0,2],[3,1,5]), ([2,0,5],[1,4,3]), ([4,3,0],[5,1,2]), ([3,0,5],[2,1,4]), ([1,0,4],[5,2,3]), ([1,4,0],[3,5,2]), ([2,4,1],[5,0,3]), ([5,3,2],[1,4,0]), ([4,1,3],[2,0,5]), ([2,4,0],[5,3,1]), ([3,4,2],[1,0,5]), ([3,2,0],[4,1,5]), ([0,2,5],[3,1,4]), ([3,0,2],[5,1,4]), ([4,3,0],[5,1,2]), ([5,2,1],[3,4,0]), ([5,2,4],[3,1,0]), ([0,3,5],[1,2,4]), ([3,2,0],[4,1,5]), ([0,2,5],[4,1,3]), ([0,4,3],[5,2,1]), ([5,3,0],[1,4,2]), ([4,3,1],[5,0,2]), ([5,0,4],[1,3,2]), ([2,3,0],[4,1,5]), ([3,2,1],[5,4,0]), ([0,2,5],[3,4,1]), ([5,1,2],[3,4,0]), ([0,1,3],[4,5,2]), ([5,0,2],[3,4,1]), ([2,4,3],[1,5,0]), ([0,5,2],[4,3,1]), ([2,3,1],[5,0,4]), ([5,0,3],[4,1,2]), ([3,1,4],[2,0,5]), ([5,0,4],[3,2,1]), ([5,3,1],[0,2,4]), ([2,0,5],[4,3,1]), ([2,5,0],[4,3,1]), ([1,3,0],[5,2,4]), ([1,0,4],[2,3,5]), ([0,1,2],[5,4,3]), ([1,0,4],[3,5,2]), ([3,2,0],[4,5,1]), ([4,3,2],[1,5,0]), ([5,2,4],[1,0,3]), ([5,1,2],[3,4,0]), ([2,5,0],[3,1,4]), ([4,0,1],[3,2,5]), ([3,0,4],[2,1,5]), ([2,1,0],[3,4,5]), ([3,1,5],[2,0,4]), ([1,3,5],[0,2,4]), ([5,1,3],[4,2,0]), ([0,4,3],[1,5,2]), ([1,3,2],[0,4,5]), ([0,4,5],[1,2,3]), ([2,3,5],[4,1,0]), ([4,3,0],[5,1,2]), ([0,5,2],[1,3,4]), ([0,5,2],[4,3,1]), ([2,4,3],[5,0,1]), ([4,0,1],[5,3,2]), ([4,3,0],[2,5,1]), ([3,4,2],[1,0,5]), ([2,5,4],[3,1,0]), ([0,1,2],[4,3,5]), ([5,2,0],[1,4,3]), ([2,0,3],[5,4,1]), ([1,2,0],[5,3,4]), ([3,0,4],[1,2,5]), ([0,1,5],[2,3,4]), ([4,2,0],[3,1,5]), ([2,3,4],[5,0,1]), ([4,2,1],[5,0,3]), ([2,0,3],[1,5,4]), ([1,3,4],[0,2,5]), ([3,1,2],[0,4,5]), ([5,1,4],[2,3,0]), ([5,2,1],[0,3,4]), ([1,4,5],[3,2,0]), ([0,3,2],[4,5,1]), ([3,5,0],[1,4,2]), ([5,4,2],[3,1,0]), ([5,2,1],[4,0,3]), ([3,0,1],[5,2,4]), ([4,2,3],[0,1,5]), ([3,2,1],[4,0,5]), ([0,2,5],[3,4,1]), ([0,5,1],[2,3,4]), ([3,0,2],[5,4,1]), ([4,0,3],[1,2,5]), ([1,2,5],[4,3,0]), ([3,1,5],[4,2,0]), ([3,0,1],[4,5,2]), ([0,2,1],[4,5,3]), ([4,3,5],[2,0,1]), ([5,4,2],[3,1,0]), ([3,4,0],[5,1,2]), ([3,1,5],[2,0,4]), ([5,1,4],[2,0,3]), ([0,1,2],[4,5,3]), ([3,2,1],[0,4,5]), ([1,3,2],[4,5,0]), ([1,4,2],[5,0,3]), ([5,0,1],[2,3,4]), ([1,4,3],[0,5,2]), ([4,2,3],[0,5,1]), ([1,4,5],[0,3,2]), ([4,2,3],[5,0,1]), ([3,4,2],[0,5,1]), ([1,0,2],[4,3,5]), ([4,1,3],[0,2,5]), ([3,0,2],[5,4,1]), ([1,5,0],[3,4,2]), ([5,0,4],[3,1,2]), ([2,4,0],[3,1,5]), ([4,3,1],[2,5,0]), ([3,5,1],[4,0,2]), ([3,4,5],[1,0,2]), ([3,1,2],[5,0,4]), ([5,4,1],[2,0,3]), ([1,3,0],[5,4,2]), ([2,0,1],[4,5,3]), ([0,5,3],[1,4,2]), ([1,5,4],[2,0,3]), ([0,2,5],[4,3,1]), ([3,5,4],[1,2,0]), ([0,3,4],[2,5,1]), ([5,0,4],[3,1,2]), ([2,0,4],[3,1,5]), ([4,2,3],[0,1,5]), ([3,4,0],[2,1,5]), ([3,4,5],[0,1,2]), ([0,3,4],[5,2,1]), ([5,2,3],[4,0,1]), ([4,1,2],[0,5,3]), ([3,4,2],[5,1,0]), ([3,5,0],[4,2,1]), ([4,5,3],[1,2,0]), ([3,4,2],[0,1,5]), ([1,5,0],[4,3,2]), ([0,5,4],[3,2,1]), ([3,2,4],[5,1,0]), ([2,0,1],[5,4,3]), ([4,5,3],[2,1,0]), ([5,0,3],[1,2,4]), ([2,5,1],[4,3,0]), ([2,3,1],[5,0,4]), ([4,3,5],[2,1,0]), ([0,3,1],[5,2,4]), ([0,4,2],[5,3,1]), ([3,4,1],[0,5,2]), ([2,4,0],[3,5,1]), ([2,3,5],[0,4,1]), ([4,5,2],[3,0,1]), ([1,5,0],[4,3,2]), ([4,2,1],[0,5,3]), ([2,0,4],[1,5,3]), ([4,5,1],[3,0,2]), ([3,5,4],[1,2,0]), ([5,2,3],[4,0,1]), ([3,4,0],[5,1,2]), ([4,3,1],[0,2,5]), ([5,2,3],[1,0,4]), ([4,5,1],[3,2,0]), ([5,0,4],[1,2,3]), ([2,4,0],[1,5,3]), ([2,4,5],[3,0,1]), ([1,5,2],[3,4,0]), ([2,3,0],[4,1,5]), ([4,3,2],[1,0,5]), ([0,1,4],[5,3,2]), ([1,4,3],[2,5,0]), ([0,1,4],[5,2,3]), ([4,2,5],[1,3,0]), ([5,4,0],[1,3,2]), ([0,1,2],[4,3,5]), ([4,3,0],[2,5,1]), ([4,5,2],[1,0,3]), ([0,1,3],[2,5,4]), ([5,1,0],[4,3,2]), ([1,5,0],[3,2,4]), ([2,3,1],[0,4,5]), ([4,5,3],[2,0,1]), ([4,1,3],[2,0,5]), ([0,2,4],[1,5,3]), ([4,0,1],[3,2,5]), ([0,3,2],[1,4,5]), ([3,0,5],[1,2,4]), ([5,1,0],[4,3,2]), ([4,2,5],[1,3,0]), ([5,2,0],[4,3,1]), ([3,5,2],[4,0,1]), ([5,4,2],[1,3,0]), ([1,2,5],[4,3,0]), ([4,0,2],[1,5,3]), ([0,2,3],[5,1,4]), ([1,3,0],[5,4,2]), ([1,3,5],[0,2,4]), ([2,1,0],[4,3,5]), ([3,2,5],[1,4,0]), ([4,2,5],[0,1,3]), ([3,0,2],[4,1,5]), ([1,5,4],[2,0,3]), ([3,0,5],[4,1,2]), ([3,4,0],[2,1,5]), ([2,0,5],[3,1,4]), ([4,1,5],[2,3,0]), ([4,3,1],[0,2,5]), ([2,5,0],[3,4,1]), ([3,4,2],[5,0,1]), ([2,0,5],[1,4,3]), ([0,1,2],[4,3,5]), ([5,1,0],[3,2,4]), ([1,4,0],[5,3,2]), ([2,3,4],[1,0,5]), ([2,0,4],[1,3,5]), ([1,3,5],[4,0,2]), ([3,4,0],[5,1,2]), ([5,3,0],[2,1,4]), ([4,0,5],[3,1,2]), ([4,0,5],[1,3,2]), ([3,5,0],[1,4,2]), ([5,0,4],[1,3,2]), ([5,3,2],[4,1,0]), ([1,5,4],[3,2,0]), ([0,5,2],[4,3,1]), ([1,3,2],[4,5,0]), ([3,4,1],[0,2,5]), ([1,2,4],[3,5,0]), ([0,5,2],[4,3,1]), ([2,0,1],[5,3,4]), ([1,5,2],[3,0,4]), ([1,4,0],[2,3,5]), ([1,5,0],[3,4,2]), ([5,1,0],[2,3,4]), ([5,1,2],[4,0,3]), ([1,2,0],[4,3,5]), ([1,5,0],[2,3,4]), ([1,0,2],[4,5,3]), ([1,3,4],[2,5,0]), ([4,3,5],[1,0,2]), ([3,4,1],[0,2,5]), ([3,2,0],[1,5,4]), ([1,5,3],[4,2,0]), ([1,3,0],[2,5,4]), ([1,0,2],[4,5,3]), ([4,0,5],[3,1,2]), ([5,2,1],[3,4,0]), ([4,0,2],[5,1,3]), ([1,2,3],[0,4,5]), ([1,0,4],[3,2,5]), ([5,1,2],[0,4,3]), ([5,4,1],[3,2,0]), ([0,4,2],[5,3,1]), ([3,2,0],[5,4,1]), ([2,4,1],[3,5,0]), ([0,4,5],[2,3,1]), ([0,5,2],[3,1,4]), ([4,2,3],[5,0,1]), ([1,2,0],[5,4,3]), ([3,1,5],[2,0,4]), ([2,1,4],[3,0,5]), ([4,3,1],[5,0,2]), ([3,5,0],[4,1,2]), ([2,3,4],[0,5,1]), ([4,5,2],[1,3,0]), ([2,0,3],[1,4,5]), ([3,0,4],[5,2,1]), ([1,4,5],[0,2,3]), ([1,0,4],[5,2,3]), ([2,0,3],[4,5,1]), ([4,0,2],[5,1,3]), ([2,3,0],[1,4,5]), ([4,0,3],[2,1,5]), ([4,0,3],[2,5,1]), ([5,4,0],[3,2,1]), ([1,4,5],[3,0,2]), ([2,1,0],[3,5,4]), ([0,2,5],[3,1,4]), ([0,4,5],[1,3,2]), ([3,2,5],[4,0,1]), ([1,4,0],[5,2,3]), ([5,1,4],[0,3,2]), ([4,1,0],[3,2,5]), ([4,1,0],[3,2,5]), ([0,4,3],[2,5,1]), ([4,0,5],[2,3,1]), ([0,5,1],[4,3,2]), ([3,2,5],[0,1,4]), ([0,4,1],[5,2,3]), ([0,2,4],[1,3,5]), ([0,1,2],[4,3,5]), ([0,4,1],[2,5,3]), ([3,0,2],[5,1,4]), ([0,1,5],[4,3,2]), ([2,1,3],[0,5,4]), ([2,1,5],[3,4,0]), ([5,4,0],[2,3,1]), ([5,4,1],[3,2,0]), ([3,4,2],[1,0,5]), ([1,2,4],[5,0,3]), ([0,4,1],[2,3,5]), ([2,3,5],[1,4,0]), ([2,0,5],[3,4,1]), ([0,5,2],[3,4,1]), ([4,5,1],[3,2,0]), ([0,3,4],[2,1,5]), ([5,4,3],[0,2,1]), ([1,0,3],[5,4,2]), ([5,3,1],[2,4,0]), ([5,3,1],[2,4,0]), ([5,0,4],[1,2,3]), ([3,1,0],[5,2,4]), ([0,1,5],[4,2,3]), ([0,5,4],[1,2,3]), ([2,5,1],[3,0,4]), ([5,0,2],[1,4,3]), ([0,4,5],[1,3,2]), ([4,1,0],[2,5,3]), ([2,3,5],[0,4,1]), ([3,2,4],[0,1,5]), ([3,5,2],[4,1,0]), ([0,1,5],[4,2,3]), ([3,1,0],[2,4,5]), ([5,0,3],[4,2,1]), ([2,1,5],[3,0,4]), ([1,2,0],[5,4,3]), ([4,1,2],[0,3,5]), ([3,1,0],[2,5,4]), ([4,0,5],[1,2,3]), ([5,4,0],[3,1,2]), ([1,0,5],[2,3,4]), ([1,3,4],[5,0,2]), ([0,4,3],[2,1,5]), ([0,4,2],[5,1,3]), ([3,5,1],[2,0,4]), ([5,0,2],[1,3,4]), ([1,0,4],[2,3,5]), ([2,4,3],[0,5,1]), ([1,0,5],[4,2,3]), ([4,5,0],[1,2,3]), ([4,1,2],[5,3,0]), ([1,2,3],[5,0,4]), ([5,0,3],[4,1,2]), ([2,5,0],[4,3,1]), ([3,5,2],[1,4,0]), ([3,0,2],[1,4,5]), ([3,4,0],[1,5,2]), ([5,1,2],[3,4,0]), ([0,5,3],[2,4,1]), ([1,0,5],[2,3,4]), ([1,5,4],[0,3,2]), ([5,4,0],[1,3,2]), ([0,2,1],[5,3,4]), ([2,0,1],[4,3,5]), ([2,3,1],[0,5,4]), ([5,4,2],[1,0,3]), ([1,5,2],[0,3,4]), ([0,3,2],[4,1,5]), ([4,3,2],[1,5,0]), ([2,3,5],[1,4,0]), ([1,0,2],[3,5,4]), ([1,0,2],[3,5,4]), ([1,2,5],[3,0,4]), ([1,3,4],[2,5,0]), ([3,0,5],[1,4,2]), ([0,5,2],[1,3,4]), ([0,1,3],[4,5,2]), ([5,3,1],[4,0,2]), ([4,2,3],[5,0,1]), ([1,5,2],[3,0,4]), ([3,1,0],[4,2,5]), ([3,0,4],[2,1,5]), ([0,3,2],[1,5,4]), ([1,5,3],[0,4,2]), ([0,5,1],[3,2,4]), ([5,2,1],[3,0,4]), ([2,3,1],[0,4,5]), ([1,0,5],[3,2,4]), ([1,2,5],[0,4,3]), ([1,3,5],[2,4,0]), ([2,3,5],[0,1,4]), ([5,2,1],[4,3,0]), ([4,2,0],[1,5,3]), ([1,0,2],[3,4,5]), ([5,2,1],[3,4,0]), ([2,5,0],[3,1,4]), ([2,4,5],[3,0,1]), ([3,0,4],[1,5,2]), ([1,4,2],[3,0,5]), ([3,2,1],[0,5,4]), ([5,0,4],[3,2,1]), ([4,2,5],[0,3,1]), ([5,3,4],[1,2,0]), ([4,5,1],[0,3,2]), ([0,1,4],[3,2,5]), ([2,1,5],[3,4,0]), ([2,1,4],[0,3,5]), ([5,0,2],[1,4,3]), ([1,0,5],[3,2,4]), ([5,4,0],[2,3,1]), ([5,3,2],[4,1,0]), ([1,3,5],[2,0,4]), ([3,5,2],[0,1,4]), ([2,4,3],[1,5,0]), ([4,5,0],[3,1,2]), ([0,5,4],[1,2,3]), ([1,3,5],[2,0,4]), ([1,5,3],[0,4,2]), ([1,0,5],[4,3,2]), ([2,5,0],[1,3,4]), ([5,0,3],[2,1,4]), ([5,4,3],[1,2,0]), ([3,2,4],[1,5,0]), ([5,4,1],[0,3,2]), ([1,2,4],[5,0,3]), ([1,5,2],[0,4,3]), ([5,4,1],[3,2,0]), ([0,4,1],[5,2,3]), ([2,5,4],[1,0,3]), ([1,5,3],[2,4,0]), ([4,3,2],[0,1,5]), ([4,5,0],[3,2,1]), ([4,0,5],[1,2,3]), ([0,1,3],[5,2,4]), ([5,0,3],[4,1,2]), ([1,3,4],[2,0,5]), ([5,2,1],[3,4,0]), ([2,5,3],[1,4,0]), ([2,4,3],[5,1,0]), ([3,2,5],[0,4,1]), ([1,2,4],[3,0,5]), ([5,2,0],[1,3,4]), ([4,1,2],[0,3,5]), ([4,3,5],[0,2,1]), ([5,1,2],[0,4,3]), ([4,3,1],[0,2,5]), ([3,0,4],[5,1,2]), ([5,1,3],[0,2,4]), ([0,1,2],[5,4,3]), ([3,5,1],[4,2,0]), ([0,2,3],[4,1,5]), ([4,5,3],[1,0,2]), ([4,1,5],[0,2,3]), ([5,3,0],[2,4,1]), ([2,3,1],[0,5,4]), ([0,2,1],[5,4,3]), ([3,1,4],[5,2,0]), ([0,5,3],[1,2,4]), ([5,2,3],[4,0,1]), ([5,3,2],[0,4,1]), ([3,1,0],[5,2,4]), ([0,1,3],[2,4,5]), ([2,4,0],[1,5,3]), ([5,3,2],[0,4,1]), ([4,2,3],[5,0,1]), ([2,0,5],[3,4,1]), ([1,5,4],[2,0,3]), ([5,4,2],[1,3,0]), ([2,1,5],[3,0,4]), ([3,1,2],[4,5,0]), ([1,0,5],[4,3,2]), ([0,3,2],[1,5,4]), ([5,4,3],[0,2,1]), ([2,1,3],[5,0,4]), ([5,2,3],[4,0,1]), ([1,4,2],[3,5,0]), ([4,5,0],[1,3,2]), ([3,0,1],[2,5,4]), ([0,1,3],[2,4,5]), ([2,5,1],[4,0,3]), ([0,5,2],[3,1,4]), ([1,5,0],[2,4,3]), ([3,5,1],[2,0,4]), ([1,5,4],[3,0,2]), ([1,5,3],[2,0,4]), ([0,2,3],[5,4,1]), ([1,0,3],[5,2,4]), ([2,0,1],[5,4,3]), ([4,3,2],[5,0,1]), ([2,1,0],[3,5,4]), ([1,0,4],[3,2,5]), ([4,0,1],[5,3,2]), ([4,3,5],[1,2,0]), ([3,0,4],[5,2,1]), ([0,4,2],[3,1,5]), ([0,2,5],[3,4,1]), ([3,4,1],[0,5,2]), ([2,0,5],[4,3,1]), ([1,0,3],[2,5,4]), ([2,0,3],[5,1,4]), ([4,5,2],[0,3,1]), ([0,5,4],[2,1,3]), ([0,2,1],[4,5,3]), ([5,1,3],[4,0,2]), ([5,0,4],[1,3,2]), ([3,5,1],[0,4,2]), ([5,4,3],[2,1,0]), ([0,1,4],[3,2,5]), ([0,5,3],[2,4,1]), ([5,2,1],[0,3,4]), ([3,5,2],[0,1,4]), ([1,5,4],[2,0,3]), ([5,2,3],[1,4,0]), ([4,1,2],[5,0,3]), ([5,0,4],[1,2,3]), ([2,5,0],[3,4,1]), ([3,0,1],[2,5,4]), ([3,4,0],[2,5,1]), ([5,2,4],[0,1,3]), ([5,0,2],[1,4,3]), ([5,4,2],[0,3,1]), ([2,5,1],[0,3,4]), ([3,1,5],[4,0,2]), ([2,4,0],[5,3,1]), ([2,3,0],[1,5,4]), ([0,2,3],[5,1,4]), ([0,1,3],[5,4,2]), ([0,3,5],[2,1,4]), ([4,5,0],[1,2,3]), ([1,0,2],[4,3,5]), ([0,3,1],[4,2,5]), ([1,5,3],[0,2,4]), ([4,5,3],[1,0,2]), ([2,4,3],[5,0,1]), ([5,4,0],[2,3,1]), ([4,0,3],[1,2,5]), ([1,3,0],[2,5,4]), ([1,5,4],[3,0,2]), ([5,2,3],[1,0,4]), ([5,4,3],[1,0,2]), ([5,0,2],[3,1,4]), ([5,3,0],[2,4,1]), ([3,4,5],[1,2,0]), ([1,5,3],[4,2,0]), ([0,1,4],[5,3,2]), ([1,5,2],[0,4,3]), ([1,0,2],[3,4,5]), ([3,5,0],[2,4,1]), ([0,2,5],[3,4,1]), ([3,5,1],[2,0,4]), ([0,4,1],[3,5,2]), ([2,3,0],[4,5,1]), ([4,2,1],[5,0,3]), ([5,2,3],[4,0,1]), ([2,5,0],[1,3,4]), ([2,5,3],[0,4,1]), ([5,2,0],[4,3,1]), ([3,2,5],[0,1,4]), ([4,0,1],[5,2,3]), ([5,4,2],[0,3,1]), ([2,5,0],[4,3,1]), ([5,0,2],[4,3,1]), ([5,0,2],[1,3,4]), ([2,1,5],[4,3,0]), ([0,4,1],[3,5,2]), ([2,3,5],[0,1,4]), ([3,4,2],[1,0,5]), ([2,0,5],[3,1,4]), ([2,1,4],[0,5,3]), ([5,2,1],[3,0,4]), ([0,4,1],[5,3,2]), ([1,2,4],[5,0,3]), ([4,5,0],[1,2,3]), ([3,4,2],[5,1,0]), ([5,2,3],[0,4,1]), ([2,3,4],[5,1,0]), ([5,2,4],[3,1,0]), ([3,0,4],[1,5,2]), ([0,2,1],[4,5,3]), ([1,2,0],[4,5,3]), ([3,1,5],[2,0,4]), ([1,5,2],[4,3,0]), ([0,4,2],[3,1,5]), ([0,4,3],[5,1,2]), ([4,3,1],[5,2,0]), ([4,2,1],[5,3,0]), ([4,5,1],[3,0,2]), ([1,3,5],[0,4,2]), ([4,3,5],[0,2,1]), ([0,5,1],[2,4,3]), ([4,3,5],[2,1,0]), ([2,3,1],[0,5,4]), ([4,5,3],[2,1,0]), ([3,1,5],[0,2,4]), ([4,1,2],[5,3,0]), ([4,1,3],[5,2,0]), ([4,3,0],[5,2,1]), ([5,0,4],[3,1,2]), ([4,0,3],[1,2,5]), ([2,1,3],[4,0,5]), ([3,5,4],[2,0,1]), ([2,1,3],[0,4,5]), ([1,4,0],[2,3,5]), ([4,1,3],[0,2,5]), ([2,0,4],[5,1,3]), ([4,1,2],[5,3,0]), ([0,2,3],[4,1,5]), ([3,1,2],[5,4,0]), ([1,0,2],[5,3,4]), ([2,5,4],[1,3,0]), ([1,2,4],[3,0,5]), ([4,2,0],[3,5,1]), ([5,3,1],[4,0,2]), ([2,0,1],[4,3,5]), ([2,0,5],[4,1,3]), ([1,0,3],[5,4,2]), ([1,2,4],[3,0,5]), ([2,1,3],[5,0,4]), ([3,4,0],[1,5,2]), ([3,5,1],[0,4,2]), ([5,3,0],[1,2,4]), ([5,3,2],[1,4,0]), ([3,2,4],[0,5,1]), ([3,4,2],[5,0,1]), ([1,5,3],[2,4,0]), ([3,1,2],[0,5,4]), ([4,3,1],[0,2,5]), ([4,1,3],[2,0,5]), ([1,0,4],[3,5,2]), ([2,3,1],[4,0,5]), ([2,3,0],[5,1,4]), ([0,4,1],[3,5,2]), ([2,0,4],[5,1,3]), ([4,1,0],[3,2,5]), ([0,1,4],[3,2,5]), ([5,1,4],[2,0,3]), ([2,3,5],[4,1,0]), ([2,4,0],[3,5,1]), ([0,2,3],[1,4,5]), ([1,4,3],[5,2,0]), ([1,0,2],[4,3,5]), ([3,0,2],[1,4,5]), ([5,4,1],[3,2,0]), ([5,0,3],[2,1,4]), ([5,2,3],[1,4,0]), ([3,0,4],[5,2,1]), ([3,1,5],[0,4,2]), ([4,3,1],[5,2,0]), ([5,0,3],[2,4,1]), ([5,2,4],[0,1,3]), ([1,0,5],[2,4,3]), ([3,1,4],[0,5,2]), ([0,2,1],[5,4,3]), ([0,5,4],[1,3,2]), ([2,5,4],[3,0,1]), ([4,0,2],[5,3,1]), ([5,0,3],[4,2,1]), ([3,2,1],[5,0,4]), ([0,3,2],[5,4,1]), ([3,5,1],[4,0,2]), ([5,4,0],[1,3,2]), ([5,0,4],[1,2,3]), ([3,4,0],[1,2,5]), ([3,2,4],[5,1,0]), ([2,3,1],[0,4,5]), ([5,0,1],[2,3,4]), ([5,2,4],[0,3,1]), ([5,1,3],[0,2,4]), ([4,0,2],[3,5,1]), ([1,2,0],[4,5,3]), ([1,3,5],[2,4,0]), ([4,2,0],[1,5,3]), ([2,1,5],[0,4,3]), ([3,5,0],[1,4,2]), ([4,0,3],[1,5,2]), ([1,3,0],[4,2,5]), ([2,0,1],[5,4,3]), ([3,1,0],[5,2,4]), ([1,2,4],[3,5,0]), ([1,3,4],[0,5,2]), ([1,3,4],[0,2,5]), ([3,4,2],[1,5,0]), ([4,1,5],[3,0,2]), ([0,1,4],[5,2,3]), ([4,3,0],[2,1,5]), ([5,0,1],[2,3,4]), ([0,1,5],[2,3,4]), ([3,4,1],[0,5,2]), ([4,1,2],[0,5,3]), ([2,5,1],[0,4,3]), ([4,1,0],[2,3,5]), ([5,3,0],[1,2,4]), ([5,3,4],[0,2,1]), ([3,1,4],[0,2,5]), ([2,3,1],[0,4,5]), ([3,2,5],[0,4,1]), ([3,1,0],[4,5,2]), ([4,2,0],[3,5,1]), ([5,4,3],[1,2,0]), ([1,4,5],[0,2,3]), ([4,5,3],[2,1,0]), ([3,1,4],[5,0,2]), ([0,2,3],[5,1,4]), ([2,1,3],[5,0,4]), ([1,5,3],[2,0,4]), ([3,0,5],[2,1,4]), ([5,3,0],[4,1,2]), ([0,5,2],[4,3,1]), ([2,1,4],[3,0,5]), ([2,4,0],[1,3,5]), ([2,5,1],[4,3,0]), ([1,2,0],[4,3,5]), ([3,4,5],[1,2,0]), ([0,3,2],[4,5,1]), ([3,1,0],[4,2,5]), ([0,2,5],[1,3,4]), ([1,5,4],[0,2,3]), ([2,1,5],[4,0,3]), ([0,2,4],[3,5,1]), ([4,5,1],[2,0,3]), ([3,2,1],[0,4,5]), ([5,2,3],[1,4,0]), ([3,4,1],[2,0,5]), ([2,3,1],[5,0,4]), ([1,0,2],[5,3,4]), ([4,0,1],[3,5,2]), ([1,0,4],[3,5,2]), ([3,0,4],[5,2,1]), ([1,0,3],[4,2,5]), ([5,3,2],[4,0,1]), ([3,5,0],[1,2,4]), ([1,5,2],[0,4,3]), ([3,2,5],[4,1,0]), ([5,1,3],[0,4,2]), ([1,4,3],[0,2,5]), ([3,5,1],[2,4,0]), ([0,3,1],[2,4,5]), ([2,4,1],[5,0,3]), ([2,4,3],[5,0,1]), ([1,5,3],[2,4,0]), ([2,3,5],[4,1,0]), ([5,0,1],[4,2,3]), ([5,1,3],[4,0,2]), ([4,5,1],[0,2,3]), ([3,0,5],[2,1,4]), ([0,3,5],[2,4,1]), ([5,0,3],[2,1,4]), ([2,4,0],[5,3,1]), ([3,5,4],[2,1,0]), ([3,4,2],[1,0,5]), ([4,2,0],[5,1,3]), ([3,2,0],[4,1,5]), ([3,2,5],[1,0,4]), ([3,0,2],[1,5,4]), ([2,4,0],[1,3,5]), ([1,4,3],[2,5,0]), ([2,1,3],[0,5,4]), ([4,5,3],[2,1,0]), ([5,4,1],[2,3,0]), ([5,0,2],[1,4,3]), ([2,0,1],[5,3,4]), ([1,3,2],[0,5,4]), ([3,0,2],[4,1,5]), ([0,3,2],[1,4,5]), ([0,1,3],[2,4,5]), ([2,0,3],[4,1,5]), ([5,0,4],[2,1,3]), ([5,2,0],[4,3,1]), ([2,5,4],[0,3,1]), ([0,3,5],[2,1,4]), ([1,0,3],[5,4,2]), ([3,4,2],[1,0,5]), ([0,3,1],[4,5,2]), ([3,0,4],[2,1,5]), ([2,1,0],[3,4,5]), ([5,0,2],[4,1,3]), ([2,4,3],[1,5,0]), ([4,1,0],[3,2,5]), ([5,3,0],[1,2,4]), ([4,3,2],[0,5,1]), ([1,3,2],[4,0,5]), ([1,5,2],[4,0,3]), ([1,0,4],[2,5,3]), ([0,5,1],[4,3,2]), ([3,2,0],[4,1,5]), ([3,4,1],[5,2,0]), ([0,4,3],[2,1,5]), ([3,0,2],[4,1,5]), ([4,1,2],[5,0,3]), ([4,2,5],[1,0,3]), ([4,5,0],[3,1,2]), ([5,3,4],[1,2,0]), ([3,2,4],[1,5,0]), ([5,3,2],[4,1,0]), ([1,3,5],[0,2,4]), ([5,3,4],[1,2,0]), ([2,0,5],[4,1,3]), ([4,5,1],[2,3,0]), ([0,3,4],[5,2,1]), ([1,0,2],[4,5,3]), ([5,0,3],[1,2,4]), ([0,1,5],[4,2,3]), ([3,5,2],[0,4,1]), ([4,1,3],[5,0,2]), ([5,2,0],[1,3,4]), ([2,3,0],[4,5,1]), ([3,1,5],[2,4,0]), ([0,3,4],[1,2,5]), ([0,1,2],[4,3,5]), ([5,0,2],[4,3,1]), ([4,1,3],[5,2,0]), ([4,1,0],[2,3,5]), ([2,0,4],[3,1,5]), ([3,2,5],[4,0,1]), ([0,5,2],[4,3,1]), ([3,5,4],[0,2,1]), ([3,2,1],[4,0,5]), ([5,4,3],[2,1,0]), ([5,4,2],[0,3,1]), ([1,2,5],[4,3,0]), ([3,2,5],[4,1,0]), ([5,0,2],[1,4,3]), ([3,0,5],[2,4,1]), ([5,2,4],[1,3,0]), ([1,2,5],[4,0,3]), ([0,2,3],[5,1,4]), ([2,3,4],[1,0,5]), ([5,3,0],[4,2,1]), ([4,0,3],[2,1,5]), ([5,3,2],[1,4,0]), ([5,0,1],[3,2,4]), ([1,5,2],[3,0,4]), ([3,5,0],[2,1,4]), ([4,5,1],[3,2,0]), ([1,5,3],[2,0,4]), ([2,1,4],[5,3,0]), ([5,0,1],[2,3,4]), ([1,4,2],[3,5,0]), ([0,4,3],[5,2,1]), ([0,2,5],[3,1,4]), ([5,2,4],[1,3,0]), ([0,5,3],[1,4,2]), ([4,0,1],[2,3,5]), ([2,1,4],[5,3,0]), ([1,5,3],[2,4,0]), ([0,1,5],[4,3,2]), ([4,1,3],[0,2,5]), ([1,3,4],[2,0,5]), ([4,3,2],[1,0,5]), ([2,0,5],[3,4,1]), ([0,2,1],[4,5,3]), ([1,0,3],[4,5,2]), ([1,3,0],[2,4,5]), ([5,0,4],[1,2,3]), ([4,5,0],[1,3,2]), ([1,4,5],[3,2,0]), ([4,1,3],[5,2,0]), ([5,1,3],[2,0,4]), ([2,4,0],[1,5,3]), ([0,2,4],[5,1,3]), ([0,3,2],[1,5,4]), ([4,2,5],[0,3,1]), ([2,1,0],[4,3,5]), ([3,2,4],[5,1,0]), ([2,5,1],[3,0,4]), ([0,3,5],[2,1,4]), ([4,5,0],[1,2,3]), ([0,2,5],[1,4,3]), ([1,2,3],[4,5,0]), ([2,3,4],[0,5,1]), ([2,4,5],[3,1,0]), ([3,1,4],[0,5,2]), ([0,4,2],[1,5,3]), ([3,2,5],[0,4,1]), ([4,3,5],[1,2,0]), ([0,4,1],[3,5,2]), ([2,3,4],[5,1,0]), ([0,1,3],[5,4,2]), ([1,4,3],[0,2,5]), ([5,0,4],[1,3,2]), ([3,2,0],[4,5,1]), ([3,5,1],[4,0,2]), ([3,4,5],[0,2,1]), ([3,5,0],[2,1,4]), ([1,5,3],[4,2,0]), ([5,2,1],[4,0,3]), ([2,3,1],[4,5,0]), ([1,3,2],[0,5,4]), ([0,2,3],[1,5,4]), ([3,2,4],[5,1,0]), ([4,2,0],[5,1,3]), ([2,1,3],[0,5,4]), ([2,4,0],[5,3,1]), ([5,0,4],[3,1,2]), ([0,5,1],[4,3,2]), ([4,3,5],[1,0,2]), ([3,1,2],[0,5,4]), ([2,3,0],[5,4,1]), ([5,4,1],[2,3,0]), ([5,2,4],[3,0,1]), ([5,1,0],[3,4,2]), ([5,3,2],[4,0,1]), ([2,1,5],[3,0,4]), ([4,3,0],[1,5,2]), ([3,0,4],[1,2,5]), ([5,2,0],[1,3,4]), ([0,2,3],[1,4,5]), ([2,5,4],[3,0,1]), ([3,4,0],[2,1,5]), ([0,5,3],[2,4,1]), ([3,0,2],[5,4,1]), ([3,5,4],[0,1,2]), ([5,4,1],[2,0,3]), ([3,5,2],[4,0,1]), ([4,0,2],[1,3,5]), ([4,3,2],[1,0,5]), ([5,4,3],[2,1,0]), ([4,2,3],[5,0,1]), ([2,0,3],[1,5,4]), ([4,1,0],[3,5,2]), ([2,0,4],[3,1,5]), ([4,1,2],[3,5,0]), ([3,0,4],[5,1,2]), ([1,2,4],[5,3,0]), ([2,5,4],[3,0,1]), ([0,2,1],[4,3,5]), ([3,4,5],[1,0,2]), ([4,0,2],[1,5,3]), ([5,2,1],[4,3,0]), ([5,0,1],[4,2,3]), ([4,1,2],[5,0,3]), ([1,0,2],[3,4,5]), ([2,5,4],[0,1,3]), ([1,0,4],[2,5,3]), ([3,0,4],[5,1,2]), ([3,0,5],[1,4,2]), ([2,5,1],[4,3,0]), ([0,3,4],[2,5,1]), ([3,0,1],[2,4,5]), ([3,1,5],[0,4,2]), ([4,0,5],[3,2,1]), ([0,1,4],[3,2,5]), ([5,3,2],[4,0,1]), ([1,0,3],[2,5,4]), ([4,0,2],[3,5,1]), ([0,2,1],[5,3,4]), ([4,0,3],[1,5,2]), ([0,1,3],[2,4,5]), ([2,0,1],[3,5,4]), ([0,4,2],[3,1,5]), ([4,2,3],[0,5,1]), ([3,1,5],[2,0,4]), ([1,5,0],[3,2,4]), ([2,5,1],[3,0,4]), ([5,0,1],[4,2,3]), ([1,5,0],[2,3,4]), ([3,4,2],[5,0,1]), ([3,4,0],[1,5,2]), ([0,5,2],[1,4,3]), ([5,4,2],[0,3,1]), ([2,0,3],[1,5,4]), ([4,2,1],[3,0,5]), ([1,5,3],[0,2,4]), ([3,4,0],[2,5,1]), ([4,1,0],[5,2,3]), ([4,2,5],[3,1,0]), ([4,1,0],[3,5,2]), ([2,1,0],[4,3,5]), ([0,3,2],[1,4,5]), ([5,4,3],[1,2,0]), ([5,3,4],[1,2,0]), ([0,4,3],[5,2,1]), ([1,0,5],[4,2,3]), ([4,3,5],[2,0,1]), ([2,4,0],[1,3,5]), ([0,1,3],[4,2,5]), ([0,4,2],[3,5,1]), ([2,1,5],[3,0,4]), ([3,0,2],[5,4,1]), ([4,5,1],[3,2,0]), ([1,0,4],[3,2,5]), ([0,2,1],[4,5,3]), ([1,0,4],[3,2,5]), ([1,5,4],[2,3,0]), ([3,0,1],[4,5,2]), ([5,4,1],[3,0,2]), ([2,0,5],[4,3,1]), ([1,3,2],[5,0,4]), ([4,1,0],[5,3,2]), ([0,4,1],[5,3,2]), ([0,3,4],[5,1,2]), ([0,5,1],[2,4,3]), ([0,3,5],[2,1,4]), ([2,0,5],[1,3,4]), ([1,0,3],[2,4,5]), ([4,0,2],[5,1,3]), ([3,5,4],[2,1,0]), ([5,1,2],[4,3,0]), ([4,5,1],[3,0,2]), ([5,4,1],[0,2,3]), ([1,3,4],[0,2,5]), ([0,5,1],[2,3,4]), ([0,3,5],[2,4,1]), ([1,5,0],[4,3,2]), ([3,0,2],[1,5,4]), ([5,4,3],[1,2,0]), ([5,3,2],[1,4,0]), ([1,4,5],[0,2,3]), ([5,4,0],[1,2,3]), ([1,4,3],[0,5,2]), ([0,2,1],[5,3,4]), ([5,0,3],[2,1,4]), ([1,0,3],[2,5,4]), ([5,1,3],[4,2,0]), ([1,2,5],[4,3,0]), ([2,4,3],[5,1,0]), ([5,4,0],[3,1,2]), ([4,2,5],[0,3,1]), ([1,2,3],[5,0,4]), ([2,4,3],[5,0,1]), ([3,5,2],[0,4,1]), ([4,1,3],[2,5,0]), ([3,0,2],[4,5,1]), ([0,4,2],[5,3,1]), ([3,1,0],[4,2,5]), ([3,4,0],[1,5,2]), ([2,3,5],[4,0,1]), ([4,0,5],[2,1,3]), ([2,4,3],[0,5,1]), ([0,3,4],[5,1,2]), ([5,0,3],[2,1,4]), ([2,1,0],[4,5,3]), ([4,3,5],[0,1,2]), ([2,5,0],[3,4,1]), ([4,5,0],[1,2,3]), ([0,5,2],[1,4,3]), ([3,4,2],[1,5,0]), ([5,0,3],[2,1,4]), ([1,5,0],[2,4,3]), ([4,3,0],[5,2,1]), ([4,1,2],[0,3,5]), ([3,2,4],[5,0,1]), ([2,3,5],[1,4,0]), ([1,3,4],[2,0,5]), ([2,1,5],[3,0,4]), ([5,1,4],[0,3,2]), ([2,1,0],[4,5,3]), ([4,5,0],[3,2,1]), ([3,5,2],[0,4,1]), ([1,2,4],[5,0,3]), ([5,3,2],[1,0,4]), ([5,2,1],[4,3,0]), ([1,3,4],[2,5,0]), ([4,3,2],[1,5,0]), ([3,0,5],[4,1,2]), ([4,0,5],[3,2,1]), ([5,3,1],[4,0,2]), ([4,0,2],[1,5,3]), ([3,0,2],[5,4,1]), ([1,0,5],[3,4,2]), ([0,3,2],[5,1,4]), ([4,1,3],[2,0,5]), ([0,1,4],[3,5,2]), ([5,4,1],[3,2,0]), ([3,0,2],[1,5,4]), ([0,4,3],[1,2,5]), ([5,2,0],[4,1,3]), ([5,3,0],[4,1,2]), ([3,1,2],[0,5,4]), ([3,1,2],[4,0,5]), ([5,1,4],[0,3,2]), ([2,1,0],[4,3,5]), ([0,3,4],[1,5,2]), ([4,3,1],[2,0,5]), ([4,5,1],[3,0,2]), ([0,1,3],[2,4,5]), ([3,0,4],[5,2,1]), ([1,0,3],[2,4,5]), ([1,2,0],[4,3,5]), ([2,1,4],[3,0,5]), ([2,1,0],[4,3,5]), ([3,2,1],[0,5,4]), ([5,4,2],[1,3,0]), ([3,1,2],[4,5,0]), ([2,4,0],[1,3,5]), ([1,0,4],[2,5,3]), ([5,3,4],[2,1,0]), ([0,1,3],[4,2,5]), ([3,5,4],[1,2,0]), ([4,5,3],[1,2,0]), ([3,4,1],[2,0,5]), ([2,0,1],[4,3,5]), ([1,2,4],[5,0,3]), ([0,2,1],[3,4,5]), ([4,3,5],[2,0,1]), ([5,2,4],[0,3,1]), ([2,5,0],[1,4,3]), ([4,5,1],[3,2,0]), ([2,1,0],[5,3,4]), ([0,1,2],[5,4,3]), ([4,0,5],[3,1,2]), ([4,0,1],[2,3,5]), ([5,1,2],[0,3,4]), ([5,0,4],[2,1,3]), ([0,2,1],[4,5,3]), ([3,4,1],[0,5,2]), ([0,5,4],[3,1,2]), ([2,3,5],[0,1,4]), ([2,5,3],[1,0,4]), ([3,0,5],[1,2,4]), ([3,4,0],[2,5,1]), ([5,0,1],[3,4,2]), ([1,4,3],[0,5,2]), ([2,0,5],[4,3,1]), ([4,3,2],[1,5,0]), ([1,3,4],[2,0,5]), ([0,3,1],[5,4,2]), ([4,0,5],[2,1,3]), ([3,5,0],[1,2,4]), ([1,4,2],[0,5,3]), ([4,0,5],[1,2,3]), ([1,2,5],[0,4,3]), ([2,4,0],[1,5,3]), ([2,3,4],[5,1,0]), ([0,1,4],[5,3,2]), ([0,2,5],[3,4,1]), ([1,2,5],[4,0,3]), ([4,2,0],[1,5,3]), ([3,2,4],[0,5,1]), ([4,2,5],[0,3,1]), ([0,1,5],[4,2,3]), ([2,4,5],[0,3,1]), ([1,2,3],[4,5,0]), ([5,3,1],[0,4,2]), ([3,4,1],[5,0,2]), ([0,1,3],[2,5,4]), ([0,3,5],[1,4,2]), ([1,2,5],[3,0,4]), ([1,5,3],[4,2,0]), ([1,3,0],[4,2,5]), ([5,2,1],[0,4,3]), ([5,4,2],[3,0,1]), ([3,0,2],[4,5,1]), ([3,0,2],[4,5,1]), ([3,2,5],[0,1,4]), ([0,2,5],[3,1,4]), ([4,1,5],[2,0,3]), ([0,3,1],[5,4,2]), ([5,0,1],[4,2,3]), ([1,3,5],[0,4,2]), ([5,4,3],[0,1,2]), ([0,3,1],[5,4,2]), ([0,4,5],[1,3,2]), ([1,4,2],[3,0,5]), ([5,1,2],[0,4,3]), ([3,5,0],[1,4,2]), ([2,0,3],[4,5,1]), ([5,0,4],[3,1,2]), ([3,2,1],[4,5,0]), ([2,3,1],[4,0,5]), ([0,1,5],[4,2,3]), ([1,2,3],[0,4,5]), ([1,5,3],[2,0,4]), ([3,5,0],[2,4,1]), ([5,3,4],[2,0,1]), ([4,0,1],[3,2,5]), ([3,4,2],[5,0,1]), ([3,1,2],[0,5,4]), ([5,1,2],[0,3,4]), ([5,2,1],[3,4,0]), ([0,2,1],[4,5,3]), ([3,2,5],[4,0,1]), ([4,0,3],[5,1,2]), ([4,3,5],[0,2,1]), ([3,4,0],[1,2,5]), ([2,0,5],[3,4,1]), ([2,1,3],[0,5,4]), ([2,4,5],[3,1,0]), ([0,1,5],[4,2,3]), ([4,0,1],[2,5,3]), ([3,5,4],[1,0,2]), ([0,2,3],[4,1,5]), ([5,3,4],[1,2,0]), ([4,1,5],[0,2,3]), ([2,1,5],[0,3,4]), ([0,5,4],[3,2,1]), ([1,4,0],[3,2,5]), ([2,0,4],[5,1,3]), ([4,3,0],[5,2,1]), ([4,5,3],[1,0,2]), ([1,2,0],[3,4,5]), ([4,2,3],[5,0,1]), ([2,3,0],[5,1,4]), ([5,0,4],[2,3,1]), ([5,0,2],[1,4,3]), ([0,3,4],[1,5,2]), ([5,3,2],[4,1,0]), ([1,5,2],[4,0,3]), ([1,0,4],[3,2,5]), ([0,2,1],[5,3,4]), ([2,0,3],[1,4,5]), ([0,1,3],[5,4,2]), ([0,5,3],[2,4,1]), ([5,0,1],[4,3,2]), ([4,2,0],[1,3,5]), ([0,5,3],[1,2,4]), ([3,5,0],[2,1,4]), ([2,4,1],[5,3,0]), ([3,2,5],[4,0,1]), ([0,5,1],[3,4,2]), ([5,0,1],[2,3,4]), ([0,3,2],[5,1,4]), ([4,2,3],[0,1,5]), ([3,2,5],[4,0,1]), ([3,5,0],[1,4,2]), ([5,2,3],[1,0,4]), ([0,1,3],[5,2,4]), ([5,2,3],[1,0,4]), ([0,4,2],[5,3,1]), ([1,3,4],[5,0,2]), ([3,1,5],[0,2,4]), ([3,2,4],[1,5,0]), ([4,5,3],[1,0,2]), ([2,3,1],[5,4,0]), ([4,0,3],[5,1,2]), ([0,2,3],[5,1,4]), ([5,4,2],[3,1,0]), ([4,3,5],[0,2,1]), ([4,5,2],[3,1,0]), ([1,3,4],[0,5,2]), ([2,3,0],[1,4,5]), ([3,2,1],[0,4,5]), ([2,0,4],[5,1,3]), ([0,1,2],[5,4,3]), ([1,0,3],[4,5,2]), ([4,0,5],[3,1,2]), ([5,2,3],[0,4,1]), ([3,1,4],[0,5,2]), ([3,1,5],[0,4,2]), ([5,2,0],[3,4,1]), ([2,0,5],[3,1,4]), ([1,3,2],[4,0,5]), ([5,0,4],[2,3,1]), ([1,3,0],[2,4,5]), ([4,1,2],[5,3,0]), ([2,0,4],[5,1,3]), ([5,0,3],[4,2,1]), ([0,4,3],[2,5,1]), ([1,2,5],[0,3,4]), ([0,2,1],[4,3,5]), ([0,5,2],[1,3,4]), ([2,3,5],[1,4,0]), ([4,3,5],[0,1,2]), ([2,3,0],[1,4,5]), ([4,2,0],[5,3,1]), ([0,1,5],[3,2,4]), ([5,4,1],[3,0,2]), ([5,2,4],[1,0,3]), ([1,5,2],[4,0,3]), ([5,3,0],[2,1,4]), ([1,4,5],[2,3,0]), ([2,0,4],[3,1,5]), ([5,3,0],[2,1,4]), ([4,5,1],[0,3,2]), ([2,5,3],[1,4,0]), ([2,3,1],[4,0,5]), ([5,0,1],[2,4,3]), ([3,5,0],[1,4,2]), ([4,2,5],[0,3,1]), ([3,1,0],[2,5,4]), ([1,2,3],[5,0,4]), ([3,1,5],[2,4,0]), ([4,2,1],[3,0,5]), ([2,5,1],[4,3,0]), ([1,3,5],[2,0,4]), ([4,1,3],[5,2,0]), ([3,0,5],[4,2,1]), ([1,4,2],[0,5,3]), ([4,5,3],[2,0,1]), ([4,5,1],[3,2,0]), ([2,3,4],[1,5,0]), ([4,5,0],[3,2,1]), ([3,2,4],[5,0,1]), ([1,2,5],[4,0,3]), ([4,0,1],[3,5,2]), ([0,2,5],[4,3,1]), ([1,4,3],[2,5,0]), ([0,2,3],[5,1,4]), ([1,2,0],[4,5,3]), ([4,3,1],[0,5,2]), ([2,0,1],[5,4,3]), ([0,2,3],[4,1,5]), ([3,0,2],[1,5,4]), ([0,5,1],[3,2,4]), ([1,3,2],[0,4,5]), ([3,4,2],[1,0,5]), ([2,1,0],[3,4,5]), ([3,0,4],[5,1,2]), ([5,0,2],[1,4,3]), ([5,1,0],[4,2,3]), ([1,4,5],[2,3,0]), ([4,3,5],[2,1,0]), ([4,1,5],[0,2,3]), ([3,5,4],[1,2,0]), ([1,0,2],[4,5,3]), ([0,4,3],[1,5,2]), ([4,2,5],[3,0,1]), ([4,2,1],[0,5,3]), ([2,5,3],[0,4,1]), ([3,5,2],[1,0,4]), ([3,2,5],[0,4,1]), ([4,0,2],[3,5,1]), ([5,3,1],[4,2,0]), ([0,1,4],[5,2,3]), ([4,1,3],[0,2,5]), ([5,0,3],[1,4,2]), ([2,5,3],[1,4,0]), ([4,3,1],[0,5,2]), ([2,5,1],[3,4,0]), ([0,5,4],[1,2,3]), ([5,3,2],[0,4,1]), ([3,0,5],[2,1,4]), ([4,5,2],[0,3,1]), ([1,0,3],[2,4,5]), ([0,1,2],[3,4,5]), ([5,2,3],[0,1,4]), ([1,2,3],[5,0,4]), ([5,1,2],[4,0,3]), ([1,5,2],[3,0,4]), ([3,2,4],[0,1,5]), ([1,3,4],[2,0,5]), ([4,2,5],[1,3,0]), ([1,4,0],[3,2,5]), ([3,4,5],[2,0,1]), ([3,4,5],[0,1,2]), ([3,4,2],[1,5,0]), ([5,2,0],[4,1,3]), ([5,1,2],[3,4,0]), ([2,4,3],[0,5,1]), ([0,5,2],[3,1,4]), ([2,0,3],[1,4,5]), ([5,2,4],[3,1,0]), ([2,5,3],[4,1,0]), ([3,5,0],[2,4,1]), ([0,1,3],[2,5,4]), ([4,1,0],[5,2,3]), ([5,2,4],[1,3,0]), ([0,1,2],[3,4,5]), ([2,1,3],[0,4,5]), ([4,5,3],[2,0,1]), ([1,3,4],[5,2,0]), ([4,2,3],[0,5,1]), ([0,3,5],[1,4,2]), ([2,5,4],[3,0,1]), ([1,3,4],[2,5,0]), ([3,4,2],[1,0,5]), ([4,5,0],[3,1,2]), ([4,0,3],[2,1,5]), ([2,0,3],[1,4,5]), ([2,5,0],[4,1,3]), ([4,1,3],[0,2,5]), ([0,4,1],[3,5,2]), ([4,1,5],[0,3,2]), ([0,1,5],[4,2,3]), ([5,4,1],[3,2,0]), ([1,0,5],[3,2,4]), ([0,5,4],[2,1,3]), ([3,5,1],[0,4,2]), ([5,4,0],[1,3,2]), ([1,0,4],[5,3,2]), ([4,1,3],[5,2,0]), ([4,0,2],[3,5,1]), ([3,5,2],[0,1,4]), ([0,5,3],[4,1,2]), ([5,0,2],[1,4,3]), ([4,0,1],[5,2,3]), ([5,0,4],[2,1,3]), ([1,2,5],[4,0,3]), ([0,5,2],[4,1,3]), ([0,2,3],[1,4,5]), ([3,4,5],[1,0,2]), ([2,0,1],[3,4,5]), ([3,4,0],[1,2,5]), ([1,0,4],[5,2,3]), ([4,2,5],[3,0,1]), ([3,1,2],[0,4,5]), ([0,3,5],[1,4,2]), ([2,0,4],[1,5,3]), ([0,1,2],[3,4,5]), ([3,5,1],[2,4,0]), ([3,4,1],[5,2,0]), ([5,3,2],[0,1,4]), ([0,1,4],[2,3,5]), ([1,2,4],[5,0,3]), ([4,3,1],[2,5,0]), ([0,4,3],[5,2,1]), ([4,1,5],[0,2,3]), ([1,5,4],[2,0,3]), ([3,5,2],[0,1,4]), ([3,2,5],[0,1,4]), ([4,0,2],[5,1,3]), ([0,3,2],[4,1,5]), ([5,0,1],[3,2,4]), ([1,2,4],[0,5,3]), ([5,4,3],[0,1,2]), ([1,2,5],[3,4,0]), ([0,3,4],[2,1,5]), ([3,5,2],[1,0,4]), ([4,0,1],[5,3,2]), ([2,0,1],[5,4,3]), ([3,4,1],[0,2,5]), ([2,5,4],[0,3,1]), ([3,1,4],[5,0,2]), ([5,3,0],[2,1,4]), ([2,4,3],[0,1,5]), ([3,0,4],[2,5,1]), ([2,1,5],[3,4,0]), ([0,2,3],[5,4,1]), ([0,2,4],[3,1,5]), ([1,3,0],[5,2,4]), ([1,0,5],[2,3,4]), ([1,0,3],[5,4,2]), ([3,1,0],[4,2,5]), ([2,0,1],[4,5,3]), ([0,1,4],[5,3,2]), ([3,2,0],[1,5,4]), ([2,0,1],[5,4,3]), ([2,0,3],[1,5,4]), ([4,1,2],[0,5,3]), ([4,3,1],[5,0,2]), ([2,5,1],[3,0,4]), ([2,4,0],[1,5,3]), ([0,3,1],[4,5,2]), ([4,5,2],[1,3,0]), ([1,5,2],[0,4,3]), ([0,3,2],[1,5,4]), ([3,0,4],[1,2,5]), ([5,1,4],[2,3,0]), ([1,5,2],[3,0,4]), ([0,5,1],[2,3,4]), ([1,2,0],[5,4,3]), ([3,4,5],[2,1,0]), ([2,1,4],[3,0,5]), ([3,4,5],[1,0,2]), ([4,0,1],[3,5,2]), ([2,4,3],[0,5,1]), ([5,4,3],[2,0,1]), ([4,5,0],[3,2,1]), ([2,0,1],[4,3,5]), ([4,2,3],[1,0,5]), ([4,3,5],[1,2,0]), ([4,5,1],[2,0,3]), ([2,4,1],[5,3,0]), ([4,3,5],[0,2,1]), ([3,5,1],[4,0,2]), ([3,5,1],[4,0,2]), ([2,1,5],[0,4,3]), ([0,3,1],[4,2,5]), ([5,3,1],[4,0,2]), ([1,2,4],[3,5,0]), ([5,1,3],[0,2,4]), ([2,4,5],[0,1,3]), ([0,1,5],[3,2,4]), ([2,3,4],[5,1,0]), ([4,2,5],[0,3,1]), ([0,1,3],[4,5,2]), ([5,4,1],[3,0,2]), ([2,3,1],[5,4,0]), ([1,0,3],[2,5,4]), ([1,2,4],[5,0,3]), ([0,4,2],[5,1,3]), ([1,3,5],[0,4,2]), ([2,0,1],[5,3,4]), ([0,3,4],[1,2,5]), ([0,1,5],[4,3,2]), ([1,3,2],[5,4,0]), ([0,3,1],[4,5,2]), ([3,4,5],[0,2,1]), ([3,5,4],[0,1,2]), ([3,2,4],[1,0,5]), ([3,0,1],[4,5,2]), ([2,1,0],[3,5,4]), ([3,2,0],[1,5,4]), ([3,1,5],[0,4,2]), ([3,1,5],[4,2,0]), ([1,0,4],[3,5,2]), ([1,5,4],[2,3,0]), ([3,4,0],[1,2,5]), ([1,5,3],[4,2,0]), ([3,2,5],[1,4,0]), ([0,1,5],[3,4,2]), ([3,2,0],[1,4,5]), ([4,2,3],[5,1,0]), ([0,3,1],[2,4,5]), ([0,3,2],[4,1,5]), ([5,4,0],[2,3,1]), ([4,1,2],[5,0,3]), ([1,3,4],[0,5,2]), ([2,1,4],[0,3,5]), ([3,5,4],[2,0,1]), ([0,4,5],[2,1,3]), ([0,2,1],[4,5,3]), ([2,3,0],[4,1,5]), ([1,0,4],[5,2,3]), ([5,3,2],[1,4,0]), ([1,4,0],[2,3,5]), ([1,5,0],[2,4,3]), ([1,2,5],[3,0,4]), ([3,1,5],[4,0,2]), ([1,4,2],[5,0,3]), ([1,5,0],[4,3,2]), ([0,2,1],[4,5,3]), ([5,0,1],[3,4,2]), ([5,2,1],[3,4,0]), ([4,1,3],[0,2,5]), ([2,4,3],[5,0,1]), ([4,1,0],[2,5,3]), ([3,2,5],[1,4,0]), ([2,0,4],[5,1,3]), ([2,4,3],[0,1,5]), ([2,0,5],[3,4,1]), ([4,1,3],[5,2,0]), ([5,3,4],[1,2,0]), ([4,3,2],[0,1,5]), ([2,3,0],[1,5,4]), ([4,2,1],[3,0,5]), ([4,3,0],[5,1,2]), ([4,2,1],[0,5,3]), ([5,3,1],[0,2,4]), ([0,3,5],[4,2,1]), ([5,2,4],[3,1,0]), ([0,5,3],[1,4,2]), ([2,5,3],[1,4,0]), ([0,4,3],[1,2,5]), ([3,0,1],[4,2,5]), ([5,0,4],[1,3,2]), ([4,3,0],[2,1,5]), ([1,5,0],[2,3,4]), ([1,0,5],[2,3,4]), ([2,1,5],[0,3,4]), ([2,1,3],[0,4,5]), ([3,4,2],[5,0,1]), ([0,3,2],[5,4,1]), ([2,0,1],[4,5,3]), ([4,5,1],[3,2,0]), ([5,2,3],[4,1,0]), ([3,2,1],[4,5,0]), ([0,5,4],[1,2,3]), ([2,1,0],[5,3,4]), ([3,0,2],[5,4,1]), ([0,4,1],[2,5,3]), ([5,4,2],[0,3,1]), ([5,3,2],[4,1,0]), ([0,3,2],[4,5,1]), ([0,1,2],[3,4,5]), ([3,4,1],[0,2,5]), ([0,4,3],[2,1,5]), ([1,5,0],[2,3,4]), ([1,0,5],[3,4,2]), ([0,5,2],[3,4,1]), ([5,0,3],[2,1,4]), ([2,0,3],[5,4,1]), ([2,5,1],[0,3,4]), ([2,4,1],[0,3,5]), ([3,0,5],[2,1,4]), ([5,3,4],[2,1,0]), ([5,1,2],[0,3,4]), ([4,0,5],[3,1,2]), ([1,5,3],[4,2,0]), ([2,4,1],[0,5,3]), ([2,3,4],[0,1,5]), ([0,5,2],[1,3,4]), ([5,0,2],[1,3,4]), ([2,3,1],[0,4,5]), ([3,1,5],[0,2,4]), ([5,0,4],[1,3,2]), ([3,5,0],[4,2,1]), ([4,3,5],[1,2,0]), ([1,0,5],[3,4,2]), ([0,5,1],[2,3,4]), ([2,5,3],[1,4,0]), ([3,1,2],[0,5,4]), ([0,4,5],[1,3,2]), ([4,2,1],[3,5,0]), ([4,1,2],[0,5,3]), ([4,2,0],[3,5,1]), ([2,0,1],[5,3,4]), ([1,2,3],[0,5,4]), ([2,1,3],[5,4,0]), ([1,0,3],[5,2,4]), ([5,0,2],[1,4,3]), ([4,2,5],[0,3,1]), ([0,5,2],[3,1,4]), ([1,3,0],[4,5,2]), ([3,0,4],[2,5,1]), ([3,2,5],[4,1,0]), ([2,0,3],[5,1,4]), ([4,0,5],[1,2,3]), ([1,4,5],[0,2,3]), ([0,1,2],[4,5,3]), ([3,4,5],[0,2,1]), ([4,1,2],[0,3,5]), ([0,3,1],[4,2,5]), ([1,0,2],[4,3,5]), ([0,1,3],[5,2,4]), ([2,1,3],[5,4,0]), ([4,2,5],[1,3,0]), ([2,3,1],[4,0,5]), ([1,4,3],[2,5,0]), ([2,4,5],[0,1,3]), ([4,2,1],[3,0,5]), ([3,0,2],[5,4,1]), ([1,0,4],[2,5,3]), ([0,3,2],[5,1,4]), ([5,4,3],[1,0,2]), ([5,0,3],[1,2,4]), ([3,1,4],[2,5,0]), ([5,0,4],[1,3,2]), ([5,3,2],[0,1,4]), ([3,0,5],[2,1,4]), ([4,1,0],[3,5,2]), ([1,4,3],[2,0,5]), ([0,1,4],[3,2,5]), ([5,4,0],[1,3,2]), ([2,5,1],[3,4,0]), ([3,1,0],[4,5,2]), ([5,4,3],[0,1,2]), ([1,2,4],[3,5,0]), ([3,1,4],[0,2,5]), ([4,3,2],[0,1,5]), ([4,0,2],[3,5,1]), ([0,2,4],[3,1,5]), ([1,4,5],[2,3,0]), ([1,0,3],[2,4,5]), ([0,2,1],[3,4,5]), ([4,1,2],[3,0,5]), ([0,3,5],[4,1,2]), ([0,2,1],[3,4,5]), ([1,4,5],[0,3,2]), ([1,2,5],[3,4,0]), ([3,5,1],[2,0,4]), ([4,0,5],[1,2,3]), ([3,1,2],[0,4,5]), ([2,5,3],[1,4,0]), ([0,4,3],[5,1,2]), ([2,0,3],[4,5,1]), ([0,2,3],[5,4,1]), ([5,3,4],[2,0,1]), ([1,3,0],[5,2,4]), ([2,5,4],[0,1,3]), ([5,2,3],[4,0,1]), ([4,5,3],[2,0,1]), ([3,4,5],[2,0,1]), ([4,3,1],[5,2,0]), ([5,1,2],[3,4,0]), ([4,2,1],[0,5,3]), ([3,5,4],[2,0,1]), ([4,2,1],[5,3,0]), ([4,1,0],[2,5,3]), ([2,0,4],[5,1,3]), ([3,0,1],[2,4,5]), ([4,2,1],[0,3,5]), ([5,2,1],[0,4,3]), ([5,2,1],[4,3,0]), ([5,4,3],[1,2,0]), ([4,1,2],[0,3,5]), ([3,2,0],[4,1,5]), ([5,3,4],[2,1,0]), ([5,0,1],[4,3,2]), ([1,3,2],[0,5,4]), ([1,3,2],[4,0,5]), ([2,0,5],[4,3,1]), ([5,0,4],[2,3,1]), ([1,3,5],[2,0,4]), ([3,1,0],[2,4,5]), ([0,5,3],[1,2,4]), ([3,1,5],[4,2,0]), ([2,3,4],[0,1,5]), ([2,4,0],[3,1,5]), ([2,3,5],[1,4,0]), ([0,4,2],[5,3,1]), ([5,2,1],[3,4,0]), ([4,3,1],[0,2,5]), ([2,5,4],[1,0,3]), ([4,3,5],[1,0,2]), ([1,5,3],[0,2,4]), ([4,2,0],[5,1,3]), ([1,5,4],[0,3,2]), ([4,0,5],[2,1,3]), ([0,5,1],[3,4,2]), ([0,3,4],[2,1,5]), ([3,5,1],[2,4,0]), ([1,4,2],[0,5,3]), ([4,1,2],[5,0,3]), ([3,1,4],[2,0,5]), ([3,1,5],[2,4,0]), ([5,1,0],[2,4,3]), ([0,3,1],[4,2,5]), ([4,3,2],[0,1,5]), ([3,2,4],[1,5,0]), ([4,3,2],[5,0,1]), ([3,0,5],[1,4,2]), ([2,4,3],[5,0,1]), ([3,2,4],[0,1,5]), ([2,3,1],[5,4,0]), ([2,1,3],[4,5,0]), ([3,4,1],[5,2,0]), ([1,5,4],[0,2,3]), ([5,1,0],[3,2,4]), ([1,4,0],[3,2,5]), ([2,0,4],[1,5,3]), ([1,5,3],[0,4,2]), ([0,2,1],[5,3,4]), ([1,0,2],[5,3,4]), ([1,5,4],[3,2,0]), ([0,1,4],[5,2,3]), ([3,4,1],[0,5,2]), ([2,3,1],[5,0,4]), ([0,4,2],[5,3,1]), ([1,0,3],[5,2,4]), ([5,2,1],[3,4,0]), ([1,2,5],[0,3,4]), ([4,0,3],[5,2,1]), ([1,5,2],[3,4,0]), ([3,2,5],[0,4,1]), ([2,4,5],[1,0,3]), ([1,0,5],[3,4,2]), ([3,1,5],[2,0,4]), ([1,5,3],[4,2,0]), ([1,3,2],[0,5,4]), ([0,2,3],[4,1,5]), ([5,3,1],[0,2,4]), ([4,2,5],[3,1,0]), ([0,4,2],[3,5,1]), ([1,0,3],[5,2,4]), ([3,5,2],[0,1,4]), ([1,0,2],[4,3,5]), ([1,2,3],[5,0,4]), ([5,4,0],[3,1,2]), ([3,5,4],[1,0,2]), ([4,1,0],[2,5,3]), ([1,0,5],[4,3,2]), ([5,2,0],[4,1,3]), ([2,5,4],[0,1,3]), ([1,3,0],[2,5,4]), ([0,4,1],[3,5,2]), ([1,3,0],[4,5,2]), ([0,3,5],[4,1,2]), ([1,2,0],[3,5,4]), ([5,2,4],[1,0,3]), ([4,3,1],[5,0,2]), ([2,3,1],[0,4,5]), ([2,1,3],[4,5,0]), ([1,0,5],[3,4,2]), ([1,2,5],[4,0,3]), ([2,0,3],[5,1,4]), ([3,0,4],[2,1,5]), ([1,2,3],[4,0,5]), ([2,3,0],[1,4,5]), ([4,0,3],[5,1,2]), ([5,2,3],[1,4,0]), ([4,3,0],[2,1,5]), ([2,5,1],[0,4,3]), ([2,5,0],[3,1,4]), ([4,0,5],[1,3,2]), ([3,2,5],[0,4,1]), ([2,4,0],[1,3,5]), ([3,2,0],[5,1,4]), ([1,5,2],[3,4,0]), ([2,0,3],[1,5,4]), ([3,0,1],[4,5,2]), ([5,0,1],[4,3,2]), ([2,5,0],[4,3,1]), ([2,1,3],[5,0,4]), ([5,2,0],[1,3,4]), ([5,0,4],[3,2,1]), ([1,2,0],[5,3,4]), ([0,5,1],[2,3,4]), ([5,3,2],[4,1,0]), ([2,4,1],[0,3,5]), ([0,4,1],[2,3,5]), ([0,4,1],[2,3,5]), ([0,5,2],[4,1,3]), ([2,4,0],[1,5,3]), ([4,2,1],[0,5,3]), ([2,3,0],[4,1,5]), ([2,4,0],[3,1,5]), ([4,2,3],[5,0,1]), ([0,3,4],[5,2,1]), ([3,1,0],[2,5,4]), ([5,0,1],[2,4,3]), ([0,1,5],[3,2,4]), ([3,4,0],[5,2,1]), ([3,2,1],[5,0,4]), ([2,1,4],[5,3,0]), ([2,1,4],[3,5,0]), ([3,4,1],[5,2,0]), ([1,3,5],[2,0,4]), ([3,5,1],[0,4,2]), ([1,5,2],[3,0,4]), ([3,0,4],[2,5,1]), ([3,5,4],[2,1,0]), ([2,3,5],[0,1,4]), ([0,1,5],[2,3,4]), ([5,0,2],[3,4,1]), ([0,4,2],[1,5,3]), ([2,5,4],[3,0,1]), ([4,1,2],[5,0,3]), ([0,4,5],[2,3,1]), ([1,3,4],[5,2,0]), ([3,4,1],[5,0,2]), ([1,0,5],[2,3,4]), ([1,5,3],[2,4,0]), ([2,3,1],[0,5,4]), ([0,4,5],[3,2,1]), ([4,3,0],[2,1,5]), ([3,4,5],[2,0,1]), ([5,1,4],[2,0,3]), ([0,5,3],[2,1,4]), ([4,1,3],[5,2,0]), ([3,5,2],[4,0,1]), ([0,3,4],[2,1,5]), ([0,4,2],[1,3,5]), ([0,2,1],[5,3,4]), ([5,1,0],[2,3,4]), ([2,5,0],[1,4,3]), ([5,1,3],[0,2,4]), ([3,5,0],[4,2,1]), ([2,4,1],[5,3,0]), ([1,2,0],[4,3,5]), ([5,4,2],[3,1,0]), ([2,3,5],[0,4,1]), ([4,5,0],[3,2,1]), ([0,4,5],[2,1,3]), ([1,4,5],[0,2,3]), ([2,3,1],[5,0,4]), ([1,3,5],[0,2,4]), ([4,0,5],[3,1,2]), ([3,1,5],[0,4,2]), ([4,1,2],[5,0,3]), ([4,0,2],[5,3,1]), ([0,2,3],[1,5,4]), ([1,0,2],[3,5,4]), ([5,4,3],[0,1,2]), ([0,4,3],[1,5,2]), ([1,5,2],[0,3,4]), ([5,2,4],[1,3,0]), ([0,3,5],[4,1,2]), ([4,2,5],[0,3,1]), ([4,3,5],[1,2,0]), ([0,5,1],[4,3,2]), ([4,2,0],[1,5,3]), ([4,3,2],[5,0,1]), ([2,3,1],[5,4,0]), ([5,4,1],[0,2,3]), ([2,3,4],[1,5,0]), ([5,1,4],[3,0,2]), ([5,2,0],[4,1,3]), ([5,1,3],[2,0,4]), ([5,1,4],[3,2,0]), ([5,3,4],[1,0,2]), ([3,1,0],[5,4,2]), ([1,4,2],[3,0,5]), ([1,5,0],[4,3,2]), ([5,4,1],[0,3,2]), ([2,0,3],[1,5,4]), ([0,1,3],[4,2,5]), ([4,5,0],[3,2,1]), ([4,0,2],[1,5,3]), ([1,0,4],[2,5,3]), ([0,4,2],[5,3,1]), ([5,3,4],[2,1,0]), ([4,5,2],[3,0,1]), ([2,4,0],[3,1,5]), ([4,5,2],[1,3,0]), ([1,4,2],[0,5,3]), ([0,5,1],[4,3,2]), ([0,4,3],[2,1,5]), ([1,5,0],[3,2,4]), ([0,2,3],[5,1,4]), ([0,4,5],[1,3,2]), ([0,4,3],[1,2,5]), ([1,3,5],[2,4,0]), ([0,2,1],[4,3,5]), ([0,4,3],[2,5,1]), ([3,4,0],[2,1,5]), ([2,0,3],[1,5,4]), ([0,3,4],[1,2,5]), ([2,4,1],[5,0,3]), ([5,3,1],[2,0,4]), ([3,4,0],[5,2,1]), ([2,0,1],[4,5,3]), ([5,2,3],[1,4,0]), ([3,4,2],[0,5,1]), ([0,2,4],[5,3,1]), ([2,0,4],[3,5,1]), ([4,3,0],[2,5,1]), ([3,5,1],[4,0,2]), ([5,3,4],[0,1,2]), ([0,1,3],[2,4,5]), ([4,1,0],[5,2,3]), ([3,2,4],[0,5,1]), ([5,3,0],[2,4,1]), ([3,0,5],[2,4,1]), ([4,2,1],[5,3,0]), ([2,4,1],[3,5,0]), ([3,4,0],[1,2,5]), ([3,2,4],[0,5,1]), ([0,1,3],[2,5,4]), ([1,5,2],[3,4,0]), ([5,4,3],[1,2,0]), ([5,3,4],[0,2,1]), ([3,4,5],[0,2,1]), ([4,5,0],[2,1,3]), ([1,3,4],[2,5,0]), ([0,1,4],[5,3,2]), ([2,4,1],[3,0,5]), ([2,0,1],[3,5,4]), ([5,3,2],[4,1,0]), ([3,0,2],[1,4,5]), ([5,0,3],[2,1,4]), ([5,1,3],[0,4,2]), ([3,0,4],[1,2,5]), ([3,2,1],[5,0,4]), ([3,2,5],[0,1,4]), ([3,4,2],[0,5,1]), ([4,2,5],[1,3,0]), ([4,3,0],[2,1,5]), ([0,3,5],[4,1,2]), ([1,0,3],[4,5,2]), ([5,3,4],[1,2,0]), ([3,5,4],[0,1,2]), ([2,4,5],[0,3,1]), ([0,2,3],[5,4,1]), ([5,4,3],[1,0,2]), ([0,3,5],[4,2,1]), ([5,1,4],[0,2,3]), ([0,5,3],[2,1,4]), ([0,2,1],[5,4,3]), ([4,2,3],[1,0,5]), ([0,1,4],[2,5,3]), ([5,1,0],[2,3,4]), ([3,1,2],[0,5,4]), ([0,5,1],[3,4,2]), ([1,4,3],[5,0,2]), ([4,1,3],[2,0,5]), ([5,4,0],[2,3,1]), ([5,1,2],[3,0,4]), ([1,2,3],[0,5,4]), ([2,5,3],[0,1,4]), ([1,2,0],[5,4,3]), ([3,2,4],[0,1,5]), ([4,2,1],[5,0,3]), ([2,1,5],[0,3,4]), ([0,2,3],[5,4,1]), ([4,0,1],[2,5,3]), ([0,2,5],[3,1,4]), ([2,0,1],[4,5,3]), ([0,4,3],[2,5,1]), ([1,4,2],[5,3,0]), ([5,3,0],[2,1,4]), ([5,0,3],[2,1,4]), ([5,4,0],[1,2,3]), ([3,4,5],[2,0,1]), ([0,3,4],[1,5,2]), ([5,1,4],[3,2,0]), ([3,4,0],[2,5,1]), ([3,0,2],[4,1,5]), ([5,2,3],[0,1,4]), ([2,0,4],[3,5,1]), ([2,0,4],[5,3,1]), ([5,4,2],[3,0,1]), ([2,5,0],[4,1,3]), ([1,0,4],[3,5,2]), ([4,0,1],[2,3,5]), ([1,5,4],[3,2,0]), ([1,2,3],[4,5,0]), ([1,4,2],[5,0,3]), ([1,4,3],[5,0,2]), ([4,0,1],[3,2,5]), ([3,0,5],[1,2,4]), ([3,2,4],[5,1,0]), ([4,0,1],[2,5,3]), ([5,2,3],[4,0,1]), ([1,0,5],[2,4,3]), ([2,1,0],[3,5,4]), ([1,5,0],[4,2,3]), ([0,4,2],[3,1,5]), ([2,3,4],[5,0,1]), ([2,4,3],[5,1,0]), ([1,2,0],[5,4,3]), ([4,3,0],[5,2,1]), ([4,5,3],[0,1,2]), ([4,3,5],[2,0,1]), ([3,1,2],[4,0,5]), ([1,2,0],[4,5,3]), ([4,1,0],[3,5,2]), ([5,3,2],[0,1,4]), ([4,5,3],[1,2,0]), ([4,0,1],[5,3,2]), ([3,5,4],[0,2,1]), ([2,4,5],[0,1,3]), ([4,1,5],[3,2,0]), ([2,1,0],[3,4,5]), ([5,3,1],[0,2,4]), ([0,2,5],[3,1,4]), ([3,2,4],[0,5,1]), ([3,0,4],[1,2,5]), ([0,1,5],[4,2,3]), ([5,0,4],[3,2,1]), ([5,3,2],[0,1,4]), ([5,0,4],[2,3,1]), ([1,4,0],[2,3,5]), ([4,1,0],[2,3,5]), ([1,4,2],[0,3,5]), ([5,2,1],[3,0,4]), ([4,1,0],[2,3,5]), ([5,0,1],[4,3,2]), ([2,4,5],[1,0,3]), ([2,3,0],[5,4,1]), ([1,0,4],[3,5,2]), ([4,2,5],[0,3,1]), ([4,0,1],[2,5,3]), ([4,0,3],[2,5,1]), ([5,0,4],[3,1,2]), ([3,4,0],[1,5,2]), ([3,4,2],[0,1,5]), ([4,2,5],[0,1,3]), ([5,3,1],[0,2,4]), ([4,3,2],[1,0,5]), ([0,5,1],[2,4,3]), ([5,1,0],[3,4,2]), ([1,3,2],[4,5,0]), ([4,3,0],[5,2,1]), ([0,1,3],[5,2,4]), ([0,3,4],[2,5,1]), ([3,4,5],[0,1,2]), ([4,0,5],[3,2,1]), ([1,0,2],[5,4,3]), ([1,4,3],[5,2,0]), ([5,0,1],[4,2,3]), ([1,4,3],[0,2,5]), ([3,2,4],[1,5,0]), ([0,2,3],[4,1,5]), ([5,2,1],[4,0,3]), ([1,0,2],[5,4,3]), ([1,3,0],[5,4,2]), ([1,0,5],[2,3,4]), ([0,2,5],[1,4,3]), ([0,1,3],[4,2,5]), ([3,2,4],[1,0,5]), ([2,1,0],[4,3,5]), ([2,1,4],[3,5,0]), ([1,0,4],[2,3,5]), ([3,2,1],[5,4,0]), ([1,4,5],[2,3,0]), ([1,5,4],[2,0,3]), ([4,3,5],[2,0,1]), ([4,3,5],[0,1,2]), ([1,3,4],[2,5,0]), ([3,0,2],[4,1,5]), ([5,0,4],[2,1,3]), ([0,3,2],[5,4,1]), ([5,4,2],[3,1,0]), ([4,3,2],[0,5,1]), ([1,0,3],[5,4,2]), ([0,2,3],[1,4,5]), ([3,0,1],[5,4,2]), ([3,4,2],[0,1,5]), ([2,0,5],[1,4,3]), ([3,2,5],[4,0,1]), ([1,2,4],[5,3,0]), ([4,0,1],[2,5,3]), ([5,3,0],[4,2,1]), ([0,4,2],[3,5,1]), ([2,5,3],[1,4,0])] for x in perms: first = x[0] second = x[1] if sum([self.scores[y] for y in first]) == sum([self.scores[y] for y in second]): result = True break if result: self.result = "YES" else: self.result = "NO" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask890ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
3
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "output": "-1" }, { "input": "1000000000000000 1000000000", "output": "-1" }, { "input": "1000000000000000 100", "output": "1953125" }, { "input": "1 2", "output": "-1" }, { "input": "4 3", "output": "4" }, { "input": "4 4", "output": "-1" }, { "input": "9 3", "output": "9" }, { "input": "21 3", "output": "7" }, { "input": "67280421310721 1", "output": "1" }, { "input": "6 3", "output": "3" }, { "input": "3 3", "output": "-1" }, { "input": "16 3", "output": "4" }, { "input": "1 1000", "output": "-1" }, { "input": "16 4", "output": "8" }, { "input": "36 8", "output": "18" }, { "input": "49 4", "output": "-1" }, { "input": "9 4", "output": "-1" }, { "input": "16 1", "output": "1" }, { "input": "16 6", "output": "-1" }, { "input": "16 5", "output": "16" }, { "input": "25 4", "output": "-1" }, { "input": "4010815561 2", "output": "63331" }, { "input": "49 3", "output": "49" }, { "input": "36 6", "output": "9" }, { "input": "36 10", "output": "-1" }, { "input": "25 3", "output": "25" }, { "input": "22876792454961 28", "output": "7625597484987" }, { "input": "1234 2", "output": "2" }, { "input": "179458711 2", "output": "179458711" }, { "input": "900104343024121 100000", "output": "-1" }, { "input": "8 3", "output": "4" }, { "input": "100 6", "output": "20" }, { "input": "15500 26", "output": "-1" }, { "input": "111111 1", "output": "1" }, { "input": "100000000000000 200", "output": "160000000000" }, { "input": "1000000000000 100", "output": "6400000" }, { "input": "100 10", "output": "-1" }, { "input": "1000000000039 2", "output": "1000000000039" }, { "input": "64 5", "output": "16" }, { "input": "999999961946176 33", "output": "63245552" }, { "input": "376219076689 3", "output": "376219076689" }, { "input": "999999961946176 63", "output": "999999961946176" }, { "input": "1048576 12", "output": "2048" }, { "input": "745 21", "output": "-1" }, { "input": "748 6", "output": "22" }, { "input": "999999961946176 50", "output": "161082468097" }, { "input": "10 3", "output": "5" }, { "input": "1099511627776 22", "output": "2097152" }, { "input": "1000000007 100010", "output": "-1" }, { "input": "3 1", "output": "1" }, { "input": "100 8", "output": "50" }, { "input": "100 7", "output": "25" }, { "input": "7 2", "output": "7" }, { "input": "999999961946176 64", "output": "-1" }, { "input": "20 5", "output": "10" }, { "input": "999999999999989 2", "output": "999999999999989" }, { "input": "100000000000000 114", "output": "10240000" }, { "input": "99999640000243 3", "output": "9999991" }, { "input": "999998000001 566", "output": "333332666667" }, { "input": "99999820000081 2", "output": "9999991" }, { "input": "49000042000009 3", "output": "49000042000009" }, { "input": "151491429961 4", "output": "-1" }, { "input": "32416190071 2", "output": "32416190071" }, { "input": "1000 8", "output": "25" }, { "input": "1999967841 15", "output": "1999967841" }, { "input": "26880 26880", "output": "-1" }, { "input": "151491429961 3", "output": "151491429961" }, { "input": "90000000000 300", "output": "100000000" }, { "input": "98765004361 10", "output": "-1" }, { "input": "15 2", "output": "3" }, { "input": "16 2", "output": "2" }, { "input": "1996 2", "output": "2" }, { "input": "1997 2", "output": "1997" }, { "input": "1999 2", "output": "1999" }, { "input": "1998 2", "output": "2" }, { "input": "1998 1", "output": "1" }, { "input": "1998 7", "output": "27" }, { "input": "1998 8", "output": "37" }, { "input": "100000380000361 2", "output": "10000019" }, { "input": "15 1", "output": "1" }, { "input": "100000000000000 226", "output": "-1" }, { "input": "844030857550613 517", "output": "-1" }, { "input": "4567890 14", "output": "430" }, { "input": "123123123 123123123", "output": "-1" }, { "input": "24 4", "output": "4" }, { "input": "999999993568952 17", "output": "31622777" }, { "input": "99999999994190 9", "output": "241656799" }, { "input": "999997874844049 4", "output": "-1" }, { "input": "99999999999931 2", "output": "99999999999931" }, { "input": "2 3", "output": "-1" }, { "input": "67280421310721 2", "output": "67280421310721" } ]
1,634,627,767
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
0
import math def lowerdivisors(n): int_sqrt_n = int(math.sqrt(n)) ld = [] for i in range(1, int_sqrt_n + 1): if n%i == 0: ld.append(i) return ld def kthdivisor(n, k): ld = lowerdivisors(n) if k > (2 * len(ld)): return -1 if k <= len(ld): return ld[k-1] return n//(ld[(2*len(ld))-k]) n, k = [int(x) for x in input().split()] print(kthdivisor(n, k))
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). Output Specification: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Demo Input: ['4 2\n', '5 3\n', '12 5\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
```python import math def lowerdivisors(n): int_sqrt_n = int(math.sqrt(n)) ld = [] for i in range(1, int_sqrt_n + 1): if n%i == 0: ld.append(i) return ld def kthdivisor(n, k): ld = lowerdivisors(n) if k > (2 * len(ld)): return -1 if k <= len(ld): return ld[k-1] return n//(ld[(2*len(ld))-k]) n, k = [int(x) for x in input().split()] print(kthdivisor(n, k)) ```
0
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,694,975,278
2,147,483,647
Python 3
OK
TESTS
71
92
0
import sys # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") # sys.stderr = open("error.txt", "w") # # your remaining code t = int(input()) mn = 0 isum = 0 for i in range(t) : a , b = map(int,input().split()) isum -= a isum += b if isum > mn : mn = isum print(mn)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python import sys # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") # sys.stderr = open("error.txt", "w") # # your remaining code t = int(input()) mn = 0 isum = 0 for i in range(t) : a , b = map(int,input().split()) isum -= a isum += b if isum > mn : mn = isum print(mn) ```
3
793
A
Oleg and shares
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
[ "3 3\n12 9 15\n", "2 2\n10 9\n", "4 1\n1 1000000000 1000000000 1000000000\n" ]
[ "3", "-1", "2999999997" ]
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
500
[ { "input": "3 3\n12 9 15", "output": "3" }, { "input": "2 2\n10 9", "output": "-1" }, { "input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997" }, { "input": "1 11\n123", "output": "0" }, { "input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14", "output": "151" }, { "input": "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54", "output": "-1" }, { "input": "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260", "output": "2157" }, { "input": "100 18\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354", "output": "-1" }, { "input": "4 2\n1 2 3 4", "output": "-1" }, { "input": "3 4\n3 5 5", "output": "-1" }, { "input": "3 2\n88888884 88888886 88888888", "output": "3" }, { "input": "2 1\n1000000000 1000000000", "output": "0" }, { "input": "4 2\n1000000000 100000000 100000000 100000000", "output": "450000000" }, { "input": "2 2\n1000000000 1000000000", "output": "0" }, { "input": "3 3\n3 2 1", "output": "-1" }, { "input": "3 4\n3 5 3", "output": "-1" }, { "input": "3 2\n1 2 2", "output": "-1" }, { "input": "4 2\n2 3 3 2", "output": "-1" }, { "input": "3 2\n1 2 4", "output": "-1" }, { "input": "3 2\n3 4 4", "output": "-1" }, { "input": "3 3\n4 7 10", "output": "3" }, { "input": "4 3\n2 2 5 1", "output": "-1" }, { "input": "3 3\n1 3 5", "output": "-1" }, { "input": "2 5\n5 9", "output": "-1" }, { "input": "2 3\n5 7", "output": "-1" }, { "input": "3 137\n1000000000 1000000000 1000000000", "output": "0" }, { "input": "5 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 5\n1 2 5", "output": "-1" }, { "input": "3 3\n1000000000 1000000000 999999997", "output": "2" }, { "input": "2 4\n5 6", "output": "-1" }, { "input": "4 1\n1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "2 3\n5 8", "output": "1" }, { "input": "2 6\n8 16", "output": "-1" }, { "input": "5 3\n15 14 9 12 18", "output": "-1" }, { "input": "3 3\n1 2 3", "output": "-1" }, { "input": "3 3\n3 4 5", "output": "-1" }, { "input": "2 5\n8 17", "output": "-1" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "1 1\n1000000000", "output": "0" }, { "input": "3 3\n5 3 4", "output": "-1" }, { "input": "3 6\n10 14 12", "output": "-1" }, { "input": "2 2\n3 5", "output": "1" }, { "input": "3 5\n1 3 4", "output": "-1" }, { "input": "4 3\n1 6 6 6", "output": "-1" }, { "input": "2 3\n1 8", "output": "-1" }, { "input": "3 5\n6 11 17", "output": "-1" }, { "input": "2 2\n1 4", "output": "-1" }, { "input": "2 4\n6 8", "output": "-1" }, { "input": "2 1\n2 3", "output": "1" }, { "input": "4 4\n1 5 8 14", "output": "-1" }, { "input": "3 3\n1 5 3", "output": "-1" }, { "input": "4 3\n1 2 2 5", "output": "-1" }, { "input": "3 2\n1 4 6", "output": "-1" }, { "input": "2 3\n6 9", "output": "1" }, { "input": "3 3\n2 3 4", "output": "-1" }, { "input": "3 2\n9 10 10", "output": "-1" }, { "input": "2 2\n9 12", "output": "-1" }, { "input": "2 2\n100000003 100000005", "output": "1" }, { "input": "2 3\n2 4", "output": "-1" }, { "input": "3 2\n2 3 5", "output": "-1" }, { "input": "3 3\n1 3 4", "output": "-1" }, { "input": "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "4499999991" }, { "input": "3 5\n2 4 5", "output": "-1" }, { "input": "2 3\n7 10", "output": "1" }, { "input": "3 10\n10 13 17", "output": "-1" }, { "input": "2 3\n1 6", "output": "-1" }, { "input": "1 7\n1000000000", "output": "0" }, { "input": "2 4\n3 7", "output": "1" }, { "input": "2 3\n2 5", "output": "1" }, { "input": "20 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 3\n7 8 8", "output": "-1" }, { "input": "4 10\n1 11 100 11", "output": "-1" } ]
1,639,895,317
2,147,483,647
PyPy 3
OK
TESTS
88
171
10,956,800
n,k=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() x=min(a) ans=0 c=True for i in a: if (i-x)%k!=0: c=False break else: ans=ans+(i-x)//k if c==False: print(-1) else: print(ans)
Title: Oleg and shares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. Output Specification: Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. Demo Input: ['3 3\n12 9 15\n', '2 2\n10 9\n', '4 1\n1 1000000000 1000000000 1000000000\n'] Demo Output: ['3', '-1', '2999999997'] Note: Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
```python n,k=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() x=min(a) ans=0 c=True for i in a: if (i-x)%k!=0: c=False break else: ans=ans+(i-x)//k if c==False: print(-1) else: print(ans) ```
3
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&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,601,352,458
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
109
307,200
n = int(input()) lista = [i for i in range((n+1)//2, 0, -1)if i < n-i] a,b = 0,0 def div(a,b): for i in range(2, a): if a % i == 0 and b % i == 0: return True return False for i in range(len(lista)): a, b = lista[i], n-lista[i] if div(a,b) == False: break print(a, b)
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 n = int(input()) lista = [i for i in range((n+1)//2, 0, -1)if i < n-i] a,b = 0,0 def div(a,b): for i in range(2, a): if a % i == 0 and b % i == 0: return True return False for i in range(len(lista)): a, b = lista[i], n-lista[i] if div(a,b) == False: break print(a, b) ```
0
435
A
Queue on Bus Stop
PROGRAMMING
1,000
[ "implementation" ]
null
null
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue. Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*).
Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside.
[ "4 3\n2 3 2 1\n", "3 4\n1 2 1\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "4 3\n2 3 2 1", "output": "3" }, { "input": "3 4\n1 2 1", "output": "1" }, { "input": "1 5\n4", "output": "1" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "6 4\n1 3 2 3 4 1", "output": "5" }, { "input": "6 8\n6 1 1 1 4 5", "output": "3" }, { "input": "10 10\n1 10 1 10 1 1 7 8 6 7", "output": "8" }, { "input": "100 100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "63" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "10" }, { "input": "10 2\n2 2 1 1 1 1 1 2 1 2", "output": "8" }, { "input": "10 3\n1 3 1 1 3 2 2 2 3 3", "output": "9" }, { "input": "10 4\n2 1 1 1 3 4 4 4 1 2", "output": "6" }, { "input": "10 5\n2 2 3 4 4 1 5 3 1 2", "output": "7" }, { "input": "100 3\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2", "output": "83" }, { "input": "100 7\n4 7 4 7 7 4 7 3 5 6 3 5 4 3 7 2 7 2 4 1 6 3 3 7 4 4 5 4 3 6 4 3 2 2 1 4 4 1 7 3 7 7 1 3 1 5 4 1 5 3 5 2 2 1 5 5 1 5 2 7 5 5 1 5 5 4 6 5 1 3 5 6 7 4 1 3 3 4 3 2 7 6 5 7 2 7 1 1 2 2 3 1 3 7 1 3 2 1 1 7", "output": "71" }, { "input": "100 10\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "output": "64" }, { "input": "100 15\n3 12 8 3 11 14 12 14 1 11 13 3 5 13 4 14 2 11 7 8 12 9 15 7 15 1 4 11 6 12 1 3 8 13 1 8 14 4 3 14 1 3 1 6 10 15 13 11 12 1 14 13 11 14 11 3 12 7 3 15 14 4 5 6 5 14 7 14 6 2 6 12 6 13 13 1 9 13 15 11 6 3 15 11 9 4 15 8 15 12 1 15 10 10 4 1 15 1 4 1", "output": "71" }, { "input": "100 30\n7 14 22 16 11 13 7 29 20 19 22 6 12 16 1 8 27 21 22 3 15 27 20 12 4 19 1 26 26 22 25 17 29 25 16 29 29 28 16 26 25 14 16 20 5 21 5 15 19 13 17 21 17 19 23 13 1 25 6 30 16 19 12 10 28 8 15 13 14 24 19 30 12 19 22 1 3 14 16 3 20 26 15 19 9 10 19 27 2 16 10 22 15 13 19 3 24 9 8 13", "output": "71" }, { "input": "100 40\n39 19 13 36 11 21 32 12 1 2 39 26 32 39 24 1 4 19 10 4 16 39 32 34 13 24 30 35 3 10 8 18 13 12 39 27 31 40 37 20 17 17 37 5 10 12 22 17 7 1 31 13 11 10 2 6 22 16 2 4 9 27 6 35 22 16 22 30 33 2 26 20 35 19 40 37 19 17 21 28 37 28 40 4 5 4 35 19 26 36 19 12 21 20 21 30 9 16 9 32", "output": "65" }, { "input": "100 50\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1", "output": "60" }, { "input": "100 60\n34 21 39 17 48 46 23 56 46 52 50 39 55 48 54 38 32 38 24 26 44 12 28 9 25 26 10 52 42 60 41 3 16 60 44 29 27 55 19 19 19 57 45 59 29 35 5 14 50 47 57 48 16 7 12 36 58 31 37 58 30 50 19 11 10 41 59 57 49 41 33 9 12 11 53 50 60 51 21 9 44 23 1 16 4 15 17 57 15 17 46 50 18 52 43 24 47 50 19 18", "output": "74" }, { "input": "100 90\n74 65 49 41 3 79 61 83 50 40 13 57 90 14 62 77 36 10 3 5 5 40 50 75 32 26 3 71 79 54 88 50 46 20 42 59 30 36 83 86 60 62 82 68 62 80 18 65 28 28 81 74 62 33 61 35 33 83 90 72 6 6 51 4 22 20 29 10 8 3 84 69 12 17 24 16 12 64 80 74 68 59 1 59 15 59 37 58 79 83 51 56 81 14 37 45 19 31 61 90", "output": "67" }, { "input": "100 99\n69 46 76 47 71 9 66 46 78 17 96 83 56 96 29 3 43 48 79 23 93 61 19 9 29 72 15 84 93 46 71 87 11 43 96 44 54 75 3 66 2 95 46 32 69 52 79 38 57 53 37 60 71 82 28 31 84 58 89 40 62 74 22 50 45 38 99 67 24 28 28 12 69 88 33 10 31 71 46 7 42 81 54 81 96 44 8 1 20 24 28 19 54 35 69 32 71 13 66 15", "output": "68" }, { "input": "90 100\n25 52 88 89 36 17 57 64 66 11 89 61 54 92 48 51 18 42 44 92 6 14 67 100 16 21 17 88 85 73 33 11 94 84 56 72 4 80 90 78 96 5 62 70 54 70 94 80 10 91 100 89 98 87 69 74 88 63 53 79 38 94 89 52 21 82 67 79 100 81 2 40 30 69 34 15 12 33 87 52 95 18 51 30 15 39 30 99 46 84", "output": "67" }, { "input": "5 100\n14 67 15 28 21", "output": "2" }, { "input": "10 100\n2 17 53 94 95 57 36 47 68 48", "output": "7" }, { "input": "1 100\n18", "output": "1" }, { "input": "100 1\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": "30 100\n56 7 99 83 2 65 35 53 99 36 42 57 13 37 68 52 87 11 50 23 86 24 32 39 97 6 64 1 18 86", "output": "18" }, { "input": "60 100\n18 75 43 88 45 43 20 59 59 79 62 39 53 21 28 46 54 53 97 81 18 15 2 95 84 9 36 70 30 76 17 19 83 40 45 32 31 70 23 14 44 35 79 84 97 96 99 60 3 73 64 83 6 12 67 86 70 89 18 61", "output": "40" }, { "input": "1 73\n24", "output": "1" }, { "input": "4 4\n1 4 4 4", "output": "4" }, { "input": "2 6\n1 4", "output": "1" }, { "input": "2 5\n5 5", "output": "2" } ]
1,612,872,122
2,147,483,647
Python 3
OK
TESTS
34
62
0
n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] c = 1 temp = 0 for i in a: if temp+i<=m: temp += i else: temp = i c += 1 print(c)
Title: Queue on Bus Stop Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue. Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). Output Specification: Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. Demo Input: ['4 3\n2 3 2 1\n', '3 4\n1 2 1\n'] Demo Output: ['3\n', '1\n'] Note: none
```python n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] c = 1 temp = 0 for i in a: if temp+i<=m: temp += i else: temp = i c += 1 print(c) ```
3
754
A
Lesha and array splitting
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation" ]
null
null
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array *A*. Lesha is tired now so he asked you to split the array. Help Lesha!
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*.
If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes). Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *r**i* which denote the subarray *A*[*l**i*... *r**i*] of the initial array *A* being the *i*-th new array. Integers *l**i*, *r**i* should satisfy the following conditions: - *l*1<==<=1 - *r**k*<==<=*n* - *r**i*<=+<=1<==<=*l**i*<=+<=1 for each 1<=≤<=*i*<=&lt;<=*k*. If there are multiple answers, print any of them.
[ "3\n1 2 -3\n", "8\n9 -12 3 4 -4 -10 7 3\n", "1\n0\n", "4\n1 2 3 -5\n" ]
[ "YES\n2\n1 2\n3 3\n", "YES\n2\n1 2\n3 8\n", "NO\n", "YES\n4\n1 1\n2 2\n3 3\n4 4\n" ]
none
500
[ { "input": "3\n1 2 -3", "output": "YES\n3\n1 1\n2 2\n3 3" }, { "input": "8\n9 -12 3 4 -4 -10 7 3", "output": "YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8" }, { "input": "1\n0", "output": "NO" }, { "input": "4\n1 2 3 -5", "output": "YES\n4\n1 1\n2 2\n3 3\n4 4" }, { "input": "6\n0 0 0 0 0 0", "output": "NO" }, { "input": "100\n507 -724 -243 -846 697 -569 -786 472 756 -272 731 -534 -664 202 592 -381 161 -668 -895 296 472 -868 599 396 -617 310 -283 -118 829 -218 807 939 -152 -343 -96 692 -570 110 442 159 -446 -631 -881 784 894 -3 -792 654 -273 -791 638 -599 -763 586 -812 248 -590 455 926 -402 61 228 209 419 -511 310 -283 857 369 472 -82 -435 -717 -421 862 -384 659 -235 406 793 -167 -504 -432 -951 0 165 36 650 -145 -500 988 -513 -495 -476 312 -754 332 819 -797 -715", "output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..." }, { "input": "100\n1 -2 -1 -1 2 2 0 1 -1 1 0 -2 1 -1 0 -2 -1 -1 2 0 -1 2 0 1 -2 -2 -1 1 2 0 -2 -2 -1 1 1 -1 -2 -1 0 -1 2 1 -1 -2 0 2 1 1 -2 1 1 -1 2 -2 2 0 1 -1 1 -2 0 0 0 0 0 0 -2 -2 2 1 2 2 0 -1 1 1 -2 -2 -2 1 0 2 -1 -2 -1 0 0 0 2 1 -2 0 -2 0 2 1 -2 -1 2 1", "output": "YES\n78\n1 1\n2 2\n3 3\n4 4\n5 5\n6 7\n8 8\n9 9\n10 11\n12 12\n13 13\n14 15\n16 16\n17 17\n18 18\n19 20\n21 21\n22 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 39\n40 40\n41 41\n42 42\n43 43\n44 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 56\n57 57\n58 58\n59 59\n60 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 73\n74 74\n75 75\n76 76\n77 77\n78 78\n79 79\n80 81\n82 82\n83 83\n84 84\n85 88\n89 89\n90 90\n91 92\n93 94\n95 95\n96 96\n..." }, { "input": "7\n0 0 0 0 3 -3 0", "output": "YES\n2\n1 5\n6 7" }, { "input": "5\n0 0 -4 0 0", "output": "YES\n1\n1 5" }, { "input": "100\n2 -38 51 -71 -24 19 35 -27 48 18 64 -4 30 -28 74 -17 -19 -25 54 41 3 -46 -43 -42 87 -76 -62 28 1 32 7 -76 15 0 -82 -33 17 40 -41 -7 43 -18 -27 65 -27 -13 46 -38 75 7 62 -23 7 -12 80 36 37 14 6 -40 -11 -35 -77 -24 -59 75 -41 -21 17 -21 -14 67 -36 16 -1 34 -26 30 -62 -4 -63 15 -49 18 57 7 77 23 -26 8 -20 8 -16 9 50 -24 -33 9 -9 -33", "output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75 75\n76..." }, { "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 -38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "YES\n1\n1 100" }, { "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\n0 0 -17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "YES\n2\n1 34\n35 100" }, { "input": "3\n1 -3 3", "output": "YES\n3\n1 1\n2 2\n3 3" }, { "input": "3\n1 0 -1", "output": "YES\n2\n1 2\n3 3" }, { "input": "3\n3 0 0", "output": "YES\n1\n1 3" }, { "input": "3\n0 0 0", "output": "NO" }, { "input": "3\n-3 3 0", "output": "YES\n2\n1 1\n2 3" }, { "input": "4\n3 -2 -1 3", "output": "YES\n4\n1 1\n2 2\n3 3\n4 4" }, { "input": "4\n-1 0 1 0", "output": "YES\n2\n1 2\n3 4" }, { "input": "4\n0 0 0 3", "output": "YES\n1\n1 4" }, { "input": "4\n0 0 0 0", "output": "NO" }, { "input": "4\n3 0 -3 0", "output": "YES\n2\n1 2\n3 4" }, { "input": "5\n-3 2 2 0 -2", "output": "YES\n4\n1 1\n2 2\n3 4\n5 5" }, { "input": "5\n0 -1 2 0 -1", "output": "YES\n3\n1 2\n3 4\n5 5" }, { "input": "5\n0 2 0 0 0", "output": "YES\n1\n1 5" }, { "input": "5\n0 0 0 0 0", "output": "NO" }, { "input": "5\n0 0 0 0 0", "output": "NO" }, { "input": "20\n101 89 -166 -148 -38 -135 -138 193 14 -134 -185 -171 -52 -191 195 39 -148 200 51 -73", "output": "YES\n20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20" }, { "input": "20\n-118 -5 101 7 9 144 55 -55 -9 -126 -71 -71 189 -64 -187 123 0 -48 -12 138", "output": "YES\n19\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 17\n18 18\n19 19\n20 20" }, { "input": "20\n-161 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "YES\n1\n1 20" }, { "input": "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 -137 0 0 0 0 137", "output": "YES\n2\n1 19\n20 20" }, { "input": "40\n64 -94 -386 -78 35 -233 33 82 -5 -200 368 -259 124 353 390 -305 -247 -133 379 44 133 -146 151 -217 -16 53 -157 186 -203 -8 117 -71 272 -290 -97 133 52 113 -280 -176", "output": "YES\n40\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40" }, { "input": "40\n120 -96 -216 131 231 -80 -166 -102 16 227 -120 105 43 -83 -53 229 24 190 -268 119 230 348 -33 19 0 -187 -349 -25 80 -38 -30 138 -104 337 -98 0 1 -66 -243 -231", "output": "YES\n38\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 36\n37 37\n38 38\n39 39\n40 40" }, { "input": "40\n0 0 0 0 0 0 324 0 0 0 0 0 0 0 0 0 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": "YES\n1\n1 40" }, { "input": "40\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", "output": "NO" }, { "input": "40\n0 0 0 0 0 308 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -308 0 0 0 0 0 0 0", "output": "YES\n2\n1 32\n33 40" }, { "input": "60\n-288 -213 -213 -23 496 489 137 -301 -219 -296 -577 269 -153 -52 -505 -138 -377 500 -256 405 588 274 -115 375 -93 117 -360 -160 429 -339 502 310 502 572 -41 -26 152 -203 562 -525 -179 -67 424 62 -329 -127 352 -474 417 -30 518 326 200 -598 471 107 339 107 -9 -244", "output": "YES\n60\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60" }, { "input": "60\n112 141 -146 -389 175 399 -59 327 -41 397 263 -422 157 0 471 -2 -381 -438 99 368 173 9 -171 118 24 111 120 70 11 317 -71 -574 -139 0 -477 -211 -116 -367 16 568 -75 -430 75 -179 -21 156 291 -422 441 -224 -8 -337 -104 381 60 -138 257 91 103 -359", "output": "YES\n58\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60" }, { "input": "60\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 -238 0 0 0 0 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": "YES\n1\n1 60" }, { "input": "60\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", "output": "NO" }, { "input": "60\n0 0 0 0 0 0 0 0 0 -98 0 0 0 0 0 0 0 0 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "YES\n2\n1 18\n19 60" }, { "input": "80\n-295 -774 -700 -366 -304 -173 -672 288 -721 -256 -348 650 223 211 379 -13 -483 162 800 631 -550 -704 -357 -306 490 713 -80 -234 -669 675 -688 471 315 607 -87 -327 -799 514 248 379 271 325 -244 98 -100 -447 574 -154 554 -377 380 -423 -140 -147 -189 -420 405 464 -110 273 -226 -109 -578 641 -426 -548 214 -184 -397 570 -428 -676 652 -155 127 462 338 534 -782 -481", "output": "YES\n80\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..." }, { "input": "80\n237 66 409 -208 -460 4 -448 29 -420 -192 -21 -76 -147 435 205 -42 -299 -29 244 -480 -4 -38 2 -214 -311 556 692 111 -19 -84 -90 -350 -354 125 -207 -137 93 367 -481 -462 -440 -92 424 -107 221 -100 -631 -72 105 201 226 -90 197 -264 427 113 202 -144 -115 398 331 147 56 -24 292 -267 -31 -11 202 506 334 -103 534 -155 -472 -124 -257 209 12 360", "output": "YES\n80\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..." }, { "input": "80\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 668 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "YES\n1\n1 80" }, { "input": "80\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", "output": "NO" }, { "input": "80\n0 0 0 0 0 0 0 0 0 0 0 0 -137 137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "YES\n2\n1 13\n14 80" }, { "input": "100\n-98 369 544 197 -991 231 399 521 582 -820 -650 -919 -615 -411 -843 -974 231 140 239 -209 721 84 -834 -27 162 460 -157 -40 0 -778 -491 -607 -34 -647 834 -7 -518 -5 -31 -766 -54 -698 -838 497 980 -77 238 549 -135 7 -629 -892 455 181 527 314 465 -321 656 -390 368 384 601 332 561 -1000 -636 -106 412 -216 -58 -365 -155 -445 404 114 260 -392 -20 840 -395 620 -860 -936 1 882 958 536 589 235 300 676 478 434 229 698 157 -95 908 -170", "output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75 75\n76..." }, { "input": "100\n-149 -71 -300 288 -677 -580 248 49 -167 264 -215 878 7 252 -239 25 -369 -22 526 -415 -175 173 549 679 161 -411 743 -454 -34 -714 282 -198 -47 -519 -45 71 615 -214 -317 399 86 -97 246 689 -22 -197 -139 237 -501 477 -385 -421 -463 -641 409 -279 538 -382 48 189 652 -696 74 303 6 -183 336 17 -178 -617 -739 280 -202 454 864 218 480 293 -118 -518 -24 -866 -357 410 239 -833 510 316 -168 38 -370 -22 741 470 -60 -507 -209 704 141 -148", "output": "YES\n100\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n7..." }, { "input": "100\n0 0 697 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "YES\n1\n1 100" }, { "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\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 -475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 475 0 0 0 0", "output": "YES\n2\n1 95\n96 100" }, { "input": "4\n0 0 3 -3", "output": "YES\n2\n1 3\n4 4" }, { "input": "4\n1 0 0 0", "output": "YES\n1\n1 4" }, { "input": "4\n3 3 3 3", "output": "YES\n4\n1 1\n2 2\n3 3\n4 4" }, { "input": "2\n0 1", "output": "YES\n1\n1 2" }, { "input": "4\n0 -1 1 0", "output": "YES\n2\n1 2\n3 4" }, { "input": "1\n1", "output": "YES\n1\n1 1" }, { "input": "5\n0 0 1 0 0", "output": "YES\n1\n1 5" }, { "input": "4\n0 0 1 0", "output": "YES\n1\n1 4" }, { "input": "10\n1 2 0 0 3 -3 0 0 -3 0", "output": "YES\n5\n1 1\n2 4\n5 5\n6 8\n9 10" }, { "input": "3\n0 -1 0", "output": "YES\n1\n1 3" }, { "input": "2\n1 0", "output": "YES\n1\n1 2" }, { "input": "5\n3 -3 0 0 0", "output": "YES\n2\n1 1\n2 5" }, { "input": "3\n0 1 0", "output": "YES\n1\n1 3" }, { "input": "4\n0 0 0 1", "output": "YES\n1\n1 4" }, { "input": "4\n1 -1 1 -1", "output": "YES\n4\n1 1\n2 2\n3 3\n4 4" }, { "input": "1\n-1", "output": "YES\n1\n1 1" }, { "input": "2\n1 1", "output": "YES\n2\n1 1\n2 2" }, { "input": "2\n1 -1", "output": "YES\n2\n1 1\n2 2" }, { "input": "2\n0 0", "output": "NO" }, { "input": "2\n0 -1", "output": "YES\n1\n1 2" }, { "input": "2\n-1 1", "output": "YES\n2\n1 1\n2 2" }, { "input": "2\n-1 0", "output": "YES\n1\n1 2" }, { "input": "2\n-1 -1", "output": "YES\n2\n1 1\n2 2" }, { "input": "3\n5 -5 5", "output": "YES\n3\n1 1\n2 2\n3 3" }, { "input": "5\n1 0 -1 0 1", "output": "YES\n3\n1 2\n3 4\n5 5" }, { "input": "6\n0 0 0 3 0 0", "output": "YES\n1\n1 6" }, { "input": "3\n1 -1 1", "output": "YES\n3\n1 1\n2 2\n3 3" } ]
1,601,096,776
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
78
307,200
n = int(input()) A = list(map(int,input().split())) if sum(A)!= 0: print("YES") print(1) print(str(1) + " " + str(len(n))) else: i = 0 while (A[i] == 0): i+=1 if i == n: print("NO") else: print("YES") print(2) print(str(1) + " " + str(i)) print(str(i+1) + " " + str(n))
Title: Lesha and array splitting Time Limit: None seconds Memory Limit: None megabytes Problem Description: One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array *A*. Lesha is tired now so he asked you to split the array. Help Lesha! Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*. Output Specification: If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes). Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *r**i* which denote the subarray *A*[*l**i*... *r**i*] of the initial array *A* being the *i*-th new array. Integers *l**i*, *r**i* should satisfy the following conditions: - *l*1<==<=1 - *r**k*<==<=*n* - *r**i*<=+<=1<==<=*l**i*<=+<=1 for each 1<=≤<=*i*<=&lt;<=*k*. If there are multiple answers, print any of them. Demo Input: ['3\n1 2 -3\n', '8\n9 -12 3 4 -4 -10 7 3\n', '1\n0\n', '4\n1 2 3 -5\n'] Demo Output: ['YES\n2\n1 2\n3 3\n', 'YES\n2\n1 2\n3 8\n', 'NO\n', 'YES\n4\n1 1\n2 2\n3 3\n4 4\n'] Note: none
```python n = int(input()) A = list(map(int,input().split())) if sum(A)!= 0: print("YES") print(1) print(str(1) + " " + str(len(n))) else: i = 0 while (A[i] == 0): i+=1 if i == n: print("NO") else: print("YES") print(2) print(str(1) + " " + str(i)) print(str(i+1) + " " + str(n)) ```
0
16
B
Burglar and Matches
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
B. Burglar and Matches
0
64
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer.
Output the only number — answer to the problem.
[ "7 3\n5 10\n2 5\n3 6\n", "3 3\n1 3\n2 2\n3 1\n" ]
[ "62\n", "7\n" ]
none
0
[ { "input": "7 3\n5 10\n2 5\n3 6", "output": "62" }, { "input": "3 3\n1 3\n2 2\n3 1", "output": "7" }, { "input": "1 1\n1 2", "output": "2" }, { "input": "1 2\n1 9\n1 6", "output": "9" }, { "input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "output": "10" }, { "input": "2 1\n2 1", "output": "2" }, { "input": "2 2\n2 4\n1 4", "output": "8" }, { "input": "2 3\n1 7\n1 2\n1 5", "output": "12" }, { "input": "4 1\n2 2", "output": "4" }, { "input": "4 2\n1 10\n4 4", "output": "22" }, { "input": "4 3\n1 4\n6 4\n1 7", "output": "19" }, { "input": "5 1\n10 5", "output": "25" }, { "input": "5 2\n3 9\n2 2", "output": "31" }, { "input": "5 5\n2 9\n3 1\n2 1\n1 8\n2 8", "output": "42" }, { "input": "5 10\n1 3\n1 2\n1 9\n1 10\n1 1\n1 5\n1 10\n1 2\n1 3\n1 7", "output": "41" }, { "input": "10 1\n9 4", "output": "36" }, { "input": "10 2\n14 3\n1 3", "output": "30" }, { "input": "10 7\n4 8\n1 10\n1 10\n1 2\n3 3\n1 3\n1 10", "output": "71" }, { "input": "10 10\n1 8\n2 10\n1 9\n1 1\n1 9\n1 6\n1 4\n2 5\n1 2\n1 4", "output": "70" }, { "input": "10 4\n1 5\n5 2\n1 9\n3 3", "output": "33" }, { "input": "100 5\n78 6\n29 10\n3 6\n7 3\n2 4", "output": "716" }, { "input": "1000 7\n102 10\n23 6\n79 4\n48 1\n34 10\n839 8\n38 4", "output": "8218" }, { "input": "10000 10\n336 2\n2782 5\n430 10\n1893 7\n3989 10\n2593 8\n165 6\n1029 2\n2097 4\n178 10", "output": "84715" }, { "input": "100000 3\n2975 2\n35046 4\n61979 9", "output": "703945" }, { "input": "1000000 4\n314183 9\n304213 4\n16864 5\n641358 9", "output": "8794569" }, { "input": "10000000 10\n360313 10\n416076 1\n435445 9\n940322 7\n1647581 7\n4356968 10\n3589256 2\n2967933 5\n2747504 7\n1151633 3", "output": "85022733" }, { "input": "100000000 7\n32844337 7\n11210848 7\n47655987 1\n33900472 4\n9174763 2\n32228738 10\n29947408 5", "output": "749254060" }, { "input": "200000000 10\n27953106 7\n43325979 4\n4709522 1\n10975786 4\n67786538 8\n48901838 7\n15606185 6\n2747583 1\n100000000 1\n633331 3", "output": "1332923354" }, { "input": "200000000 9\n17463897 9\n79520463 1\n162407 4\n41017993 8\n71054118 4\n9447587 2\n5298038 9\n3674560 7\n20539314 5", "output": "996523209" }, { "input": "200000000 8\n6312706 6\n2920548 2\n16843192 3\n1501141 2\n13394704 6\n10047725 10\n4547663 6\n54268518 6", "output": "630991750" }, { "input": "200000000 7\n25621043 2\n21865270 1\n28833034 1\n22185073 5\n100000000 2\n13891017 9\n61298710 8", "output": "931584598" }, { "input": "200000000 6\n7465600 6\n8453505 10\n4572014 8\n8899499 3\n86805622 10\n64439238 6", "output": "1447294907" }, { "input": "200000000 5\n44608415 6\n100000000 9\n51483223 9\n44136047 1\n52718517 1", "output": "1634907859" }, { "input": "200000000 4\n37758556 10\n100000000 6\n48268521 3\n20148178 10", "output": "1305347138" }, { "input": "200000000 3\n65170000 7\n20790088 1\n74616133 4", "output": "775444620" }, { "input": "200000000 2\n11823018 6\n100000000 9", "output": "970938108" }, { "input": "200000000 1\n100000000 6", "output": "600000000" }, { "input": "200000000 10\n12097724 9\n41745972 5\n26982098 9\n14916995 7\n21549986 7\n3786630 9\n8050858 7\n27994924 4\n18345001 5\n8435339 5", "output": "1152034197" }, { "input": "200000000 10\n55649 8\n10980981 9\n3192542 8\n94994808 4\n3626106 1\n100000000 6\n5260110 9\n4121453 2\n15125061 4\n669569 6", "output": "1095537357" }, { "input": "10 20\n1 7\n1 7\n1 8\n1 3\n1 10\n1 7\n1 7\n1 9\n1 3\n1 1\n1 2\n1 1\n1 3\n1 10\n1 9\n1 8\n1 8\n1 6\n1 7\n1 5", "output": "83" }, { "input": "10000000 20\n4594 7\n520836 8\n294766 6\n298672 4\n142253 6\n450626 1\n1920034 9\n58282 4\n1043204 1\n683045 1\n1491746 5\n58420 4\n451217 2\n129423 4\n246113 5\n190612 8\n912923 6\n473153 6\n783733 6\n282411 10", "output": "54980855" }, { "input": "200000000 20\n15450824 5\n839717 10\n260084 8\n1140850 8\n28744 6\n675318 3\n25161 2\n5487 3\n6537698 9\n100000000 5\n7646970 9\n16489 6\n24627 3\n1009409 5\n22455 1\n25488456 4\n484528 9\n32663641 3\n750968 4\n5152 6", "output": "939368573" }, { "input": "200000000 20\n16896 2\n113 3\n277 2\n299 7\n69383562 2\n3929 8\n499366 4\n771846 5\n9 4\n1278173 7\n90 2\n54 7\n72199858 10\n17214 5\n3 10\n1981618 3\n3728 2\n141 8\n2013578 9\n51829246 5", "output": "1158946383" }, { "input": "200000000 20\n983125 2\n7453215 9\n9193588 2\n11558049 7\n28666199 1\n34362244 1\n5241493 5\n15451270 4\n19945845 8\n6208681 3\n38300385 7\n6441209 8\n21046742 7\n577198 10\n3826434 8\n9764276 8\n6264675 7\n8567063 3\n3610303 4\n2908232 3", "output": "1131379312" }, { "input": "10 15\n1 6\n2 6\n3 4\n1 3\n1 2\n1 5\n1 6\n1 2\n2 9\n1 10\n1 3\n1 7\n1 8\n1 2\n2 9", "output": "79" }, { "input": "10000000 15\n111 5\n914124 3\n3 9\n177790 1\n2352 3\n32138 9\n104477 1\n1223 4\n18 6\n6655580 4\n57643 10\n94309 2\n37 1\n227002 10\n1733193 7", "output": "45116295" }, { "input": "200000000 15\n7069868 1\n5567826 8\n2310059 10\n13539782 7\n38420939 4\n29911411 8\n52256316 1\n12265839 9\n2074265 1\n24896428 9\n72470695 5\n3236301 1\n3890243 2\n65168965 8\n65724 6", "output": "1489289257" }, { "input": "200000000 15\n12044094 7\n2475138 10\n944451 7\n4854766 2\n3809145 10\n7727571 2\n43908937 6\n2745883 1\n427511 2\n100000000 5\n190914 6\n554889 3\n288798 4\n1848572 5\n893874 3", "output": "961871671" }, { "input": "200000000 15\n6334191 7\n1927941 4\n5175933 10\n468389 1\n433043 10\n6863198 5\n7480646 4\n14774279 10\n2921129 8\n18325627 7\n6973152 9\n8277324 9\n21522856 2\n2058070 1\n2444742 4", "output": "664376069" } ]
1,604,789,872
2,147,483,647
Python 3
OK
TESTS
49
218
307,200
n, m = input().split() n = int(n) m = int(m) dec = {} lis = [] for i in range(int(m)): a, b = input().split() a = int(a) b = int(b) pr = (a, b) lis.append(pr) lis.sort(key=lambda x: x[1], reverse=True) max_count = 0 for i in range(len(lis)): if lis[i][0] <= n: n = n-lis[i][0] max_count += lis[i][0]*lis[i][1] else: max_count += n*lis[i][1] n = 0 if n == 0: break print(max_count)
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. Output Specification: Output the only number — answer to the problem. Demo Input: ['7 3\n5 10\n2 5\n3 6\n', '3 3\n1 3\n2 2\n3 1\n'] Demo Output: ['62\n', '7\n'] Note: none
```python n, m = input().split() n = int(n) m = int(m) dec = {} lis = [] for i in range(int(m)): a, b = input().split() a = int(a) b = int(b) pr = (a, b) lis.append(pr) lis.sort(key=lambda x: x[1], reverse=True) max_count = 0 for i in range(len(lis)): if lis[i][0] <= n: n = n-lis[i][0] max_count += lis[i][0]*lis[i][1] else: max_count += n*lis[i][1] n = 0 if n == 0: break print(max_count) ```
3
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "input": "8\n4\n1\n10\n59392", "output": "59392" }, { "input": "4\n1\n8\n7\n44835", "output": "44835" }, { "input": "6\n1\n7\n2\n62982", "output": "62982" }, { "input": "2\n7\n4\n9\n56937", "output": "35246" }, { "input": "2\n9\n8\n1\n75083", "output": "75083" }, { "input": "8\n7\n7\n6\n69038", "output": "24656" }, { "input": "4\n4\n2\n3\n54481", "output": "36320" }, { "input": "6\n4\n9\n8\n72628", "output": "28244" }, { "input": "9\n7\n8\n10\n42357", "output": "16540" }, { "input": "5\n6\n4\n3\n60504", "output": "36302" }, { "input": "7\n2\n3\n8\n21754", "output": "15539" }, { "input": "1\n2\n10\n4\n39901", "output": "39901" }, { "input": "3\n4\n7\n1\n58048", "output": "58048" }, { "input": "9\n10\n4\n6\n52003", "output": "21956" }, { "input": "5\n10\n9\n3\n70149", "output": "32736" }, { "input": "5\n5\n5\n10\n55592", "output": "11118" }, { "input": "1\n5\n2\n6\n49547", "output": "49547" }, { "input": "3\n7\n7\n7\n84046", "output": "36019" }, { "input": "10\n2\n1\n8\n63537", "output": "63537" }, { "input": "7\n2\n10\n5\n81684", "output": "53678" }, { "input": "7\n1\n6\n8\n99831", "output": "99831" }, { "input": "3\n9\n3\n3\n61082", "output": "20360" }, { "input": "5\n5\n8\n9\n79228", "output": "29931" }, { "input": "1\n5\n5\n6\n89535", "output": "89535" }, { "input": "5\n5\n2\n1\n7682", "output": "7682" }, { "input": "7\n4\n8\n8\n25829", "output": "9224" }, { "input": "3\n4\n3\n3\n87079", "output": "43539" }, { "input": "5\n8\n4\n9\n5226", "output": "2438" }, { "input": "4\n9\n6\n6\n1070", "output": "415" }, { "input": "10\n10\n10\n10\n100000", "output": "10000" }, { "input": "1\n1\n1\n1\n1", "output": "1" }, { "input": "10\n10\n10\n10\n1", "output": "0" }, { "input": "10\n10\n1\n10\n10", "output": "10" }, { "input": "10\n10\n1\n10\n100", "output": "100" }, { "input": "2\n2\n2\n2\n1", "output": "0" } ]
1,694,837,550
2,147,483,647
Python 3
OK
TESTS
40
92
0
q=int(input()) w=int(input()) e=int(input()) r=int(input()) t=int(input()) y=0 for dragon in range(1,t+1): if dragon %q == 0 or dragon % w ==0 or dragon % e ==0 or dragon % r == 0: y+=1 print(y)
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? Input Specification: Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). Output Specification: Output the number of damaged dragons. Demo Input: ['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n'] Demo Output: ['12\n', '17\n'] Note: In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
```python q=int(input()) w=int(input()) e=int(input()) r=int(input()) t=int(input()) y=0 for dragon in range(1,t+1): if dragon %q == 0 or dragon % w ==0 or dragon % e ==0 or dragon % r == 0: y+=1 print(y) ```
3
78
A
Haiku
PROGRAMMING
800
[ "implementation", "strings" ]
A. Haiku
2
256
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not.
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
[ "on codeforces \nbeta round is running\n a rustling of keys \n", "how many gallons\nof edo s rain did you drink\n cuckoo\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "on codeforces \nbeta round is running\n a rustling of keys ", "output": "YES" }, { "input": "how many gallons\nof edo s rain did you drink\n cuckoo", "output": "NO" }, { "input": " hatsu shigure\n saru mo komino wo\nhoshige nari", "output": "YES" }, { "input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae", "output": "NO" }, { "input": " furuike ya\nkawazu tobikomu\nmizu no oto ", "output": "YES" }, { "input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ", "output": "NO" }, { "input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det", "output": "YES" }, { "input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel", "output": "NO" }, { "input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti", "output": "NO" }, { "input": "kutaburete\nyado karu koro ya\nfuji no hana", "output": "YES" }, { "input": " beginnings of poetry\n the rice planting songs \n of the interior", "output": "NO" }, { "input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden", "output": "NO" }, { "input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut", "output": "YES" }, { "input": "writing in the dark\nunaware that my pen\nhas run out of ink", "output": "NO" }, { "input": "kusaaiu\nuieueua\nuo efaa", "output": "YES" }, { "input": "v\nh\np", "output": "NO" }, { "input": "i\ni\nu", "output": "NO" }, { "input": "awmio eoj\nabdoolceegood\nwaadeuoy", "output": "YES" }, { "input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo", "output": "YES" }, { "input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr", "output": "YES" }, { "input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd", "output": "YES" }, { "input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ", "output": "YES" }, { "input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs", "output": "YES" }, { "input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn", "output": "NO" }, { "input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl", "output": "NO" }, { "input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr", "output": "NO" }, { "input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf", "output": "NO" }, { "input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi", "output": "NO" }, { "input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu", "output": "NO" }, { "input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt", "output": "NO" }, { "input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo", "output": "NO" }, { "input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau", "output": "NO" }, { "input": "ab\na\na", "output": "NO" }, { "input": "on codeforcs\nbeta round is runnineg\na rustling of keys", "output": "NO" }, { "input": "coooooooooooooooood\nd\nd", "output": "NO" }, { "input": "on codeforces \nbeta round is runninog\n a rustling of keys", "output": "NO" }, { "input": "aaaaaaaaaaaaaaa\na\na", "output": "NO" }, { "input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "output": "YES" }, { "input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "output": "NO" }, { "input": "aaaaaa\naaaaaa\naaaaa", "output": "NO" } ]
1,641,724,106
2,147,483,647
Python 3
OK
TESTS
40
124
0
def is_haiku(l1, l2, l3): vowel = ['a', 'e', 'i', 'o', 'u'] lines = [l1, l2, l3] vowel_count = [0, 0, 0] for index in range(len(lines)): for char in lines[index]: if char in vowel: vowel_count[index] += 1 return vowel_count == [5, 7, 5] print("YES" if is_haiku(input(), input(), input()) else "NO")
Title: Haiku Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input Specification: The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Specification: Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Demo Input: ['on codeforces \nbeta round is running\n a rustling of keys \n', 'how many gallons\nof edo s rain did you drink\n cuckoo\n'] Demo Output: ['YES', 'NO'] Note: none
```python def is_haiku(l1, l2, l3): vowel = ['a', 'e', 'i', 'o', 'u'] lines = [l1, l2, l3] vowel_count = [0, 0, 0] for index in range(len(lines)): for char in lines[index]: if char in vowel: vowel_count[index] += 1 return vowel_count == [5, 7, 5] print("YES" if is_haiku(input(), input(), input()) else "NO") ```
3.969
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,386,609,083
2,147,483,647
Python 3
OK
TESTS
32
124
0
n=int(input()) d=list(map(int,input().split())) for i in range(len(d)): d[i]=d[i]%2 print(d.index(int(d.count(1)==1))+1)
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 n=int(input()) d=list(map(int,input().split())) for i in range(len(d)): d[i]=d[i]%2 print(d.index(int(d.count(1)==1))+1) ```
3.969
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,667,324,683
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
13
2,000
0
a,b = list(map(int, input().split(sep = " "))) n = int(input()) for j in range(n): l,r = list(map(int, input().split(sep = " "))) m = -1 for k in range(r,l-1,-1): if (a%k == 0 and b%k == 0): m = k break print(m)
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 a,b = list(map(int, input().split(sep = " "))) n = int(input()) for j in range(n): l,r = list(map(int, input().split(sep = " "))) m = -1 for k in range(r,l-1,-1): if (a%k == 0 and b%k == 0): m = k break print(m) ```
0
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message.
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "output": "vyvvysyooysyo" }, { "input": "L\ngggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\ngggggggggggggggggggggggggggggggggggggggggg", "output": "ffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nxgwurenkxkiau,c,vonei.zltazmnkhqtwuogkgvgckvja,z.rhanuy.ybebmzcfwozkwvuuiolaqlgvvvewnbuinrncgjwjdsfw", "output": "cheitrmlclosi.v.bpmro/x;ysx,mljwyeiphlhbhvlbks.x/tjsmiu/unrn,xvgepxlebiiop;sw;hbbbremniomtmvhkekfdge" }, { "input": "L\nuoz.vmks,wxrb,nwcvdzh.m,hwsios.lvu,ktes,,ythddhm.sh,d,c,cfj.wqam,bowofbyx,jathqayhreqvixvbmgdokofmym", "output": "ipx/b,ld.ectn.mevbfxj/,.jedopd/;bi.lyrd..uyjffj,/dj.f.v.vgk/ews,.npepgnuc.ksyjwsujtrwbocbn,hfplpg,u," }, { "input": "R\noedjyrvuw/rn.v.hdwndbiposiewgsn.pnyf;/tsdohp,hrtd/mx,;coj./billd..mwbneohcikrdes/ucjr,wspthleyp,..f,", "output": "iwshtecyq.eb,c,gsqbsvuoiauwqfab,obtdl.rasigomgers.nzmlxih,.vukks,,nqvbwigxujeswa.yxhemqaorgkwtom,,dm" }, { "input": "R\nvgj;o;ijrtfyck,dthccioltcx,crub;oceooognsuvfx/kgo.fbsudv,yod.erdrxhbeiyltxhnrobbb;ydrgroefcr/f;uvdjd", "output": "cfhliluherdtxjmsrgxxuikrxzmxeyvlixwiiifbaycdz.jfi,dvayscmtis,wesezgvwutkrzgbeivvvltsefeiwdxe.dlycshs" }, { "input": "L\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", "output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }, { "input": "L\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp" }, { "input": "L\n,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "output": "...................................................................................................." }, { "input": "L\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "R\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" }, { "input": "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" }, { "input": "R\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "L\nq", "output": "w" }, { "input": "L\no", "output": "p" }, { "input": "L\n,", "output": "." }, { "input": "L\nz", "output": "x" }, { "input": "R\n.", "output": "," }, { "input": "R\no", "output": "i" }, { "input": "R\nw", "output": "q" }, { "input": "R\nx", "output": "z" }, { "input": "R\n,./", "output": "m,." }, { "input": "R\nwertuk;;/", "output": "qweryjll." }, { "input": "L\n..", "output": "//" } ]
1,678,078,486
2,147,483,647
Python 3
OK
TESTS
31
46
0
letters = [ ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'], ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';'], ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'] ] d = input() s = input() new_s = [] for l in s: if l in letters[0]: i = [0, letters[0].index(l)] elif l in letters[1]: i = [1, letters[1].index(l)] else: i = [2, letters[2].index(l)] if d == 'L': i[1] += 1 else: i[1] -= 1 new_s.append(letters[i[0]][i[1]]) print(''.join(new_s))
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input Specification: First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Specification: Print a line that contains the original message. Demo Input: ['R\ns;;upimrrfod;pbr\n'] Demo Output: ['allyouneedislove\n'] Note: none
```python letters = [ ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'], ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';'], ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'] ] d = input() s = input() new_s = [] for l in s: if l in letters[0]: i = [0, letters[0].index(l)] elif l in letters[1]: i = [1, letters[1].index(l)] else: i = [2, letters[2].index(l)] if d == 'L': i[1] += 1 else: i[1] -= 1 new_s.append(letters[i[0]][i[1]]) print(''.join(new_s)) ```
3
409
H
A + B Strikes Back
PROGRAMMING
1,500
[ "*special", "brute force", "constructive algorithms", "dsu", "implementation" ]
null
null
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space.
Output the sum of the given integers.
[ "5 14\n", "381 492\n" ]
[ "19\n", "873\n" ]
none
0
[ { "input": "5 14", "output": "19" }, { "input": "381 492", "output": "873" }, { "input": "536 298", "output": "834" }, { "input": "143 522", "output": "665" }, { "input": "433 126", "output": "559" }, { "input": "723 350", "output": "1073" }, { "input": "632 264", "output": "896" }, { "input": "923 488", "output": "1411" }, { "input": "522 92", "output": "614" }, { "input": "953 553", "output": "1506" }, { "input": "242 86", "output": "328" }, { "input": "151 691", "output": "842" }, { "input": "441 915", "output": "1356" }, { "input": "740 519", "output": "1259" }, { "input": "339 433", "output": "772" }, { "input": "629 657", "output": "1286" }, { "input": "538 261", "output": "799" }, { "input": "828 485", "output": "1313" }, { "input": "117 399", "output": "516" }, { "input": "399 280", "output": "679" } ]
1,675,420,329
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
# LUOGU_RID: 101338716 a=int(input()) b=int(input()) print(a+b) print()
Title: A + B Strikes Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input Specification: The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. Output Specification: Output the sum of the given integers. Demo Input: ['5 14\n', '381 492\n'] Demo Output: ['19\n', '873\n'] Note: none
```python # LUOGU_RID: 101338716 a=int(input()) b=int(input()) print(a+b) print() ```
-1
598
B
Queries on a String
PROGRAMMING
1,300
[ "implementation", "strings" ]
null
null
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given. One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right. For example, if the string *s* is abacaba and the query is *l*1<==<=3,<=*r*1<==<=6,<=*k*1<==<=1 then the answer is abbacaa. If after that we would process the query *l*2<==<=1,<=*r*2<==<=4,<=*k*2<==<=2 then we would get the string baabcaa.
The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters. Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries. The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|,<=1<=≤<=*k**i*<=≤<=1<=000<=000) — the description of the *i*-th query.
Print the resulting string *s* after processing all *m* queries.
[ "abacaba\n2\n3 6 1\n1 4 2\n" ]
[ "baabcaa\n" ]
The sample is described in problem statement.
0
[ { "input": "abacaba\n2\n3 6 1\n1 4 2", "output": "baabcaa" }, { "input": "u\n1\n1 1 1", "output": "u" }, { "input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4", "output": "p" }, { "input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6", "output": "ssssssssss" }, { "input": "tcpyzttcpo\n10\n2 3 6\n2 4 1\n2 6 9\n7 10 5\n2 3 5\n4 5 6\n3 4 5\n7 9 4\n9 10 7\n1 10 8", "output": "zctycopttp" }, { "input": "yywlblbblw\n10\n4 7 2\n3 8 2\n4 10 6\n4 7 1\n3 9 6\n1 7 3\n3 7 3\n3 7 1\n1 8 7\n2 7 5", "output": "bylwlwylbb" }, { "input": "thisisahacktest\n1\n1 2 1", "output": "htisisahacktest" }, { "input": "ozozumuhackleyan\n1\n1 4 1", "output": "zozoumuhackleyan" }, { "input": "lacongaithattuyet\n1\n1 1 1", "output": "lacongaithattuyet" } ]
1,664,254,692
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
31
0
s = list(input()) m = int(input()) while m: l, r, k = map(int, input().split()) k = k % (r - l) l = l - 1 s[l : r] = s[l : r][::-1] s[l : l + k] = s[l : l + k][::-1] s[l + k : r] = s[l + k : r][::-1] m = m - 1 print(''.join(s))
Title: Queries on a String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given. One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right. For example, if the string *s* is abacaba and the query is *l*1<==<=3,<=*r*1<==<=6,<=*k*1<==<=1 then the answer is abbacaa. If after that we would process the query *l*2<==<=1,<=*r*2<==<=4,<=*k*2<==<=2 then we would get the string baabcaa. Input Specification: The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters. Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries. The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|,<=1<=≤<=*k**i*<=≤<=1<=000<=000) — the description of the *i*-th query. Output Specification: Print the resulting string *s* after processing all *m* queries. Demo Input: ['abacaba\n2\n3 6 1\n1 4 2\n'] Demo Output: ['baabcaa\n'] Note: The sample is described in problem statement.
```python s = list(input()) m = int(input()) while m: l, r, k = map(int, input().split()) k = k % (r - l) l = l - 1 s[l : r] = s[l : r][::-1] s[l : l + k] = s[l : l + k][::-1] s[l + k : r] = s[l + k : r][::-1] m = m - 1 print(''.join(s)) ```
-1
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,952,299
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n = int(input()) array = list(map(int,input().split())) total = sum(array) t = 0 if total%3 != 0: print(0) exit() else: b = total//3 left = 0 total1 = [0] for i in range(n): if total1 != b: left += 1 total1 += array[left] else: right = i+1 total2 = 0 for _ in range(i+1,n): total2 += array[right] if total2 == total1: t += 1 break print(t)
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()) array = list(map(int,input().split())) total = sum(array) t = 0 if total%3 != 0: print(0) exit() else: b = total//3 left = 0 total1 = [0] for i in range(n): if total1 != b: left += 1 total1 += array[left] else: right = i+1 total2 = 0 for _ in range(i+1,n): total2 += array[right] if total2 == total1: t += 1 break print(t) ```
-1
616
A
Comparing Two Long Integers
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().
The first line contains a non-negative integer *a*. The second line contains a non-negative integer *b*. The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits.
Print the symbol "&lt;" if *a*<=&lt;<=*b* and the symbol "&gt;" if *a*<=&gt;<=*b*. If the numbers are equal print the symbol "=".
[ "9\n10\n", "11\n10\n", "00012345\n12345\n", "0123\n9\n", "0123\n111\n" ]
[ "&lt;\n", "&gt;\n", "=\n", "&gt;\n", "&gt;\n" ]
none
0
[ { "input": "9\n10", "output": "<" }, { "input": "11\n10", "output": ">" }, { "input": "00012345\n12345", "output": "=" }, { "input": "0123\n9", "output": ">" }, { "input": "0123\n111", "output": ">" }, { "input": "9\n9", "output": "=" }, { "input": "0\n0000", "output": "=" }, { "input": "1213121\n1213121", "output": "=" }, { "input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479", "output": ">" }, { "input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\n8", "output": ">" }, { "input": "9\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772", "output": "<" }, { "input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "0000000001\n2", "output": "<" }, { "input": "1000000000000000000000000000000000\n1000000000000000000000000000000001", "output": "<" }, { "input": "123456123456123456123456123456123456123456123456123456123456123456\n123456123456123456123456123456123456123456123456123456123456123456123456123456", "output": "<" }, { "input": "1111111111111111111111111111111111111111\n2222222222222222222222222222222222222222", "output": "<" }, { "input": "123456789999999\n123456789999999", "output": "=" }, { "input": "111111111111111111111111111111\n222222222222222222222222222222", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "587345873489573457357834\n47957438573458347574375348", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333", "output": "<" }, { "input": "11111111111111111111111111111111111\n44444444444444444444444444444444444", "output": "<" }, { "input": "11111111111111111111111111111111111\n22222222222222222222222222222222222", "output": "<" }, { "input": "9999999999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "<" }, { "input": "1\n2", "output": "<" }, { "input": "9\n0", "output": ">" }, { "input": "222222222222222222222222222222222222222222222222222222222\n22222222222222222222222222222222222222222222222222222222222", "output": "<" }, { "input": "66646464222222222222222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "11111111111111111111111111111111111111\n44444444444444444444444444444444444444", "output": "<" }, { "input": "01\n2", "output": "<" }, { "input": "00\n01", "output": "<" }, { "input": "99999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999", "output": "=" }, { "input": "43278947323248843213443272432\n793439250984509434324323453435435", "output": "<" }, { "input": "0\n1", "output": "<" }, { "input": "010\n011", "output": "<" }, { "input": "999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "0001001\n0001010", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "00000\n00", "output": "=" }, { "input": "999999999999999999999999999\n999999999999999999999999999", "output": "=" }, { "input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "001\n000000000010", "output": "<" }, { "input": "01\n10", "output": "<" }, { "input": "555555555555555555555555555555555555555555555555555555555555\n555555555555555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "5555555555555555555555555555555555555555555555555\n5555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "01\n02", "output": "<" }, { "input": "001111\n0001111", "output": "=" }, { "input": "55555555555555555555555555555555555555555555555555\n55555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "1029301293019283091283091283091280391283\n1029301293019283091283091283091280391283", "output": "=" }, { "input": "001\n2", "output": "<" }, { "input": "000000000\n000000000", "output": "=" }, { "input": "000000\n10", "output": "<" }, { "input": "000000000000000\n001", "output": "<" }, { "input": "0000001\n2", "output": "<" }, { "input": "0000\n123", "output": "<" }, { "input": "951\n960", "output": "<" }, { "input": "002\n0001", "output": ">" }, { "input": "0000001\n01", "output": "=" }, { "input": "99999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "12345678901234567890123456789012345678901234567890123456789012\n12345678901234567890123456789012345678901234567890123456789012", "output": "=" }, { "input": "02\n01", "output": ">" }, { "input": "00000111111\n00000110111", "output": ">" }, { "input": "0123\n123", "output": "=" }, { "input": "123771237912798378912\n91239712798379812897389123123123123", "output": "<" }, { "input": "00001\n002", "output": "<" }, { "input": "0000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "=" }, { "input": "000000001\n00002", "output": "<" }, { "input": "00002\n00003", "output": "<" }, { "input": "000123456\n123457", "output": "<" }, { "input": "01\n00", "output": ">" }, { "input": "00\n0", "output": "=" }, { "input": "10\n11", "output": "<" }, { "input": "0011\n12", "output": "<" }, { "input": "00\n1", "output": "<" }, { "input": "0\n0", "output": "=" }, { "input": "00\n10", "output": "<" }, { "input": "011\n10", "output": ">" }, { "input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091", "output": "<" }, { "input": "0000001\n00", "output": ">" }, { "input": "01\n1", "output": "=" }, { "input": "010\n001", "output": ">" }, { "input": "100\n111", "output": "<" }, { "input": "1\n0", "output": ">" }, { "input": "000000\n000000000000000000000", "output": "=" }, { "input": "010101\n010101", "output": "=" }, { "input": "00000000000000000001111111111111111111111111111111111111111111111111111111\n11111111111111111111111", "output": ">" }, { "input": "0000000\n0", "output": "=" }, { "input": "187923712738712879387912839182381\n871279397127389781927389718923789178923897123", "output": "<" }, { "input": "0010\n030", "output": "<" } ]
1,678,344,767
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
46
2,764,800
a,b=map(int,input().split()) if a<b: print("<") if a==b: print("=") if a>b: print(">")
Title: Comparing Two Long Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input Specification: The first line contains a non-negative integer *a*. The second line contains a non-negative integer *b*. The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. Output Specification: Print the symbol "&lt;" if *a*<=&lt;<=*b* and the symbol "&gt;" if *a*<=&gt;<=*b*. If the numbers are equal print the symbol "=". Demo Input: ['9\n10\n', '11\n10\n', '00012345\n12345\n', '0123\n9\n', '0123\n111\n'] Demo Output: ['&lt;\n', '&gt;\n', '=\n', '&gt;\n', '&gt;\n'] Note: none
```python a,b=map(int,input().split()) if a<b: print("<") if a==b: print("=") if a>b: print(">") ```
-1
817
C
Really Big Numbers
PROGRAMMING
1,600
[ "binary search", "brute force", "dp", "math" ]
null
null
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018).
Print one integer — the quantity of really big numbers that are not greater than *n*.
[ "12 1\n", "25 20\n", "10 9\n" ]
[ "3\n", "0\n", "1\n" ]
In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20). In the third example 10 is the only really big number (10 - 1 ≥ 9).
0
[ { "input": "12 1", "output": "3" }, { "input": "25 20", "output": "0" }, { "input": "10 9", "output": "1" }, { "input": "300 1000", "output": "0" }, { "input": "500 1000", "output": "0" }, { "input": "1000 2000", "output": "0" }, { "input": "10000 1000", "output": "8991" }, { "input": "1000000000000000000 1000000000000000000", "output": "0" }, { "input": "1000000000000000000 100000000000000000", "output": "899999999999999991" }, { "input": "1000000000000000000 10000000000000000", "output": "989999999999999991" }, { "input": "1000000000000000000 1000000000000000", "output": "998999999999999991" }, { "input": "1000000000000000000 100000000000000", "output": "999899999999999991" }, { "input": "1000000000000000000 200000000000000000", "output": "799999999999999991" }, { "input": "10 5", "output": "1" }, { "input": "20 5", "output": "11" }, { "input": "20 9", "output": "11" }, { "input": "100 9", "output": "91" }, { "input": "1 1", "output": "0" }, { "input": "130 118", "output": "1" }, { "input": "190 181", "output": "0" }, { "input": "1999 1971", "output": "10" }, { "input": "100 99", "output": "1" }, { "input": "6909094398 719694282", "output": "6189400069" }, { "input": "260 258", "output": "0" }, { "input": "35 19", "output": "6" }, { "input": "100 87", "output": "1" }, { "input": "91 89", "output": "0" }, { "input": "109 89", "output": "10" }, { "input": "109 91", "output": "10" }, { "input": "20331 11580", "output": "8732" }, { "input": "405487470 255750281", "output": "149737161" }, { "input": "17382 12863", "output": "4493" }, { "input": "19725 14457", "output": "5246" }, { "input": "24848 15384", "output": "9449" }, { "input": "25727 15982", "output": "9728" }, { "input": "109 90", "output": "10" }, { "input": "1000000000000000000 999999999999999999", "output": "1" }, { "input": "1000000000000000000 999999999999999998", "output": "1" }, { "input": "1009 980", "output": "10" }, { "input": "999999999999999999 999999999999999838", "output": "0" }, { "input": "1000000000000000000 99999999999999800", "output": "900000000000000061" }, { "input": "8785369357 3377262261", "output": "5408107058" }, { "input": "110 109", "output": "0" }, { "input": "999 777", "output": "200" }, { "input": "327170000015578 77230000029054", "output": "249939999986479" }, { "input": "12515000022229 1791000022317", "output": "10723999999880" }, { "input": "9999999999999 9999999999882", "output": "10" }, { "input": "213 196", "output": "14" }, { "input": "92 82", "output": "0" }, { "input": "148 136", "output": "0" }, { "input": "8 9", "output": "0" }, { "input": "309 299", "output": "0" }, { "input": "9999 9963", "output": "10" }, { "input": "82 81", "output": "0" }, { "input": "9999999 9999936", "output": "10" }, { "input": "171 155", "output": "2" }, { "input": "999 972", "output": "10" }, { "input": "999999999999 999999999891", "output": "10" }, { "input": "9 9", "output": "0" }, { "input": "6900 6885", "output": "1" }, { "input": "96 57", "output": "27" }, { "input": "5 4", "output": "0" }, { "input": "17386 5814", "output": "11557" }, { "input": "493679757404593 316259583979965", "output": "177420173424564" }, { "input": "18474 9478", "output": "8975" }, { "input": "270091571496186 250931112649966", "output": "19160458846177" }, { "input": "565751690089037 381448507916936", "output": "184303182172038" }, { "input": "19 10", "output": "0" } ]
1,497,547,179
8,079
Python 3
WRONG_ANSWER
TESTS
0
46
0
inp = list(map(int, input().split())) n, s = inp[0], inp[1] a = int(s/9) b = a-1 c = 0 while b > 0: c = c*10 + 1 b = int(b /10) while c > 0: b = b*10 + min(int(a/c), 9) a = a%c print(a) print(c) c = int(c/10) if a != 0 or s % 9 != 0: print(max(0, n - (b+1)*10 + 1)) else: print(max(0, n - b*10 + 1))
Title: Really Big Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. Input Specification: The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). Output Specification: Print one integer — the quantity of really big numbers that are not greater than *n*. Demo Input: ['12 1\n', '25 20\n', '10 9\n'] Demo Output: ['3\n', '0\n', '1\n'] Note: In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20). In the third example 10 is the only really big number (10 - 1 ≥ 9).
```python inp = list(map(int, input().split())) n, s = inp[0], inp[1] a = int(s/9) b = a-1 c = 0 while b > 0: c = c*10 + 1 b = int(b /10) while c > 0: b = b*10 + min(int(a/c), 9) a = a%c print(a) print(c) c = int(c/10) if a != 0 or s % 9 != 0: print(max(0, n - (b+1)*10 + 1)) else: print(max(0, n - b*10 + 1)) ```
0
371
C
Hamburgers
PROGRAMMING
1,600
[ "binary search", "brute force" ]
null
null
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again. Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese. Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
[ "BBBSSC\n6 4 1\n1 2 3\n4\n", "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n" ]
[ "2\n", "7\n", "200000000001\n" ]
none
1,500
[ { "input": "BBBSSC\n6 4 1\n1 2 3\n4", "output": "2" }, { "input": "BBC\n1 10 1\n1 10 1\n21", "output": "7" }, { "input": "BSC\n1 1 1\n1 1 3\n1000000000000", "output": "200000000001" }, { "input": "B\n1 1 1\n1 1 1\n381", "output": "382" }, { "input": "BSC\n3 5 6\n7 3 9\n100", "output": "10" }, { "input": "BSC\n100 1 1\n100 1 1\n100", "output": "51" }, { "input": "SBBCCSBB\n1 50 100\n31 59 21\n100000", "output": "370" }, { "input": "BBBBCCCCCCCCCCCCCCCCCCCCSSSSBBBBBBBBSS\n100 100 100\n1 1 1\n3628800", "output": "95502" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n200", "output": "0" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n2000", "output": "1" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300", "output": "0" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300000000", "output": "42858" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n914159265358", "output": "130594181" }, { "input": "SSSSSSSSSSBBBBBBBBBCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSBB\n31 53 97\n13 17 31\n914159265358", "output": "647421579" }, { "input": "BBBCSBSBBSSSSCCCCBBCSBBBBSSBBBCBSCCSSCSSCSBSSSCCCCBSCSSBSSSCCCBBCCCSCBCBBCCSCCCCSBBCCBBBBCCCCCCBSSCB\n91 87 17\n64 44 43\n958532915587", "output": "191668251" }, { "input": "CSSCBBCCCSBSCBBBCSBBBCBSBCSCBCSCBCBSBCBCSSBBSBBCBBBBSCSBBCCBCCBCBBSBSBCSCSBBSSBBCSSBCSCSCCSSBCBBCBSB\n56 34 48\n78 6 96\n904174875419", "output": "140968956" }, { "input": "CCSCCCSBBBSCBSCSCCSSBBBSSBBBSBBBCBCSSBCSCBBCCCBCBCBCCCSSBSBBCCCCCBBSCBSCBCBBCBBCSSBCSBSSCCSCCSCCBBBS\n33 73 67\n4 56 42\n886653164314", "output": "277425898" }, { "input": "SBCSSCBBSSBCSSBBBSSBSCBSSSCBBSBBBBCSBCSBSCBSCBSCBSBSSCCCCBSBCCBCBSCCCBSCCBSBBCBSSCCCCSBSBBBSSSBCSCBC\n94 16 85\n14 18 91\n836590091442", "output": "217522127" }, { "input": "BSCSBSCCSCSSCCCSBCSSBCBBSCCBSCCSSSSSSSSSCCSBSCCBBCBBSBSCCCCBCSBSBSSBBBBBSSBSSCBCCSSBSSSCBBCSBBSBCCCB\n67 54 8\n36 73 37\n782232051273", "output": "154164772" }, { "input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSSBSBSCBBSBBCSSSSBBBBSBBCBCSBBCBCSSBBCSBSCCSCSBCSCBSCCBBCSC\n71 71 52\n52 88 3\n654400055575", "output": "137826467" }, { "input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCSC\n100 1 1\n1 17 23\n954400055575", "output": "1355681897" }, { "input": "C\n100 100 100\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n100 100 100\n100 100 100\n1000000000000", "output": "100000001" }, { "input": "B\n100 100 100\n1 1 1\n1", "output": "101" }, { "input": "SC\n2 1 1\n1 1 1\n100000000000", "output": "50000000001" }, { "input": "B\n100 1 1\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n1 1 1\n100 100 100\n1000000000000", "output": "100000000" }, { "input": "CC\n1 1 1\n100 100 100\n1", "output": "0" }, { "input": "B\n100 100 100\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "BSC\n100 100 100\n1 1 1\n1000000000000", "output": "333333333433" }, { "input": "BSC\n100 100 100\n1 1 1\n1", "output": "100" } ]
1,621,196,820
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
204,800
from collections import Counter from math import inf recipe = Counter(input()) #demand state = list(map(int,input().split(' '))) #B S C prices = list(map(int,input().split(' '))) rubles = int(input()) max_result,min_val = 0,inf if recipe['B'] != 0: min_val = min(state[0] // recipe['B'],min_val) if recipe['S'] != 0: min_val = min(state[1] // recipe['S'],min_val) if recipe['C'] != 0: min_val = min(state[2] // recipe['C'],min_val) state[0] -= min_val * recipe['B'] state[1] -= min_val * recipe['S'] state[2] -= min_val * recipe['C'] flag,max_result = True,min_val full_h = rubles // ((recipe['B'] * prices[0]) + (recipe['S'] * prices[1]) + (recipe['C'] * prices[2])) rubles -= ((recipe['B'] * prices[0]) + (recipe['S'] * prices[1]) + (recipe['C'] * prices[2])) * full_h max_result += full_h if state[0] < recipe['B'] and rubles >= prices[0]: rubles -= prices[0] * (recipe['B'] - state[0]) state[0] += (recipe['B'] - state[0]) elif state[0] < recipe['B'] and rubles < prices[0]: flag = False if state[1] < recipe['S'] and rubles >= prices[1]: rubles -= prices[1] * (recipe['S'] - state[1]) state[1] += (recipe['S'] - state[1]) elif state[1] < recipe['S'] and rubles < prices[1]: flag = False if state[2] < recipe['C'] and rubles >= prices[2]: rubles -= prices[2] * (recipe['C'] - state[2]) state[2] += (recipe['C'] - state[2]) elif state[2] < recipe['C'] and rubles < prices[2]: flag = False if flag == True: max_result += 1 print(max_result) ''' Najpierw zrob z tego co masz a potem dokup, 1.Current_recipe - [bread,cheese,sausage] 2.State - {bread:x , cheese:y, sasuage:z} Przejdź po obecnym stanie i sprawdź ile hamburgerów możesz zrobić z tego co masz, będzie to var = min(składnik[i] // zapotrzebowanie w Current_recipe[skladnik]) (możesz zrobić tyle hamburgerów na ile pozwoli ci składnik którego masz najmniej) Po ustaleniu zmiennej, przechodzisz po skladnikach i odejmujesz var * zapotrzebowanie[skladnik] od kazdego skladnika. Teraz musisz dokupic. 3.Greedy - póki możesz coś kupić iterujesz po tych skladnikach ktore masz i po kolei sprawdzasz czy jakiegoś brakuje do zrobienia jednego hamburgera, zawsze dokupujesz do jednego! Jeżeli nie masz pieniędzy koniec algorytmu. O(1) rozwiązanie: ze wszystkich rubli ktore posiadasz, kup wszystkie pelne gotowe przepisy ktore bys mógł (Sum(recipe)). + mozliwe ten jeden ktory mozesz dopelnic. '''
Title: Hamburgers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again. Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese. Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient. Input Specification: The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. Demo Input: ['BBBSSC\n6 4 1\n1 2 3\n4\n', 'BBC\n1 10 1\n1 10 1\n21\n', 'BSC\n1 1 1\n1 1 3\n1000000000000\n'] Demo Output: ['2\n', '7\n', '200000000001\n'] Note: none
```python from collections import Counter from math import inf recipe = Counter(input()) #demand state = list(map(int,input().split(' '))) #B S C prices = list(map(int,input().split(' '))) rubles = int(input()) max_result,min_val = 0,inf if recipe['B'] != 0: min_val = min(state[0] // recipe['B'],min_val) if recipe['S'] != 0: min_val = min(state[1] // recipe['S'],min_val) if recipe['C'] != 0: min_val = min(state[2] // recipe['C'],min_val) state[0] -= min_val * recipe['B'] state[1] -= min_val * recipe['S'] state[2] -= min_val * recipe['C'] flag,max_result = True,min_val full_h = rubles // ((recipe['B'] * prices[0]) + (recipe['S'] * prices[1]) + (recipe['C'] * prices[2])) rubles -= ((recipe['B'] * prices[0]) + (recipe['S'] * prices[1]) + (recipe['C'] * prices[2])) * full_h max_result += full_h if state[0] < recipe['B'] and rubles >= prices[0]: rubles -= prices[0] * (recipe['B'] - state[0]) state[0] += (recipe['B'] - state[0]) elif state[0] < recipe['B'] and rubles < prices[0]: flag = False if state[1] < recipe['S'] and rubles >= prices[1]: rubles -= prices[1] * (recipe['S'] - state[1]) state[1] += (recipe['S'] - state[1]) elif state[1] < recipe['S'] and rubles < prices[1]: flag = False if state[2] < recipe['C'] and rubles >= prices[2]: rubles -= prices[2] * (recipe['C'] - state[2]) state[2] += (recipe['C'] - state[2]) elif state[2] < recipe['C'] and rubles < prices[2]: flag = False if flag == True: max_result += 1 print(max_result) ''' Najpierw zrob z tego co masz a potem dokup, 1.Current_recipe - [bread,cheese,sausage] 2.State - {bread:x , cheese:y, sasuage:z} Przejdź po obecnym stanie i sprawdź ile hamburgerów możesz zrobić z tego co masz, będzie to var = min(składnik[i] // zapotrzebowanie w Current_recipe[skladnik]) (możesz zrobić tyle hamburgerów na ile pozwoli ci składnik którego masz najmniej) Po ustaleniu zmiennej, przechodzisz po skladnikach i odejmujesz var * zapotrzebowanie[skladnik] od kazdego skladnika. Teraz musisz dokupic. 3.Greedy - póki możesz coś kupić iterujesz po tych skladnikach ktore masz i po kolei sprawdzasz czy jakiegoś brakuje do zrobienia jednego hamburgera, zawsze dokupujesz do jednego! Jeżeli nie masz pieniędzy koniec algorytmu. O(1) rozwiązanie: ze wszystkich rubli ktore posiadasz, kup wszystkie pelne gotowe przepisy ktore bys mógł (Sum(recipe)). + mozliwe ten jeden ktory mozesz dopelnic. ''' ```
0
160
A
Twins
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
In the single line print the single number — the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
500
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 1 3", "output": "2" }, { "input": "6\n1 1 1 1 1 1", "output": "4" }, { "input": "7\n10 10 5 5 5 5 1", "output": "3" }, { "input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1", "output": "8" }, { "input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4", "output": "8" }, { "input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40", "output": "8" }, { "input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90", "output": "6" }, { "input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28", "output": "14" }, { "input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42", "output": "22" }, { "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": "51" }, { "input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2", "output": "37" }, { "input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2", "output": "36" }, { "input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3", "output": "33" }, { "input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "output": "30" }, { "input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2", "output": "29" }, { "input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1", "output": "30" }, { "input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "29" }, { "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": "30" }, { "input": "1\n1", "output": "1" }, { "input": "4\n4 1 2 3", "output": "2" }, { "input": "5\n2 2 2 4 4", "output": "2" }, { "input": "4\n100 99 99 100", "output": "2" } ]
1,690,942,305
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
n = int(input()) a = list(map(int, input().split())) count = 0 j = len(a)-1 for i in range(len(a)): if len(a) == 1: count+=1 elif i == j: count+=2 j+=1 print(count)
Title: Twins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. Output Specification: In the single line print the single number — the minimum needed number of coins. Demo Input: ['2\n3 3\n', '3\n2 1 2\n'] Demo Output: ['2\n', '2\n'] Note: In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
```python n = int(input()) a = list(map(int, input().split())) count = 0 j = len(a)-1 for i in range(len(a)): if len(a) == 1: count+=1 elif i == j: count+=2 j+=1 print(count) ```
0
186
B
Growing Mushrooms
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch. Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break. After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary. Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa. Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results. The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly. Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose.
Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
[ "2 3 3 50\n2 4\n4 2\n", "4 1 1 1\n544 397\n280 101\n280 101\n693 970\n" ]
[ "1 15.00\n2 15.00\n", "4 1656.07\n1 937.03\n2 379.99\n3 379.99\n" ]
- First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 &gt; 4·3·0.5 + 2·3.
1,000
[ { "input": "2 3 3 50\n2 4\n4 2", "output": "1 15.00\n2 15.00" }, { "input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970", "output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99" }, { "input": "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737", "output": "8 1641.50\n6 1417.00\n7 1368.25\n10 1067.00\n4 1005.25\n1 981.75\n9 861.75\n3 814.00\n5 671.75\n2 559.00" }, { "input": "10 6 1 48\n239 632\n976 315\n797 112\n1 835\n938 862\n531 884\n422 607\n152 331\n413 677\n622 978", "output": "5 3788.56\n10 3673.36\n2 3360.12\n6 3289.08\n4 2606.20\n3 2598.64\n9 2525.24\n7 2315.84\n1 2210.84\n8 1184.72" }, { "input": "8 1 4 55\n507 82\n681 492\n602 849\n367 557\n438 320\n798 699\n338 302\n391 814", "output": "3 3666.90\n6 3506.55\n8 3431.95\n2 2945.40\n4 2393.15\n1 2064.90\n5 1896.00\n7 1487.90" }, { "input": "9 6 4 80\n95 269\n95 269\n781 724\n22 269\n173 655\n972 850\n22 269\n95 269\n642 666", "output": "6 4908.00\n3 3992.80\n9 3434.40\n5 2827.60\n1 1190.00\n2 1190.00\n8 1190.00\n4 1102.40\n7 1102.40" }, { "input": "7 1 8 25\n98 713\n876 112\n990 771\n57 395\n171 899\n86 600\n459 320", "output": "3 8498.25\n5 7320.25\n2 7092.00\n1 5777.50\n6 4864.50\n7 3912.00\n4 3202.75" }, { "input": "6 1 5 9\n105 771\n105 771\n105 771\n557 985\n105 771\n105 771", "output": "4 5431.87\n1 3950.55\n2 3950.55\n3 3950.55\n5 3950.55\n6 3950.55" }, { "input": "6 2 2 78\n942 465\n593 600\n480 359\n733 648\n995 55\n526 538", "output": "1 2088.60\n5 2014.20\n4 1751.12\n2 1460.92\n6 1307.44\n3 1117.96" }, { "input": "2 1 1 1\n2 2\n2 2", "output": "1 3.98\n2 3.98" }, { "input": "2 1 1 100\n3 4\n4 3", "output": "1 4.00\n2 4.00" }, { "input": "1 1 1 1\n1 1", "output": "1 1.99" } ]
1,607,443,112
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
204,800
def I(): return list(map(int, input().split())) n, t1, t2, k = I() lis = [] for i in range(n): x, y = I() a = y * t2 - x * t1 * (k / 100) + x * t1 b = x * t2 - y * t1 * (k / 100) + y * t1 maxi = max(a, b) lis.append([i + 1, maxi]) lis.sort(key=lambda x: x[1], reverse=True) print(lis) for i, j in lis: print(f'{i} {j:.2f}')
Title: Growing Mushrooms Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch. Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break. After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary. Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa. Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results. The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier). Input Specification: The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly. Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose. Output Specification: Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate. Demo Input: ['2 3 3 50\n2 4\n4 2\n', '4 1 1 1\n544 397\n280 101\n280 101\n693 970\n'] Demo Output: ['1 15.00\n2 15.00\n', '4 1656.07\n1 937.03\n2 379.99\n3 379.99\n'] Note: - First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 &gt; 4·3·0.5 + 2·3.
```python def I(): return list(map(int, input().split())) n, t1, t2, k = I() lis = [] for i in range(n): x, y = I() a = y * t2 - x * t1 * (k / 100) + x * t1 b = x * t2 - y * t1 * (k / 100) + y * t1 maxi = max(a, b) lis.append([i + 1, maxi]) lis.sort(key=lambda x: x[1], reverse=True) print(lis) for i, j in lis: print(f'{i} {j:.2f}') ```
0
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "0\n0\n3\n3\n3\n0\n3" }, { "input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969", "output": "1\n1\n0\n1\n1\n1\n0\n1\n1" }, { "input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192", "output": "4\n4\n4\n4" }, { "input": "1\n1\n1\n1000000000", "output": "1" }, { "input": "1\n1\n1\n100005", "output": "1" }, { "input": "3\n1 2 3\n1\n100005", "output": "3" }, { "input": "2\n1 2\n3\n100004\n100005\n100006", "output": "2\n2\n2" }, { "input": "3\n1 1 1\n1\n1", "output": "3" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "3\n1 2 3\n1\n100000", "output": "3" }, { "input": "5\n1 1 1 1 10\n2\n1\n10", "output": "4\n5" }, { "input": "5\n3 10 8 6 11\n1\n10000000", "output": "5" } ]
1,699,326,666
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
12,390,400
input() shops=list(map(int,input().split())) for _ in range(int(input())): q=int(input()) count=0 for i in shops: if q>=i: count+=1 print(count)
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. Output Specification: Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. Demo Input: ['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n'] Demo Output: ['0\n4\n1\n5\n'] Note: On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
```python input() shops=list(map(int,input().split())) for _ in range(int(input())): q=int(input()) count=0 for i in shops: if q>=i: count+=1 print(count) ```
0
688
B
Lovely Palindromes
PROGRAMMING
1,000
[ "constructive algorithms", "math" ]
null
null
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number?
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
Print the *n*-th even-length palindrome number.
[ "1\n", "10\n" ]
[ "11\n", "1001\n" ]
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
1,000
[ { "input": "1", "output": "11" }, { "input": "10", "output": "1001" }, { "input": "11", "output": "1111" }, { "input": "12", "output": "1221" }, { "input": "100", "output": "100001" }, { "input": "1321", "output": "13211231" }, { "input": "2", "output": "22" }, { "input": "3", "output": "33" }, { "input": "4", "output": "44" }, { "input": "5", "output": "55" }, { "input": "6", "output": "66" }, { "input": "7", "output": "77" }, { "input": "8", "output": "88" }, { "input": "9", "output": "99" }, { "input": "13", "output": "1331" }, { "input": "14", "output": "1441" }, { "input": "15", "output": "1551" }, { "input": "16", "output": "1661" }, { "input": "17", "output": "1771" }, { "input": "18", "output": "1881" }, { "input": "19", "output": "1991" }, { "input": "20", "output": "2002" }, { "input": "26550", "output": "2655005562" }, { "input": "16137", "output": "1613773161" }, { "input": "91471", "output": "9147117419" }, { "input": "41242", "output": "4124224214" }, { "input": "30866", "output": "3086666803" }, { "input": "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116", "output": "44422312327410030099641831997138515664660798829290072534438483719780486106821804312956719051059801166110895015091765921340812860168408791738483443527009292889706646651583179913814699003001472321322444" }, { "input": "7806526084732010742850470902979267046151204705563201965818390803445852115032119297648697933316807252", "output": "78065260847320107428504709029792670461512047055632019658183908034458521150321192976486979333168072522527086133397968467929112305112585443080938185691023655074021516407629792090740582470102374806256087" }, { "input": "2244399823612183124978103773977739948197709395321563148611877999503840818596183803323258317041875913", "output": "22443998236121831249781037739777399481977093953215631486118779995038408185961838033232583170418759133195781407138523233083816958180483059997781168413651235939077918499377793773018794213812163289934422" }, { "input": "123451", "output": "123451154321" } ]
1,592,125,090
2,147,483,647
Python 3
OK
TESTS
40
109
1,126,400
n=input() s1=list(n) s1.reverse() n1=''.join(s1) print(n+n1)
Title: Lovely Palindromes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number? Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). Output Specification: Print the *n*-th even-length palindrome number. Demo Input: ['1\n', '10\n'] Demo Output: ['11\n', '1001\n'] Note: The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
```python n=input() s1=list(n) s1.reverse() n1=''.join(s1) print(n+n1) ```
3
440
A
Forgotten Episode
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*. The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watched. All values of *a**i* are distinct.
Print the number of the episode that Polycarpus hasn't watched.
[ "10\n3 8 10 1 7 9 6 5 2\n" ]
[ "4\n" ]
none
500
[ { "input": "10\n3 8 10 1 7 9 6 5 2", "output": "4" }, { "input": "5\n4 3 2 1", "output": "5" }, { "input": "2\n1", "output": "2" }, { "input": "2\n2", "output": "1" }, { "input": "3\n1 2", "output": "3" }, { "input": "3\n1 3", "output": "2" }, { "input": "3\n2 3", "output": "1" }, { "input": "3\n2 1", "output": "3" }, { "input": "3\n3 1", "output": "2" }, { "input": "3\n3 2", "output": "1" }, { "input": "5\n2 3 4 5", "output": "1" }, { "input": "5\n5 4 3 2", "output": "1" }, { "input": "5\n5 2 4 3", "output": "1" }, { "input": "5\n1 2 3 4", "output": "5" }, { "input": "5\n2 1 3 4", "output": "5" }, { "input": "5\n1 5 3 4", "output": "2" }, { "input": "5\n1 4 5 2", "output": "3" }, { "input": "5\n2 1 5 3", "output": "4" }, { "input": "5\n2 3 4 5", "output": "1" } ]
1,595,916,830
2,147,483,647
Python 3
OK
TESTS
35
156
15,360,000
missed = [i + 1 for i in range(int(input()))] for i in map(int, input().split()): missed[i - 1] = 0 print(sum(missed))
Title: Forgotten Episode Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*. The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watched. All values of *a**i* are distinct. Output Specification: Print the number of the episode that Polycarpus hasn't watched. Demo Input: ['10\n3 8 10 1 7 9 6 5 2\n'] Demo Output: ['4\n'] Note: none
```python missed = [i + 1 for i in range(int(input()))] for i in map(int, input().split()): missed[i - 1] = 0 print(sum(missed)) ```
3
1,003
B
Binary String Constructing
PROGRAMMING
1,300
[ "constructive algorithms" ]
null
null
You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i &lt; n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists. For example, for the string "01010" there are four indices $i$ such that $1 \le i &lt; n$ and $s_i \ne s_{i + 1}$ ($i = 1, 2, 3, 4$). For the string "111001" there are two such indices $i$ ($i = 3, 5$). Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1.
The first line of the input contains three integers $a$, $b$ and $x$ ($1 \le a, b \le 100, 1 \le x &lt; a + b)$.
Print only one string $s$, where $s$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.
[ "2 2 1\n", "3 3 3\n", "5 3 6\n" ]
[ "1100\n", "101100\n", "01010100\n" ]
All possible answers for the first example: - 1100; - 0011. All possible answers for the second example: - 110100; - 101100; - 110010; - 100110; - 011001; - 001101; - 010011; - 001011.
0
[ { "input": "2 2 1", "output": "1100" }, { "input": "3 3 3", "output": "101100" }, { "input": "5 3 6", "output": "01010100" }, { "input": "100 1 2", "output": "01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 1 1", "output": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" }, { "input": "1 100 1", "output": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "1 100 2", "output": "10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "7 8 7", "output": "101010111110000" }, { "input": "100 100 199", "output": "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010" }, { "input": "50 47 18", "output": "0101010101010101011111111111111111111111111111111111111100000000000000000000000000000000000000000" }, { "input": "2 3 3", "output": "10110" }, { "input": "100 100 100", "output": "10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111" }, { "input": "2 2 2", "output": "1001" }, { "input": "3 4 6", "output": "1010101" }, { "input": "1 1 1", "output": "10" }, { "input": "5 6 2", "output": "10000011111" }, { "input": "5 4 2", "output": "011110000" }, { "input": "2 3 4", "output": "10101" }, { "input": "3 3 2", "output": "100011" }, { "input": "100 99 100", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000" }, { "input": "3 2 1", "output": "00011" }, { "input": "12 74 22", "output": "10101010101010101010100111111111111111111111111111111111111111111111111111111111111111" }, { "input": "6 84 12", "output": "101010101010111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "3 2 4", "output": "01010" }, { "input": "66 11 22", "output": "01010101010101010101010000000000000000000000000000000000000000000000000000000" }, { "input": "83 83 83", "output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010111111111111111111111111111111111111111111000000000000000000000000000000000000000000" }, { "input": "9 89 18", "output": "10101010101010101011111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "2 1 2", "output": "010" }, { "input": "52 12 17", "output": "0101010101010101000000000000000000000000000000000000000000001111" }, { "input": "55 56 110", "output": "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" }, { "input": "67 81 40", "output": "1010101010101010101010101010101010101010000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111" }, { "input": "15 26 24", "output": "10101010101010101010101000011111111111111" }, { "input": "7 99 14", "output": "1010101010101011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "99 41 17", "output": "01010101010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111" }, { "input": "91 87 11", "output": "0101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "73 61 122", "output": "01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101000000000000" }, { "input": "10 40 1", "output": "11111111111111111111111111111111111111110000000000" }, { "input": "10 6 10", "output": "0101010101100000" }, { "input": "78 67 117", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100000000000000000000111111111" }, { "input": "3 5 6", "output": "10101011" }, { "input": "30 34 44", "output": "1010101010101010101010101010101010101010101000000000111111111111" }, { "input": "2 15 4", "output": "10101111111111111" }, { "input": "4 9 6", "output": "1010100111111" } ]
1,645,613,849
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
a, b, x = map(int, input().split()) rem = x%2; x = (x + 1) >> 1 a -= x; b -= x s = "1"*a + "10"*x + "0"*b print(("0" + s[:-1] if a < b else s[1:] + "1") if rem == 0 else s)
Title: Binary String Constructing Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i &lt; n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists. For example, for the string "01010" there are four indices $i$ such that $1 \le i &lt; n$ and $s_i \ne s_{i + 1}$ ($i = 1, 2, 3, 4$). For the string "111001" there are two such indices $i$ ($i = 3, 5$). Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1. Input Specification: The first line of the input contains three integers $a$, $b$ and $x$ ($1 \le a, b \le 100, 1 \le x &lt; a + b)$. Output Specification: Print only one string $s$, where $s$ is any binary string satisfying conditions described above. It is guaranteed that the answer always exists. Demo Input: ['2 2 1\n', '3 3 3\n', '5 3 6\n'] Demo Output: ['1100\n', '101100\n', '01010100\n'] Note: All possible answers for the first example: - 1100; - 0011. All possible answers for the second example: - 110100; - 101100; - 110010; - 100110; - 011001; - 001101; - 010011; - 001011.
```python a, b, x = map(int, input().split()) rem = x%2; x = (x + 1) >> 1 a -= x; b -= x s = "1"*a + "10"*x + "0"*b print(("0" + s[:-1] if a < b else s[1:] + "1") if rem == 0 else s) ```
0
257
C
View Angle
PROGRAMMING
1,800
[ "brute force", "geometry", "math" ]
null
null
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle. As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins. Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane.
Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6.
[ "2\n2 0\n0 2\n", "3\n2 0\n0 2\n-2 2\n", "4\n2 0\n0 2\n-2 0\n0 -2\n", "2\n2 1\n1 2\n" ]
[ "90.0000000000\n", "135.0000000000\n", "270.0000000000\n", "36.8698976458\n" ]
Solution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below:
1,500
[ { "input": "2\n2 0\n0 2", "output": "90.0000000000" }, { "input": "3\n2 0\n0 2\n-2 2", "output": "135.0000000000" }, { "input": "4\n2 0\n0 2\n-2 0\n0 -2", "output": "270.0000000000" }, { "input": "2\n2 1\n1 2", "output": "36.8698976458" }, { "input": "1\n1 1", "output": "0.0000000000" }, { "input": "10\n9 7\n10 7\n6 5\n6 10\n7 6\n5 10\n6 7\n10 9\n5 5\n5 8", "output": "28.4429286244" }, { "input": "10\n-1 28\n1 28\n1 25\n0 23\n-1 24\n-1 22\n1 27\n0 30\n1 22\n1 21", "output": "5.3288731964" }, { "input": "10\n-5 9\n-10 6\n-8 8\n-9 9\n-6 5\n-8 9\n-5 7\n-6 6\n-5 10\n-8 7", "output": "32.4711922908" }, { "input": "10\n6 -9\n9 -5\n10 -5\n7 -5\n8 -7\n8 -10\n8 -5\n6 -10\n7 -6\n8 -9", "output": "32.4711922908" }, { "input": "10\n-5 -7\n-8 -10\n-9 -5\n-5 -9\n-9 -8\n-7 -7\n-6 -8\n-6 -10\n-10 -7\n-9 -6", "output": "31.8907918018" }, { "input": "10\n-1 -29\n-1 -26\n1 -26\n-1 -22\n-1 -24\n-1 -21\n1 -24\n-1 -20\n-1 -23\n-1 -25", "output": "5.2483492565" }, { "input": "10\n21 0\n22 1\n30 0\n20 0\n28 0\n29 0\n21 -1\n30 1\n24 1\n26 0", "output": "5.3288731964" }, { "input": "10\n-20 0\n-22 1\n-26 0\n-22 -1\n-30 -1\n-30 0\n-28 0\n-24 1\n-23 -1\n-29 1", "output": "5.2051244050" }, { "input": "10\n-5 -5\n5 -5\n-4 -5\n4 -5\n1 -5\n0 -5\n3 -5\n-2 -5\n2 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n-5 -5\n-4 -5\n-2 -5\n4 -5\n5 -5\n3 -5\n2 -5\n-1 -5\n-3 -5\n0 -5", "output": "90.0000000000" }, { "input": "10\n-1 -5\n-5 -5\n2 -5\n-2 -5\n1 -5\n5 -5\n0 -5\n3 -5\n-4 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n-1 -5\n-5 -5\n-4 -5\n3 -5\n0 -5\n4 -5\n1 -5\n-2 -5\n5 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n5 -5\n4 -5\n-1 -5\n1 -5\n-4 -5\n3 -5\n0 -5\n-5 -5\n-2 -5\n-3 -5", "output": "90.0000000000" }, { "input": "10\n2 -5\n-4 -5\n-2 -5\n4 -5\n-5 -5\n-1 -5\n0 -5\n-3 -5\n3 -5\n1 -5", "output": "83.6598082541" }, { "input": "5\n2 1\n0 1\n2 -1\n-2 -1\n2 0", "output": "233.1301023542" }, { "input": "5\n-2 -2\n2 2\n2 -1\n-2 0\n1 -1", "output": "225.0000000000" }, { "input": "5\n0 -2\n-2 -1\n-1 2\n0 -1\n-1 0", "output": "153.4349488229" }, { "input": "5\n-1 -1\n-2 -1\n1 0\n-1 -2\n-1 1", "output": "225.0000000000" }, { "input": "5\n1 -1\n0 2\n-2 2\n-2 1\n2 1", "output": "198.4349488229" }, { "input": "5\n2 2\n1 2\n-2 -1\n1 1\n-2 -2", "output": "180.0000000000" }, { "input": "2\n1 1\n2 2", "output": "0.0000000000" }, { "input": "27\n-592 -96\n-925 -150\n-111 -18\n-259 -42\n-370 -60\n-740 -120\n-629 -102\n-333 -54\n-407 -66\n-296 -48\n-37 -6\n-999 -162\n-222 -36\n-555 -90\n-814 -132\n-444 -72\n-74 -12\n-185 -30\n-148 -24\n-962 -156\n-777 -126\n-518 -84\n-888 -144\n-666 -108\n-481 -78\n-851 -138\n-703 -114", "output": "0.0000000000" }, { "input": "38\n96 416\n24 104\n6 26\n12 52\n210 910\n150 650\n54 234\n174 754\n114 494\n18 78\n90 390\n36 156\n222 962\n186 806\n126 546\n78 338\n108 468\n180 780\n120 520\n84 364\n66 286\n138 598\n30 130\n228 988\n72 312\n144 624\n198 858\n60 260\n48 208\n102 442\n42 182\n162 702\n132 572\n156 676\n204 884\n216 936\n168 728\n192 832", "output": "0.0000000000" }, { "input": "14\n-2 -134\n-4 -268\n-11 -737\n-7 -469\n-14 -938\n-10 -670\n-3 -201\n-1 -67\n-9 -603\n-6 -402\n-13 -871\n-12 -804\n-8 -536\n-5 -335", "output": "0.0000000000" }, { "input": "14\n588 938\n420 670\n210 335\n252 402\n504 804\n126 201\n42 67\n546 871\n294 469\n84 134\n336 536\n462 737\n168 268\n378 603", "output": "0.0000000000" }, { "input": "20\n-45 147\n-240 784\n-135 441\n-60 196\n-105 343\n-285 931\n-195 637\n-300 980\n-165 539\n-210 686\n-75 245\n-15 49\n-30 98\n-270 882\n-120 392\n-90 294\n-150 490\n-180 588\n-255 833\n-225 735", "output": "0.0000000000" }, { "input": "2\n1 1\n1 -1", "output": "90.0000000000" } ]
1,621,263,643
1,783
Python 3
OK
TESTS
56
1,028
10,649,600
import math def angle(x, y): a = (x**2+y**2)**0.5 x1, y1 = x/a, y/a my_angle = math.asin(y1) my_angle = 180*my_angle/math.pi if x < 0: my_angle = 180-my_angle if my_angle < 0: my_angle = 360+my_angle return my_angle def process(M): angles = [] for x, y in M: angles.append(angle(x, y)) answer = max(angles)-min(angles) angles = sorted(angles) for i in range(len(angles)-1): a1 = angles[i] a2 = angles[i+1] answer = min(answer, 360-(a2-a1)) return answer n = int(input()) M = [] for i in range(n): x, y = [int(c) for c in input().split()] M.append([x, y]) print(process(M))
Title: View Angle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle. As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins. Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane. Output Specification: Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6. Demo Input: ['2\n2 0\n0 2\n', '3\n2 0\n0 2\n-2 2\n', '4\n2 0\n0 2\n-2 0\n0 -2\n', '2\n2 1\n1 2\n'] Demo Output: ['90.0000000000\n', '135.0000000000\n', '270.0000000000\n', '36.8698976458\n'] Note: Solution for the first sample test is shown below: Solution for the second sample test is shown below: Solution for the third sample test is shown below: Solution for the fourth sample test is shown below:
```python import math def angle(x, y): a = (x**2+y**2)**0.5 x1, y1 = x/a, y/a my_angle = math.asin(y1) my_angle = 180*my_angle/math.pi if x < 0: my_angle = 180-my_angle if my_angle < 0: my_angle = 360+my_angle return my_angle def process(M): angles = [] for x, y in M: angles.append(angle(x, y)) answer = max(angles)-min(angles) angles = sorted(angles) for i in range(len(angles)-1): a1 = angles[i] a2 = angles[i+1] answer = min(answer, 360-(a2-a1)) return answer n = int(input()) M = [] for i in range(n): x, y = [int(c) for c in input().split()] M.append([x, y]) print(process(M)) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,695,645,761
2,147,483,647
PyPy 3-64
OK
TESTS
35
124
0
length, breadth = [int(x) for x in input().split()] area = length * breadth max_dominoes = area // 2 print(max_dominoes)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python length, breadth = [int(x) for x in input().split()] area = length * breadth max_dominoes = area // 2 print(max_dominoes) ```
3.969
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,598,439,598
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
12
186
0
c=0 d=0 n=int(input()) m=list(map(int,input().split())) i=0 while c<n: c+=m[i] i+=1 d+=1 if d==7: i=0 d=0 print(d)
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 c=0 d=0 n=int(input()) m=list(map(int,input().split())) i=0 while c<n: c+=m[i] i+=1 d+=1 if d==7: i=0 d=0 print(d) ```
0
327
A
Flipping Game
PROGRAMMING
1,200
[ "brute force", "dp", "implementation" ]
null
null
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*. The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
[ "5\n1 0 0 1 0\n", "4\n1 0 0 1\n" ]
[ "4\n", "4\n" ]
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1.
500
[ { "input": "5\n1 0 0 1 0", "output": "4" }, { "input": "4\n1 0 0 1", "output": "4" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "8\n1 0 0 0 1 0 0 0", "output": "7" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "18" }, { "input": "23\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "22" }, { "input": "100\n0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1", "output": "70" }, { "input": "100\n0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1", "output": "60" }, { "input": "18\n0 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0", "output": "11" }, { "input": "25\n0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1", "output": "18" }, { "input": "55\n0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1", "output": "36" }, { "input": "75\n1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0", "output": "44" }, { "input": "100\n0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 1", "output": "61" }, { "input": "100\n0 0 0 1 0 0 0 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0", "output": "61" }, { "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\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": "99" }, { "input": "100\n0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 0 0 1 0", "output": "61" }, { "input": "100\n0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1", "output": "59" }, { "input": "99\n1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1", "output": "61" }, { "input": "2\n1 1", "output": "1" } ]
1,695,272,594
2,147,483,647
PyPy 3-64
OK
TESTS
21
124
0
n = int(input()) l = [int(x) for x in input().split()] s=c=0 m = -100000000 for i in l: if i==0: s+=1 else: c+=1 s-=1 if s>m: m=s if s<0: s=0 print(m+c)
Title: Flipping Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*. The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. Output Specification: Print an integer — the maximal number of 1s that can be obtained after exactly one move. Demo Input: ['5\n1 0 0 1 0\n', '4\n1 0 0 1\n'] Demo Output: ['4\n', '4\n'] Note: In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1.
```python n = int(input()) l = [int(x) for x in input().split()] s=c=0 m = -100000000 for i in l: if i==0: s+=1 else: c+=1 s-=1 if s>m: m=s if s<0: s=0 print(m+c) ```
3
689
B
Mike and Shortcuts
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "greedy", "shortest paths" ]
null
null
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number *i* to intersection *j* requires |*i*<=-<=*j*| units of energy. The total energy spent by Mike to visit a sequence of intersections *p*1<==<=1,<=*p*2,<=...,<=*p**k* is equal to units of energy. Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly *n* shortcuts in Mike's city, the *i**th* of them allows walking from intersection *i* to intersection *a**i* (*i*<=≤<=*a**i*<=≤<=*a**i*<=+<=1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k* then for each 1<=≤<=*i*<=&lt;<=*k* satisfying *p**i*<=+<=1<==<=*a**p**i* and *a**p**i*<=≠<=*p**i* Mike will spend only 1 unit of energy instead of |*p**i*<=-<=*p**i*<=+<=1| walking from the intersection *p**i* to intersection *p**i*<=+<=1. For example, if Mike chooses a sequence *p*1<==<=1,<=*p*2<==<=*a**p*1,<=*p*3<==<=*a**p*2,<=...,<=*p**k*<==<=*a**p**k*<=-<=1, he spends exactly *k*<=-<=1 units of total energy walking around them. Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1<=≤<=*i*<=≤<=*n* Mike is interested in finding minimum possible total energy of some sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k*<==<=*i*.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from *a**i* to *i*).
In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*.
[ "3\n2 2 3\n", "5\n1 2 3 4 5\n", "7\n4 4 4 4 7 7 7\n" ]
[ "0 1 2 \n", "0 1 2 3 4 \n", "0 1 2 1 2 3 3 \n" ]
In the first sample case desired sequences are: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = 1; 3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 &lt; *i* is always 1, *i* and *m*<sub class="lower-index">*i*</sub> = |1 - *i*|. In the third sample case — consider the following intersection sequences: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = |2 - 1| = 1; 3: 1, 4, 3; *m*<sub class="lower-index">3</sub> = 1 + |4 - 3| = 2; 4: 1, 4; *m*<sub class="lower-index">4</sub> = 1; 5: 1, 4, 5; *m*<sub class="lower-index">5</sub> = 1 + |4 - 5| = 2; 6: 1, 4, 6; *m*<sub class="lower-index">6</sub> = 1 + |4 - 6| = 3; 7: 1, 4, 5, 7; *m*<sub class="lower-index">7</sub> = 1 + |4 - 5| + 1 = 3.
1,000
[ { "input": "3\n2 2 3", "output": "0 1 2 " }, { "input": "5\n1 2 3 4 5", "output": "0 1 2 3 4 " }, { "input": "7\n4 4 4 4 7 7 7", "output": "0 1 2 1 2 3 3 " }, { "input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 90 90 90 90 90 90 90 90 90 90 90 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 95 95 95 95 95 97 98 98", "output": "0 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 4 4 5 6 5 6 7 8 " }, { "input": "91\n4 6 23 23 23 23 23 28 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 47 47 47 54 54 54 54 54 54 54 58 58 58 58 58 58 69 69 69 69 69 69 69 69 69 69 69 69 70 70 70 70 70 70 70 70 70 70 71 72 72 72 73 75 77 77 77 82 82 84 84 84 84 84 85 86 87 89 89 90 91", "output": "0 1 2 1 2 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 3 4 5 6 5 6 7 8 9 9 8 7 6 5 4 3 4 5 6 7 8 9 10 9 10 9 8 7 6 5 4 5 6 7 6 7 8 9 10 11 10 9 8 7 6 5 6 6 7 8 9 10 11 11 12 13 14 14 13 14 14 15 16 17 18 19 20 21 " }, { "input": "82\n1 5 11 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 39 39 39 39 39 45 45 45 45 45 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 71 71 71 71 71 71 71 73 73 75 75 76 77 79 81 81 81 82", "output": "0 1 2 3 2 3 4 5 5 4 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 4 5 6 7 8 9 10 9 9 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 16 15 14 13 12 11 10 9 8 7 6 5 6 6 7 8 9 10 11 12 13 14 15 15 16 " }, { "input": "4\n2 3 3 4", "output": "0 1 2 3 " } ]
1,668,611,069
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
print( input() ) # def take_input(): # tuple_input = take_input() # process_intersections( tuple_input )
Title: Mike and Shortcuts Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number *i* to intersection *j* requires |*i*<=-<=*j*| units of energy. The total energy spent by Mike to visit a sequence of intersections *p*1<==<=1,<=*p*2,<=...,<=*p**k* is equal to units of energy. Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly *n* shortcuts in Mike's city, the *i**th* of them allows walking from intersection *i* to intersection *a**i* (*i*<=≤<=*a**i*<=≤<=*a**i*<=+<=1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k* then for each 1<=≤<=*i*<=&lt;<=*k* satisfying *p**i*<=+<=1<==<=*a**p**i* and *a**p**i*<=≠<=*p**i* Mike will spend only 1 unit of energy instead of |*p**i*<=-<=*p**i*<=+<=1| walking from the intersection *p**i* to intersection *p**i*<=+<=1. For example, if Mike chooses a sequence *p*1<==<=1,<=*p*2<==<=*a**p*1,<=*p*3<==<=*a**p*2,<=...,<=*p**k*<==<=*a**p**k*<=-<=1, he spends exactly *k*<=-<=1 units of total energy walking around them. Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1<=≤<=*i*<=≤<=*n* Mike is interested in finding minimum possible total energy of some sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k*<==<=*i*. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from *a**i* to *i*). Output Specification: In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*. Demo Input: ['3\n2 2 3\n', '5\n1 2 3 4 5\n', '7\n4 4 4 4 7 7 7\n'] Demo Output: ['0 1 2 \n', '0 1 2 3 4 \n', '0 1 2 1 2 3 3 \n'] Note: In the first sample case desired sequences are: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = 1; 3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 &lt; *i* is always 1, *i* and *m*<sub class="lower-index">*i*</sub> = |1 - *i*|. In the third sample case — consider the following intersection sequences: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = |2 - 1| = 1; 3: 1, 4, 3; *m*<sub class="lower-index">3</sub> = 1 + |4 - 3| = 2; 4: 1, 4; *m*<sub class="lower-index">4</sub> = 1; 5: 1, 4, 5; *m*<sub class="lower-index">5</sub> = 1 + |4 - 5| = 2; 6: 1, 4, 6; *m*<sub class="lower-index">6</sub> = 1 + |4 - 6| = 3; 7: 1, 4, 5, 7; *m*<sub class="lower-index">7</sub> = 1 + |4 - 5| + 1 = 3.
```python print( input() ) # def take_input(): # tuple_input = take_input() # process_intersections( tuple_input ) ```
0
129
A
Cookies
PROGRAMMING
900
[ "implementation" ]
null
null
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
[ "1\n1\n", "10\n1 2 2 3 4 4 4 2 2 2\n", "11\n2 2 2 2 2 2 2 2 2 2 99\n" ]
[ "1\n", "8\n", "1\n" ]
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.
500
[ { "input": "1\n1", "output": "1" }, { "input": "10\n1 2 2 3 4 4 4 2 2 2", "output": "8" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 99", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 2", "output": "2" }, { "input": "2\n1 2", "output": "1" }, { "input": "7\n7 7 7 7 7 7 7", "output": "7" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "4" }, { "input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2", "output": "50" }, { "input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99", "output": "49" }, { "input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15", "output": "50" }, { "input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38", "output": "7" }, { "input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87", "output": "39" }, { "input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53", "output": "37" }, { "input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32", "output": "51" }, { "input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80", "output": "21" }, { "input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81", "output": "37" }, { "input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59", "output": "28" }, { "input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94", "output": "47" }, { "input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28", "output": "15" }, { "input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42", "output": "11" }, { "input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35", "output": "33" }, { "input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22", "output": "37" }, { "input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14", "output": "15" }, { "input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77", "output": "35" }, { "input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75", "output": "42" }, { "input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26", "output": "23" }, { "input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78", "output": "15" }, { "input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78", "output": "13" }, { "input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51", "output": "17" }, { "input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59", "output": "45" }, { "input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43", "output": "53" }, { "input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8", "output": "40" }, { "input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54", "output": "53" }, { "input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77", "output": "55" }, { "input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66", "output": "52" }, { "input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89", "output": "51" }, { "input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2", "output": "53" }, { "input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23", "output": "48" }, { "input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25", "output": "48" }, { "input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71", "output": "58" }, { "input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45", "output": "53" }, { "input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17", "output": "54" }, { "input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52", "output": "49" }, { "input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31", "output": "44" }, { "input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74", "output": "46" }, { "input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75", "output": "53" }, { "input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37", "output": "43" }, { "input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82", "output": "51" }, { "input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5", "output": "47" }, { "input": "1\n2", "output": "1" }, { "input": "5\n1 1 3 2 2", "output": "3" } ]
1,588,924,930
2,147,483,647
Python 3
OK
TESTS
52
248
6,656,000
integer = int string = str length = len def main(): n=int(input()) l=list(map(integer,input().split())) add=0 odd=0 even=0 for i in l: add+=i if i%2: odd+=1 else: even+=1 if add%2: print(odd) else: print(even) main()
Title: Cookies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? Input Specification: The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. Output Specification: Print in the only line the only number — the sought number of ways. If there are no such ways print 0. Demo Input: ['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n'] Demo Output: ['1\n', '8\n', '1\n'] Note: In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.
```python integer = int string = str length = len def main(): n=int(input()) l=list(map(integer,input().split())) add=0 odd=0 even=0 for i in l: add+=i if i%2: odd+=1 else: even+=1 if add%2: print(odd) else: print(even) main() ```
3
276
A
Lunch Rush
PROGRAMMING
900
[ "implementation" ]
null
null
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.
The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant.
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
[ "2 5\n3 3\n4 5\n", "4 6\n5 8\n3 6\n2 3\n2 2\n", "1 5\n1 7\n" ]
[ "4\n", "3\n", "-1\n" ]
none
500
[ { "input": "2 5\n3 3\n4 5", "output": "4" }, { "input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3" }, { "input": "1 5\n1 7", "output": "-1" }, { "input": "4 9\n10 13\n4 18\n13 3\n10 6", "output": "13" }, { "input": "1 1\n1 1000000000", "output": "-999999998" }, { "input": "1 1\n1000000000 1000000000", "output": "1" }, { "input": "1 1\n1000000000 1", "output": "1000000000" }, { "input": "2 3\n1000000000 1\n2 2", "output": "1000000000" }, { "input": "2 5\n1 7\n1 1000000000", "output": "-1" } ]
1,643,950,525
2,147,483,647
Python 3
OK
TESTS
35
122
409,600
n,k = map(int, input().split()) l = [] m = [] o = [] s = 0 for i in range(n): f,t = map(int, input().split()) l.append(f) m.append(t) if m[i]>k: s = l[i]-(m[i]-k) o.append(s) i = i + 1 else: s = l[i] o.append(s) i = i + 1 print(max(o))
Title: Lunch Rush Time Limit: None seconds Memory Limit: None megabytes Problem Description: Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value. Input Specification: The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant. Output Specification: In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. Demo Input: ['2 5\n3 3\n4 5\n', '4 6\n5 8\n3 6\n2 3\n2 2\n', '1 5\n1 7\n'] Demo Output: ['4\n', '3\n', '-1\n'] Note: none
```python n,k = map(int, input().split()) l = [] m = [] o = [] s = 0 for i in range(n): f,t = map(int, input().split()) l.append(f) m.append(t) if m[i]>k: s = l[i]-(m[i]-k) o.append(s) i = i + 1 else: s = l[i] o.append(s) i = i + 1 print(max(o)) ```
3
876
B
Divisiblity of Differences
PROGRAMMING
1,300
[ "implementation", "math", "number theory" ]
null
null
You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset.
If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them.
[ "3 2 3\n1 8 4\n", "3 3 3\n1 8 4\n", "4 3 5\n2 7 7 7\n" ]
[ "Yes\n1 4 ", "No", "Yes\n2 7 7 " ]
none
1,000
[ { "input": "3 2 3\n1 8 4", "output": "Yes\n1 4 " }, { "input": "3 3 3\n1 8 4", "output": "No" }, { "input": "4 3 5\n2 7 7 7", "output": "Yes\n2 7 7 " }, { "input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825", "output": "Yes\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825 " }, { "input": "15 8 10\n216175135 15241965 611723934 987180005 151601897 403701727 533996295 207637446 875331635 46172555 604086315 350146655 401084142 156540458 982110455", "output": "Yes\n216175135 15241965 987180005 533996295 875331635 46172555 604086315 350146655 " }, { "input": "2 2 100000\n0 1", "output": "No" }, { "input": "101 25 64\n451 230 14 53 7 520 709 102 678 358 166 870 807 230 230 279 166 230 765 176 742 358 924 976 647 806 870 473 976 994 750 146 802 224 503 801 105 614 882 203 390 338 29 587 214 213 405 806 102 102 621 358 521 742 678 205 309 871 796 326 162 693 268 486 68 627 304 829 806 623 748 934 714 672 712 614 587 589 846 260 593 85 839 257 711 395 336 358 472 133 324 527 599 5 845 920 989 494 358 70 882", "output": "Yes\n230 102 678 358 166 870 230 230 166 230 742 358 806 870 614 806 102 102 358 742 678 486 806 934 614 " }, { "input": "108 29 72\n738 619 711 235 288 288 679 36 785 233 706 71 216 144 216 781 338 583 495 648 144 432 72 720 541 288 158 328 154 202 10 533 635 176 707 216 314 397 440 142 326 458 568 701 745 144 61 634 520 720 744 144 409 127 526 476 101 469 72 432 738 432 235 641 695 276 144 144 231 555 630 9 109 319 437 288 288 317 453 432 601 0 449 576 743 352 333 504 504 369 228 288 381 142 500 72 297 359 230 773 216 576 144 244 437 772 483 51", "output": "Yes\n288 288 216 144 216 648 144 432 72 720 288 216 144 720 144 72 432 432 144 144 288 288 432 0 576 504 504 288 72 " }, { "input": "8 2 6\n750462183 165947982 770714338 368445737 363145692 966611485 376672869 678687947", "output": "Yes\n165947982 363145692 " }, { "input": "12 2 1\n512497388 499105388 575265677 864726520 678272195 667107176 809432109 439696443 770034376 873126825 690514828 541499950", "output": "Yes\n512497388 499105388 " }, { "input": "9 3 1\n506004039 471451660 614118177 518013571 43210072 454727076 285905913 543002174 298515615", "output": "Yes\n506004039 471451660 614118177 " }, { "input": "8 4 6\n344417267 377591123 938158786 682031413 804153975 89006697 275945670 735510539", "output": "No" }, { "input": "8 8 1\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253", "output": "Yes\n314088413 315795280 271532387 241073087 961218399 884234132 419866508 286799253 " }, { "input": "7 7 1\n0 0 0 0 0 0 0", "output": "Yes\n0 0 0 0 0 0 0 " }, { "input": "11 4 3\n0 1 0 1 1 0 0 0 0 0 0", "output": "Yes\n0 0 0 0 " }, { "input": "13 4 4\n1 1 0 3 2 4 1 0 3 4 2 4 3", "output": "Yes\n0 4 0 4 " }, { "input": "5 5 1\n6 4 6 0 4", "output": "Yes\n6 4 6 0 4 " }, { "input": "3 2 3\n1 2 3", "output": "No" }, { "input": "6 3 4\n5 9 10 6 7 8", "output": "No" }, { "input": "4 4 3\n4 7 2 5", "output": "No" }, { "input": "4 2 6\n5 5 5 5", "output": "Yes\n5 5 " }, { "input": "4 3 3\n5 1 4 7", "output": "Yes\n1 4 7 " }, { "input": "4 3 10\n0 1 11 11", "output": "Yes\n1 11 11 " }, { "input": "5 2 4\n1 2 2 2 2", "output": "Yes\n2 2 " }, { "input": "5 5 9\n8 17 26 35 44", "output": "Yes\n8 17 26 35 44 " }, { "input": "3 2 2\n1 2 4", "output": "Yes\n2 4 " }, { "input": "5 4 2\n1 3 6 10 12", "output": "No" }, { "input": "3 2 4\n1 2 3", "output": "No" }, { "input": "8 3 5\n1 2 3 4 1 2 3 4", "output": "No" }, { "input": "5 2 9\n8 8 8 8 8", "output": "Yes\n8 8 " }, { "input": "3 3 3\n1 3 6", "output": "No" }, { "input": "5 2 10\n4 5 6 19 29", "output": "Yes\n19 29 " }, { "input": "5 3 3\n3 6 4 7 10", "output": "Yes\n4 7 10 " } ]
1,508,152,603
703
Python 3
OK
TESTS
63
218
13,926,400
n,k,m = map(int, input().split()) a = list(map(int, input().split())) d = {} for i in range(n): r = a[i]%m if r not in d: d[r] = 0 d[r]+=1 ans_r=None for key in d: if d[key] >= k: ans_r=key break if ans_r is None: print('No') else: ans = [] for i in range(n): if a[i]%m == ans_r: ans.append(str(a[i])) if len(ans) == k: break print('Yes') print(' '.join(ans))
Title: Divisiblity of Differences Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. Input Specification: First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset. Output Specification: If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them. Demo Input: ['3 2 3\n1 8 4\n', '3 3 3\n1 8 4\n', '4 3 5\n2 7 7 7\n'] Demo Output: ['Yes\n1 4 ', 'No', 'Yes\n2 7 7 '] Note: none
```python n,k,m = map(int, input().split()) a = list(map(int, input().split())) d = {} for i in range(n): r = a[i]%m if r not in d: d[r] = 0 d[r]+=1 ans_r=None for key in d: if d[key] >= k: ans_r=key break if ans_r is None: print('No') else: ans = [] for i in range(n): if a[i]%m == ans_r: ans.append(str(a[i])) if len(ans) == k: break print('Yes') print(' '.join(ans)) ```
3
474
D
Flowers
PROGRAMMING
1,700
[ "dp" ]
null
null
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size *k*. Now Marmot wonders in how many ways he can eat between *a* and *b* flowers. As the number of ways could be very large, print it modulo 1000000007 (109<=+<=7).
Input contains several test cases. The first line contains two integers *t* and *k* (1<=≤<=*t*,<=*k*<=≤<=105), where *t* represents the number of test cases. The next *t* lines contain two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=105), describing the *i*-th test.
Print *t* lines to the standard output. The *i*-th line should contain the number of ways in which Marmot can eat between *a**i* and *b**i* flowers at dinner modulo 1000000007 (109<=+<=7).
[ "3 2\n1 3\n2 3\n4 4\n" ]
[ "6\n5\n5\n" ]
- For *K* = 2 and length 1 Marmot can eat (*R*). - For *K* = 2 and length 2 Marmot can eat (*RR*) and (*WW*). - For *K* = 2 and length 3 Marmot can eat (*RRR*), (*RWW*) and (*WWR*). - For *K* = 2 and length 4 Marmot can eat, for example, (*WWWW*) or (*RWWR*), but for example he can't eat (*WWWR*).
2,000
[ { "input": "3 2\n1 3\n2 3\n4 4", "output": "6\n5\n5" }, { "input": "1 1\n1 3", "output": "14" }, { "input": "1 2\n64329 79425", "output": "0" } ]
1,695,317,665
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> #define ll long long const int N=1e5+5; const ll mod=1e9+7; using namespace std; int n,T; ll dp[N][2],p[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>T>>n; dp[0][0]=1; for(int i=1;i<=100000;++i) { dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod; if(i>=n) dp[i][1]=(dp[i-n][0]+dp[i-n][1])%mod; } for(int i=1;i<=100000;++i) { p[i]=((p[i-1]+dp[i][0])%mod+dp[i][1])%mod; } while(T--) { int a,b; cin>>a>>b; ll ans=(p[b]-p[a-1]+mod)%mod; printf("%lld\n",ans); } }
Title: Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size *k*. Now Marmot wonders in how many ways he can eat between *a* and *b* flowers. As the number of ways could be very large, print it modulo 1000000007 (109<=+<=7). Input Specification: Input contains several test cases. The first line contains two integers *t* and *k* (1<=≤<=*t*,<=*k*<=≤<=105), where *t* represents the number of test cases. The next *t* lines contain two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=105), describing the *i*-th test. Output Specification: Print *t* lines to the standard output. The *i*-th line should contain the number of ways in which Marmot can eat between *a**i* and *b**i* flowers at dinner modulo 1000000007 (109<=+<=7). Demo Input: ['3 2\n1 3\n2 3\n4 4\n'] Demo Output: ['6\n5\n5\n'] Note: - For *K* = 2 and length 1 Marmot can eat (*R*). - For *K* = 2 and length 2 Marmot can eat (*RR*) and (*WW*). - For *K* = 2 and length 3 Marmot can eat (*RRR*), (*RWW*) and (*WWR*). - For *K* = 2 and length 4 Marmot can eat, for example, (*WWWW*) or (*RWWR*), but for example he can't eat (*WWWR*).
```python #include<bits/stdc++.h> #define ll long long const int N=1e5+5; const ll mod=1e9+7; using namespace std; int n,T; ll dp[N][2],p[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>T>>n; dp[0][0]=1; for(int i=1;i<=100000;++i) { dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod; if(i>=n) dp[i][1]=(dp[i-n][0]+dp[i-n][1])%mod; } for(int i=1;i<=100000;++i) { p[i]=((p[i-1]+dp[i][0])%mod+dp[i][1])%mod; } while(T--) { int a,b; cin>>a>>b; ll ans=(p[b]-p[a-1]+mod)%mod; printf("%lld\n",ans); } } ```
-1
796
D
Police Stations
PROGRAMMING
2,100
[ "constructive algorithms", "dfs and similar", "dp", "graphs", "shortest paths", "trees" ]
null
null
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be possible to reach a police station by traveling at most *d* kilometers along the roads. There are *n* cities in the country, numbered from 1 to *n*, connected only by exactly *n*<=-<=1 roads. All roads are 1 kilometer long. It is initially possible to travel from a city to any other city using these roads. The country also has *k* police stations located in some cities. In particular, the city's structure satisfies the requirement enforced by the previously mentioned law. Also note that there can be multiple police stations in one city. However, Zane feels like having as many as *n*<=-<=1 roads is unnecessary. The country is having financial issues, so it wants to minimize the road maintenance cost by shutting down as many roads as possible. Help Zane find the maximum number of roads that can be shut down without breaking the law. Also, help him determine such roads.
The first line contains three integers *n*, *k*, and *d* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=3·105, 0<=≤<=*d*<=≤<=*n*<=-<=1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively. The second line contains *k* integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≤<=*p**i*<=≤<=*n*) — each denoting the city each police station is located in. The *i*-th of the following *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities directly connected by the road with index *i*. It is guaranteed that it is possible to travel from one city to any other city using only the roads. Also, it is possible from any city to reach a police station within *d* kilometers.
In the first line, print one integer *s* that denotes the maximum number of roads that can be shut down. In the second line, print *s* distinct integers, the indices of such roads, in any order. If there are multiple answers, print any of them.
[ "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n" ]
[ "1\n5\n", "2\n4 5 " ]
In the first sample, if you shut down road 5, all cities can still reach a police station within *k* = 4 kilometers. In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line.
1,500
[ { "input": "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6", "output": "1\n3 " }, { "input": "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6", "output": "2\n4 5 " }, { "input": "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10", "output": "0" }, { "input": "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11", "output": "0" }, { "input": "2 1 1\n1\n1 2", "output": "0" } ]
1,650,004,240
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
70,041,600
from collections import deque from itertools import repeat inf = 10000000 def bfs(graph, v, q): visited = [0]*(v+1) res = [0]*v cnt=0 while(len(q)!=0): if visited[q[0][0]] == 1 : q.popleft() continue cur = q[0][0] prev = q[0][1] visited[cur] = 1 q.popleft() for i in graph[cur]: if i[0] != prev: if visited[i[0]] == 1: res[i[1]] = 1 cnt+=1 else: q.append([i[0],cur]) return cnt,res def main(): v, p, lim= map(int, input().split()) police = deque([]) inp = list(map(int, input().split())) ind = 0 for i in range(p): police.append([inp[i], 0]) graph = [[]*(v+1) for i in repeat(None, v+1)] for i in range(v-1): in1, in2= map(int,input().split()) graph[in1].append([in2, i+1]) graph[in2].append([in1, i+1]) cnt,res = bfs(graph, v, police) print(cnt) for i in range(len(res)): if res[i]== 1: print(i, end=" ") main()
Title: Police Stations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be possible to reach a police station by traveling at most *d* kilometers along the roads. There are *n* cities in the country, numbered from 1 to *n*, connected only by exactly *n*<=-<=1 roads. All roads are 1 kilometer long. It is initially possible to travel from a city to any other city using these roads. The country also has *k* police stations located in some cities. In particular, the city's structure satisfies the requirement enforced by the previously mentioned law. Also note that there can be multiple police stations in one city. However, Zane feels like having as many as *n*<=-<=1 roads is unnecessary. The country is having financial issues, so it wants to minimize the road maintenance cost by shutting down as many roads as possible. Help Zane find the maximum number of roads that can be shut down without breaking the law. Also, help him determine such roads. Input Specification: The first line contains three integers *n*, *k*, and *d* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=3·105, 0<=≤<=*d*<=≤<=*n*<=-<=1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively. The second line contains *k* integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≤<=*p**i*<=≤<=*n*) — each denoting the city each police station is located in. The *i*-th of the following *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities directly connected by the road with index *i*. It is guaranteed that it is possible to travel from one city to any other city using only the roads. Also, it is possible from any city to reach a police station within *d* kilometers. Output Specification: In the first line, print one integer *s* that denotes the maximum number of roads that can be shut down. In the second line, print *s* distinct integers, the indices of such roads, in any order. If there are multiple answers, print any of them. Demo Input: ['6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n', '6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n'] Demo Output: ['1\n5\n', '2\n4 5 '] Note: In the first sample, if you shut down road 5, all cities can still reach a police station within *k* = 4 kilometers. In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line.
```python from collections import deque from itertools import repeat inf = 10000000 def bfs(graph, v, q): visited = [0]*(v+1) res = [0]*v cnt=0 while(len(q)!=0): if visited[q[0][0]] == 1 : q.popleft() continue cur = q[0][0] prev = q[0][1] visited[cur] = 1 q.popleft() for i in graph[cur]: if i[0] != prev: if visited[i[0]] == 1: res[i[1]] = 1 cnt+=1 else: q.append([i[0],cur]) return cnt,res def main(): v, p, lim= map(int, input().split()) police = deque([]) inp = list(map(int, input().split())) ind = 0 for i in range(p): police.append([inp[i], 0]) graph = [[]*(v+1) for i in repeat(None, v+1)] for i in range(v-1): in1, in2= map(int,input().split()) graph[in1].append([in2, i+1]) graph[in2].append([in1, i+1]) cnt,res = bfs(graph, v, police) print(cnt) for i in range(len(res)): if res[i]== 1: print(i, end=" ") main() ```
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,662,892,203
2,147,483,647
Python 3
OK
TESTS
50
46
0
l = [int(l) for l in input().split()] n = l[0]; m = l[1] p = '' for i in range(n): x = [str(x) for x in input().split()] for j in x: if j == 'C' or j == 'M' or j == 'Y': p = "#Color" print(p) break if p != '': break if p == '': 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 l = [int(l) for l in input().split()] n = l[0]; m = l[1] p = '' for i in range(n): x = [str(x) for x in input().split()] for j in x: if j == 'C' or j == 'M' or j == 'Y': p = "#Color" print(p) break if p != '': break if p == '': print("#Black&White") ```
3
597
A
Divisibility
PROGRAMMING
1,600
[ "math" ]
null
null
Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018).
Print the required number.
[ "1 1 10\n", "2 -4 4\n" ]
[ "10\n", "5\n" ]
none
500
[ { "input": "1 1 10", "output": "10" }, { "input": "2 -4 4", "output": "5" }, { "input": "1 1 1", "output": "1" }, { "input": "1 0 0", "output": "1" }, { "input": "1 0 1", "output": "2" }, { "input": "1 10181 10182", "output": "2" }, { "input": "1 10182 10183", "output": "2" }, { "input": "1 -191 1011", "output": "1203" }, { "input": "2 0 0", "output": "1" }, { "input": "2 0 1", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "2 2 3", "output": "1" }, { "input": "2 -1 0", "output": "1" }, { "input": "2 -1 1", "output": "1" }, { "input": "2 -7 -6", "output": "1" }, { "input": "2 -7 -5", "output": "1" }, { "input": "2 -6 -6", "output": "1" }, { "input": "2 -6 -4", "output": "2" }, { "input": "2 -6 13", "output": "10" }, { "input": "2 -19171 1911", "output": "10541" }, { "input": "3 123 456", "output": "112" }, { "input": "3 124 456", "output": "111" }, { "input": "3 125 456", "output": "111" }, { "input": "3 381 281911", "output": "93844" }, { "input": "3 381 281912", "output": "93844" }, { "input": "3 381 281913", "output": "93845" }, { "input": "3 382 281911", "output": "93843" }, { "input": "3 382 281912", "output": "93843" }, { "input": "3 382 281913", "output": "93844" }, { "input": "3 383 281911", "output": "93843" }, { "input": "3 383 281912", "output": "93843" }, { "input": "3 383 281913", "output": "93844" }, { "input": "3 -381 281911", "output": "94098" }, { "input": "3 -381 281912", "output": "94098" }, { "input": "3 -381 281913", "output": "94099" }, { "input": "3 -380 281911", "output": "94097" }, { "input": "3 -380 281912", "output": "94097" }, { "input": "3 -380 281913", "output": "94098" }, { "input": "3 -379 281911", "output": "94097" }, { "input": "3 -379 281912", "output": "94097" }, { "input": "3 -379 281913", "output": "94098" }, { "input": "3 -191381 -1911", "output": "63157" }, { "input": "3 -191381 -1910", "output": "63157" }, { "input": "3 -191381 -1909", "output": "63157" }, { "input": "3 -191380 -1911", "output": "63157" }, { "input": "3 -191380 -1910", "output": "63157" }, { "input": "3 -191380 -1909", "output": "63157" }, { "input": "3 -191379 -1911", "output": "63157" }, { "input": "3 -191379 -1910", "output": "63157" }, { "input": "3 -191379 -1909", "output": "63157" }, { "input": "3 -2810171 0", "output": "936724" }, { "input": "3 0 29101", "output": "9701" }, { "input": "3 -2810170 0", "output": "936724" }, { "input": "3 0 29102", "output": "9701" }, { "input": "3 -2810169 0", "output": "936724" }, { "input": "3 0 29103", "output": "9702" }, { "input": "1 -1000000000000000000 1000000000000000000", "output": "2000000000000000001" }, { "input": "2 -1000000000000000000 1000000000000000000", "output": "1000000000000000001" }, { "input": "3 -1000000000000000000 1000000000000000000", "output": "666666666666666667" }, { "input": "4 -1000000000000000000 1000000000000000000", "output": "500000000000000001" }, { "input": "5 -1000000000000000000 1000000000000000000", "output": "400000000000000001" }, { "input": "6 -1000000000000000000 1000000000000000000", "output": "333333333333333333" }, { "input": "7 -1000000000000000000 1000000000000000000", "output": "285714285714285715" }, { "input": "1 -1000000000000000000 -100000000000000000", "output": "900000000000000001" }, { "input": "2 -1000000000000000000 -10000000000000000", "output": "495000000000000001" }, { "input": "3 -1000000000000000000 -10218000000000000", "output": "329927333333333334" }, { "input": "4 -1000000000000000000 -320110181919100", "output": "249919972454520226" }, { "input": "5 -1000000000000000000 -402710171917", "output": "199999919457965617" }, { "input": "6 -1000000000000000000 -6666666666", "output": "166666665555555556" }, { "input": "7 -1000000000000000000 -77777777777778", "output": "142846031746031746" }, { "input": "1000000000000000000 -1000000000000000000 1000000000000000000", "output": "3" }, { "input": "1000000000000000000 0 1000000000000000000", "output": "2" }, { "input": "1000000000000000000 1000000000000000000 1000000000000000000", "output": "1" }, { "input": "100000000000000321 1000000000000000000 1000000000000000000", "output": "0" }, { "input": "100000000000000321 -1000000000000000000 1000000000000000000", "output": "19" }, { "input": "1000000000000000000 0 0", "output": "1" }, { "input": "1000000000000000000 1 1", "output": "0" }, { "input": "1000000000000000000 -1 -1", "output": "0" }, { "input": "1000000000000000000 -2 -1", "output": "0" }, { "input": "142000000000000271 -228118171 -1382811", "output": "0" }, { "input": "1 1 1000000000000000000", "output": "1000000000000000000" } ]
1,615,780,561
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
12
108
0
from math import floor def seal(a, b): return (a + b - 1)//b k,a,b = map(int,input().split()) ans = abs(b)//k + abs(a)//k if(a < 0 and b > 0): values = b - a + 1 print(ans + 1) else: a,b = abs(a), abs(b) lower = seal(a,k) upper = floor(b/k) print(upper - lower + 1) # if(a % k == 0 and b % k == 0 and k != 1): # ans += 1 # print(ans)
Title: Divisibility Time Limit: None seconds Memory Limit: None megabytes Problem Description: Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. Input Specification: The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018). Output Specification: Print the required number. Demo Input: ['1 1 10\n', '2 -4 4\n'] Demo Output: ['10\n', '5\n'] Note: none
```python from math import floor def seal(a, b): return (a + b - 1)//b k,a,b = map(int,input().split()) ans = abs(b)//k + abs(a)//k if(a < 0 and b > 0): values = b - a + 1 print(ans + 1) else: a,b = abs(a), abs(b) lower = seal(a,k) upper = floor(b/k) print(upper - lower + 1) # if(a % k == 0 and b % k == 0 and k != 1): # ans += 1 # print(ans) ```
0
305
A
Strange Addition
PROGRAMMING
1,600
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers. The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100).
In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
[ "4\n100 10 1 0\n", "3\n2 70 3\n" ]
[ "4\n0 1 10 100 ", "2\n2 70 " ]
none
500
[ { "input": "4\n100 10 1 0", "output": "4\n0 1 10 100 " }, { "input": "3\n2 70 3", "output": "2\n2 70 " }, { "input": "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29", "output": "4\n0 6 30 100 " }, { "input": "50\n20 67 96 6 75 12 37 46 38 86 83 22 10 8 21 2 93 9 81 49 69 52 63 62 70 92 97 40 47 99 16 85 48 77 39 100 28 5 11 44 89 1 19 42 35 27 7 14 88 33", "output": "3\n1 10 100 " }, { "input": "2\n1 2", "output": "1\n1 " }, { "input": "73\n39 66 3 59 40 93 72 34 95 79 83 65 99 57 48 44 82 76 31 21 64 19 53 75 37 16 43 5 47 24 15 22 20 55 45 74 42 10 61 49 23 80 35 62 2 9 67 97 51 81 1 70 88 63 33 25 68 13 69 71 73 6 18 52 41 38 96 46 92 85 14 36 100", "output": "3\n1 10 100 " }, { "input": "15\n74 90 73 47 36 44 81 21 66 92 2 38 62 72 49", "output": "2\n2 90 " }, { "input": "96\n17 10 0 85 57 78 15 99 55 6 7 88 12 95 58 19 47 18 96 82 21 80 97 77 46 31 54 70 23 60 59 100 66 92 51 14 91 25 16 27 44 4 35 98 8 52 24 5 81 29 73 13 61 56 45 75 49 71 94 48 3 76 32 65 72 1 84 36 86 40 83 50 22 33 41 11 26 93 90 43 39 79 89 9 64 68 42 74 87 2 62 34 20 63 67 37", "output": "4\n0 1 10 100 " }, { "input": "5\n23 75 38 47 70", "output": "1\n23 " }, { "input": "12\n89 61 45 92 22 3 94 66 48 21 54 14", "output": "1\n3 " }, { "input": "1\n99", "output": "1\n99 " }, { "input": "1\n0", "output": "1\n0 " }, { "input": "2\n100 1", "output": "2\n1 100 " }, { "input": "3\n1 100 99", "output": "2\n1 100 " }, { "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": "3\n1 10 100 " }, { "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 100 0", "output": "4\n0 1 10 100 " }, { "input": "99\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", "output": "2\n1 10 " }, { "input": "2\n5 6", "output": "1\n5 " }, { "input": "81\n11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 58 59 61 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 78 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99", "output": "1\n11 " }, { "input": "3\n99 10 6", "output": "2\n6 10 " }, { "input": "4\n11 10 100 3", "output": "3\n3 10 100 " }, { "input": "2\n99 6", "output": "1\n6 " }, { "input": "3\n23 0 100", "output": "3\n0 23 100 " }, { "input": "2\n43 0", "output": "2\n0 43 " }, { "input": "4\n99 0 100 6", "output": "3\n0 6 100 " }, { "input": "1\n100", "output": "1\n100 " }, { "input": "2\n0 100", "output": "2\n0 100 " }, { "input": "3\n0 100 10", "output": "3\n0 10 100 " }, { "input": "3\n0 100 12", "output": "3\n0 12 100 " }, { "input": "3\n0 100 1", "output": "3\n0 1 100 " }, { "input": "4\n0 100 10 1", "output": "4\n0 1 10 100 " }, { "input": "4\n0 100 10 99", "output": "3\n0 10 100 " }, { "input": "1\n1", "output": "1\n1 " }, { "input": "2\n10 12", "output": "1\n10 " }, { "input": "2\n90 9", "output": "2\n9 90 " } ]
1,615,539,545
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
186
0
k=int(input()) l=list(map(int,input().split())) r=0 q1=[] q2=[] for i in range(k): if(l[i]==0): q1.append(l[i]) elif(l[i]%10==0): q1.append(l[i]) for i in range(k): if(l[i]!=0 and l[i]%10!=0): r=r+1 q2.append(l[i]) if(r==len(q1)): break print(len(q1)+r) for i in range(len(q1)): print(q1[i],end=" ") for i in range(len(q2)): print(q2[i],end=" ")
Title: Strange Addition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? Input Specification: The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers. The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100). Output Specification: In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. Demo Input: ['4\n100 10 1 0\n', '3\n2 70 3\n'] Demo Output: ['4\n0 1 10 100 ', '2\n2 70 '] Note: none
```python k=int(input()) l=list(map(int,input().split())) r=0 q1=[] q2=[] for i in range(k): if(l[i]==0): q1.append(l[i]) elif(l[i]%10==0): q1.append(l[i]) for i in range(k): if(l[i]!=0 and l[i]%10!=0): r=r+1 q2.append(l[i]) if(r==len(q1)): break print(len(q1)+r) for i in range(len(q1)): print(q1[i],end=" ") for i in range(len(q2)): print(q2[i],end=" ") ```
0
401
A
Vanya and Cards
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*.
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value.
Print a single number — the answer to the problem.
[ "3 2\n-1 1 2\n", "2 3\n-2 -2\n" ]
[ "1\n", "2\n" ]
In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
500
[ { "input": "3 2\n-1 1 2", "output": "1" }, { "input": "2 3\n-2 -2", "output": "2" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "2 2\n-1 -1", "output": "1" }, { "input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2", "output": "4" }, { "input": "15 16\n-15 -5 -15 -14 -8 15 -15 -12 -5 -3 5 -7 3 8 -15", "output": "6" }, { "input": "1 4\n-3", "output": "1" }, { "input": "10 7\n6 4 6 6 -3 4 -1 2 3 3", "output": "5" }, { "input": "2 1\n1 -1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "8 13\n-11 -1 -11 12 -2 -2 -10 -11", "output": "3" }, { "input": "16 11\n3 -7 7 -9 -2 -3 -4 -2 -6 8 10 7 1 4 6 7", "output": "2" }, { "input": "67 15\n-2 -2 6 -4 -7 4 3 13 -9 -4 11 -7 -6 -11 1 11 -1 11 14 10 -8 7 5 11 -13 1 -1 7 -14 9 -11 -11 13 -4 12 -11 -8 -5 -11 6 10 -2 6 9 9 6 -11 -2 7 -10 -1 9 -8 -5 1 -7 -2 3 -1 -13 -6 -9 -8 10 13 -3 9", "output": "1" }, { "input": "123 222\n44 -190 -188 -185 -55 17 190 176 157 176 -24 -113 -54 -61 -53 53 -77 68 -12 -114 -217 163 -122 37 -37 20 -108 17 -140 -210 218 19 -89 54 18 197 111 -150 -36 -131 -172 36 67 16 -202 72 169 -137 -34 -122 137 -72 196 -17 -104 180 -102 96 -69 -184 21 -15 217 -61 175 -221 62 173 -93 -106 122 -135 58 7 -110 -108 156 -141 -102 -50 29 -204 -46 -76 101 -33 -190 99 52 -197 175 -71 161 -140 155 10 189 -217 -97 -170 183 -88 83 -149 157 -208 154 -3 77 90 74 165 198 -181 -166 -4 -200 -89 -200 131 100 -61 -149", "output": "8" }, { "input": "130 142\n58 -50 43 -126 84 -92 -108 -92 57 127 12 -135 -49 89 141 -112 -31 47 75 -19 80 81 -5 17 10 4 -26 68 -102 -10 7 -62 -135 -123 -16 55 -72 -97 -34 21 21 137 130 97 40 -18 110 -52 73 52 85 103 -134 -107 88 30 66 97 126 82 13 125 127 -87 81 22 45 102 13 95 4 10 -35 39 -43 -112 -5 14 -46 19 61 -44 -116 137 -116 -80 -39 92 -75 29 -65 -15 5 -108 -114 -129 -5 52 -21 118 -41 35 -62 -125 130 -95 -11 -75 19 108 108 127 141 2 -130 54 96 -81 -102 140 -58 -102 132 50 -126 82 6 45 -114 -42", "output": "5" }, { "input": "7 12\n2 5 -1 -4 -7 4 3", "output": "1" }, { "input": "57 53\n-49 7 -41 7 38 -51 -23 8 45 1 -24 26 37 28 -31 -40 38 25 -32 -47 -3 20 -40 -32 -44 -36 5 33 -16 -5 28 10 -22 3 -10 -51 -32 -51 27 -50 -22 -12 41 3 15 24 30 -12 -34 -15 -29 38 -10 -35 -9 6 -51", "output": "8" }, { "input": "93 273\n-268 -170 -163 19 -69 18 -244 35 -34 125 -224 -48 179 -247 127 -150 271 -49 -102 201 84 -151 -70 -46 -16 216 240 127 3 218 -209 223 -227 -201 228 -8 203 46 -100 -207 126 255 40 -58 -217 93 172 -97 23 183 102 -92 -157 -117 173 47 144 -235 -227 -62 -128 13 -151 158 110 -116 68 -2 -148 -206 -52 79 -152 -223 74 -149 -69 232 38 -70 -256 -213 -236 132 -189 -200 199 -57 -108 -53 269 -101 -134", "output": "8" }, { "input": "1 1000\n997", "output": "1" }, { "input": "4 3\n2 -1 -2 -1", "output": "1" }, { "input": "1 1\n-1", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "2 2\n1 -1", "output": "0" }, { "input": "2 2\n-1 1", "output": "0" }, { "input": "2 3\n-1 1", "output": "0" }, { "input": "2 2\n-2 2", "output": "0" }, { "input": "2 2\n2 2", "output": "2" }, { "input": "4 2\n-1 -1 -1 -1", "output": "2" }, { "input": "4 1\n-1 -1 -1 1", "output": "2" }, { "input": "3 2\n2 2 2", "output": "3" }, { "input": "10 300\n300 300 300 300 300 300 300 300 300 300", "output": "10" } ]
1,616,254,536
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
36
62
307,200
n,x=[int(i) for i in input().split()] xi=[int(x) for x in input().split()] s=sum(xi) s=abs(s) cnt=0 for i in range(x,0,-1): if(s<=0): print(cnt) break if(s>i): q=s//i s-=(i*q) cnt+=q else: s-=i cnt+=1
Title: Vanya and Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*. Input Specification: The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value. Output Specification: Print a single number — the answer to the problem. Demo Input: ['3 2\n-1 1 2\n', '2 3\n-2 -2\n'] Demo Output: ['1\n', '2\n'] Note: In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
```python n,x=[int(i) for i in input().split()] xi=[int(x) for x in input().split()] s=sum(xi) s=abs(s) cnt=0 for i in range(x,0,-1): if(s<=0): print(cnt) break if(s>i): q=s//i s-=(i*q) cnt+=q else: s-=i cnt+=1 ```
0
61
D
Eternal Victory
PROGRAMMING
1,800
[ "dfs and similar", "graphs", "greedy", "shortest paths", "trees" ]
D. Eternal Victory
2
256
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these *n* cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities. All cities are numbered 1 to *n*. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city. Help Shapur find how much He should travel.
First line contains a single natural number *n* (1<=≤<=*n*<=≤<=105) — the amount of cities. Next *n*<=-<=1 lines contain 3 integer numbers each *x**i*, *y**i* and *w**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=0<=≤<=*w**i*<=≤<=2<=×<=104). *x**i* and *y**i* are two ends of a road and *w**i* is the length of that road.
A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
[ "3\n1 2 3\n2 3 4\n", "3\n1 2 3\n1 3 3\n" ]
[ "7\n", "9\n" ]
none
2,000
[ { "input": "3\n1 2 3\n2 3 4", "output": "7" }, { "input": "3\n1 2 3\n1 3 3", "output": "9" }, { "input": "5\n5 3 60\n4 3 63\n2 1 97\n3 1 14", "output": "371" }, { "input": "3\n2 1 63\n3 1 78", "output": "204" }, { "input": "13\n8 2 58\n2 1 49\n13 10 41\n11 9 67\n6 4 18\n7 1 79\n3 2 58\n9 7 92\n10 6 62\n4 3 5\n12 4 87\n5 3 66", "output": "1126" }, { "input": "2\n2 1 89", "output": "89" }, { "input": "12\n3 1 31\n5 2 94\n9 8 37\n10 9 45\n7 5 75\n4 2 77\n6 3 31\n11 6 14\n8 7 19\n2 1 68\n12 1 60", "output": "764" }, { "input": "2\n2 1 5", "output": "5" }, { "input": "12\n3 2 52\n4 1 2\n5 2 68\n6 1 93\n8 5 60\n2 1 88\n9 8 44\n7 5 48\n11 2 31\n10 4 45\n12 7 58", "output": "916" }, { "input": "15\n12 1 52\n3 2 10\n4 1 45\n11 7 20\n10 3 54\n13 9 44\n15 2 8\n14 5 55\n9 3 32\n2 1 32\n8 4 14\n6 5 24\n5 3 74\n7 6 88", "output": "856" }, { "input": "1", "output": "0" }, { "input": "3\n1 2 0\n2 3 0", "output": "0" }, { "input": "6\n1 2 3\n1 3 1\n3 4 1\n4 5 1\n5 6 1", "output": "10" } ]
1,619,556,298
2,147,483,647
Python 3
OK
TESTS
56
655
18,432,000
n = int(input()) matrix = [[] * n for i in range(n)] conn = dict() def dfs(el, el2): suma = 0 for element in matrix[el]: if element[0] != el2: suma = max(suma, element[1]+dfs(element[0],el)) return suma suma=0 for i in range(n-1): line = input() line = line.split(' ') matrix[int(line[0])-1].append((int(line[1])-1,int(line[2]))) matrix[int(line[1])-1].append((int(line[0])-1,int(line[2]))) suma += 2*int(line[2]) print(suma-dfs(0,-1))
Title: Eternal Victory Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these *n* cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities. All cities are numbered 1 to *n*. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city. Help Shapur find how much He should travel. Input Specification: First line contains a single natural number *n* (1<=≤<=*n*<=≤<=105) — the amount of cities. Next *n*<=-<=1 lines contain 3 integer numbers each *x**i*, *y**i* and *w**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=0<=≤<=*w**i*<=≤<=2<=×<=104). *x**i* and *y**i* are two ends of a road and *w**i* is the length of that road. Output Specification: A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). Demo Input: ['3\n1 2 3\n2 3 4\n', '3\n1 2 3\n1 3 3\n'] Demo Output: ['7\n', '9\n'] Note: none
```python n = int(input()) matrix = [[] * n for i in range(n)] conn = dict() def dfs(el, el2): suma = 0 for element in matrix[el]: if element[0] != el2: suma = max(suma, element[1]+dfs(element[0],el)) return suma suma=0 for i in range(n-1): line = input() line = line.split(' ') matrix[int(line[0])-1].append((int(line[1])-1,int(line[2]))) matrix[int(line[1])-1].append((int(line[0])-1,int(line[2]))) suma += 2*int(line[2]) print(suma-dfs(0,-1)) ```
3.801918
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,692,717,212
2,147,483,647
Python 3
OK
TESTS
30
92
0
string = input() summ1 = sum(i.isupper() for i in string) summ2 = sum(k.islower() for k in string) if summ2 >= summ1: print(string.lower()) elif summ1 > summ2: print(string.upper())
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 string = input() summ1 = sum(i.isupper() for i in string) summ2 = sum(k.islower() for k in string) if summ2 >= summ1: print(string.lower()) elif summ1 > summ2: print(string.upper()) ```
3.977
597
A
Divisibility
PROGRAMMING
1,600
[ "math" ]
null
null
Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018).
Print the required number.
[ "1 1 10\n", "2 -4 4\n" ]
[ "10\n", "5\n" ]
none
500
[ { "input": "1 1 10", "output": "10" }, { "input": "2 -4 4", "output": "5" }, { "input": "1 1 1", "output": "1" }, { "input": "1 0 0", "output": "1" }, { "input": "1 0 1", "output": "2" }, { "input": "1 10181 10182", "output": "2" }, { "input": "1 10182 10183", "output": "2" }, { "input": "1 -191 1011", "output": "1203" }, { "input": "2 0 0", "output": "1" }, { "input": "2 0 1", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "2 2 3", "output": "1" }, { "input": "2 -1 0", "output": "1" }, { "input": "2 -1 1", "output": "1" }, { "input": "2 -7 -6", "output": "1" }, { "input": "2 -7 -5", "output": "1" }, { "input": "2 -6 -6", "output": "1" }, { "input": "2 -6 -4", "output": "2" }, { "input": "2 -6 13", "output": "10" }, { "input": "2 -19171 1911", "output": "10541" }, { "input": "3 123 456", "output": "112" }, { "input": "3 124 456", "output": "111" }, { "input": "3 125 456", "output": "111" }, { "input": "3 381 281911", "output": "93844" }, { "input": "3 381 281912", "output": "93844" }, { "input": "3 381 281913", "output": "93845" }, { "input": "3 382 281911", "output": "93843" }, { "input": "3 382 281912", "output": "93843" }, { "input": "3 382 281913", "output": "93844" }, { "input": "3 383 281911", "output": "93843" }, { "input": "3 383 281912", "output": "93843" }, { "input": "3 383 281913", "output": "93844" }, { "input": "3 -381 281911", "output": "94098" }, { "input": "3 -381 281912", "output": "94098" }, { "input": "3 -381 281913", "output": "94099" }, { "input": "3 -380 281911", "output": "94097" }, { "input": "3 -380 281912", "output": "94097" }, { "input": "3 -380 281913", "output": "94098" }, { "input": "3 -379 281911", "output": "94097" }, { "input": "3 -379 281912", "output": "94097" }, { "input": "3 -379 281913", "output": "94098" }, { "input": "3 -191381 -1911", "output": "63157" }, { "input": "3 -191381 -1910", "output": "63157" }, { "input": "3 -191381 -1909", "output": "63157" }, { "input": "3 -191380 -1911", "output": "63157" }, { "input": "3 -191380 -1910", "output": "63157" }, { "input": "3 -191380 -1909", "output": "63157" }, { "input": "3 -191379 -1911", "output": "63157" }, { "input": "3 -191379 -1910", "output": "63157" }, { "input": "3 -191379 -1909", "output": "63157" }, { "input": "3 -2810171 0", "output": "936724" }, { "input": "3 0 29101", "output": "9701" }, { "input": "3 -2810170 0", "output": "936724" }, { "input": "3 0 29102", "output": "9701" }, { "input": "3 -2810169 0", "output": "936724" }, { "input": "3 0 29103", "output": "9702" }, { "input": "1 -1000000000000000000 1000000000000000000", "output": "2000000000000000001" }, { "input": "2 -1000000000000000000 1000000000000000000", "output": "1000000000000000001" }, { "input": "3 -1000000000000000000 1000000000000000000", "output": "666666666666666667" }, { "input": "4 -1000000000000000000 1000000000000000000", "output": "500000000000000001" }, { "input": "5 -1000000000000000000 1000000000000000000", "output": "400000000000000001" }, { "input": "6 -1000000000000000000 1000000000000000000", "output": "333333333333333333" }, { "input": "7 -1000000000000000000 1000000000000000000", "output": "285714285714285715" }, { "input": "1 -1000000000000000000 -100000000000000000", "output": "900000000000000001" }, { "input": "2 -1000000000000000000 -10000000000000000", "output": "495000000000000001" }, { "input": "3 -1000000000000000000 -10218000000000000", "output": "329927333333333334" }, { "input": "4 -1000000000000000000 -320110181919100", "output": "249919972454520226" }, { "input": "5 -1000000000000000000 -402710171917", "output": "199999919457965617" }, { "input": "6 -1000000000000000000 -6666666666", "output": "166666665555555556" }, { "input": "7 -1000000000000000000 -77777777777778", "output": "142846031746031746" }, { "input": "1000000000000000000 -1000000000000000000 1000000000000000000", "output": "3" }, { "input": "1000000000000000000 0 1000000000000000000", "output": "2" }, { "input": "1000000000000000000 1000000000000000000 1000000000000000000", "output": "1" }, { "input": "100000000000000321 1000000000000000000 1000000000000000000", "output": "0" }, { "input": "100000000000000321 -1000000000000000000 1000000000000000000", "output": "19" }, { "input": "1000000000000000000 0 0", "output": "1" }, { "input": "1000000000000000000 1 1", "output": "0" }, { "input": "1000000000000000000 -1 -1", "output": "0" }, { "input": "1000000000000000000 -2 -1", "output": "0" }, { "input": "142000000000000271 -228118171 -1382811", "output": "0" }, { "input": "1 1 1000000000000000000", "output": "1000000000000000000" } ]
1,591,851,464
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
93
0
import sys k, a, b = map(int, sys.stdin.readline().rsplit()) c = (abs(b - a))//k if not b%k or not b%k: c += 1 print(c)
Title: Divisibility Time Limit: None seconds Memory Limit: None megabytes Problem Description: Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. Input Specification: The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018). Output Specification: Print the required number. Demo Input: ['1 1 10\n', '2 -4 4\n'] Demo Output: ['10\n', '5\n'] Note: none
```python import sys k, a, b = map(int, sys.stdin.readline().rsplit()) c = (abs(b - a))//k if not b%k or not b%k: c += 1 print(c) ```
0
810
A
Straight <<A>>
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
[ "2 10\n8 9\n", "3 5\n4 4 4\n" ]
[ "4", "3" ]
Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
500
[ { "input": "2 10\n8 9", "output": "4" }, { "input": "3 5\n4 4 4", "output": "3" }, { "input": "3 10\n10 8 9", "output": "3" }, { "input": "2 23\n21 23", "output": "2" }, { "input": "5 10\n5 10 10 9 10", "output": "7" }, { "input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12", "output": "712" }, { "input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6", "output": "482" }, { "input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28", "output": "6469" }, { "input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31", "output": "1340" }, { "input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61", "output": "329" }, { "input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16", "output": "5753" }, { "input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29", "output": "0" }, { "input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25", "output": "851" }, { "input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4", "output": "5884" }, { "input": "82 88\n1 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 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1", "output": "14170" }, { "input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30", "output": "6650" }, { "input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20", "output": "11786" }, { "input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28", "output": "3182" }, { "input": "1 26\n26", "output": "0" }, { "input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26", "output": "1807" }, { "input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4", "output": "946" }, { "input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2", "output": "3164" }, { "input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16", "output": "1262" }, { "input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18", "output": "2024" }, { "input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15", "output": "1984" }, { "input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55", "output": "740" }, { "input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4", "output": "14888" }, { "input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40", "output": "13118" }, { "input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76", "output": "3030" }, { "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": "19700" }, { "input": "100 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": "0" }, { "input": "100 100\n1 1 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "19696" }, { "input": "100 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": "0" }, { "input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 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": "0" }, { "input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100", "output": "2" }, { "input": "100 1\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": "0" }, { "input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1", "output": "16" }, { "input": "3 5\n5 5 5", "output": "0" }, { "input": "7 7\n1 1 1 1 1 1 1", "output": "77" }, { "input": "1 1\n1", "output": "0" }, { "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": "19700" }, { "input": "4 10\n10 10 10 10", "output": "0" }, { "input": "1 10\n10", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3 10\n10 10 10", "output": "0" }, { "input": "2 4\n3 4", "output": "0" }, { "input": "1 2\n2", "output": "0" }, { "input": "3 4\n4 4 4", "output": "0" }, { "input": "3 2\n2 2 1", "output": "0" }, { "input": "5 5\n5 5 5 5 5", "output": "0" }, { "input": "3 3\n3 3 3", "output": "0" }, { "input": "2 9\n8 9", "output": "0" }, { "input": "3 10\n9 10 10", "output": "0" }, { "input": "1 3\n3", "output": "0" }, { "input": "2 2\n1 2", "output": "0" }, { "input": "2 10\n10 10", "output": "0" }, { "input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14", "output": "0" }, { "input": "2 10\n9 10", "output": "0" }, { "input": "2 2\n2 2", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 5 5 4", "output": "0" }, { "input": "3 5\n4 5 5", "output": "0" }, { "input": "5 4\n4 4 4 4 4", "output": "0" }, { "input": "2 10\n10 9", "output": "0" }, { "input": "4 5\n3 5 5 5", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "3 10\n10 10 9", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "4 10\n9 10 10 10", "output": "0" }, { "input": "5 2\n2 2 2 2 2", "output": "0" }, { "input": "2 5\n4 5", "output": "0" }, { "input": "5 10\n10 10 10 10 10", "output": "0" }, { "input": "2 6\n6 6", "output": "0" }, { "input": "2 9\n9 9", "output": "0" }, { "input": "3 10\n10 9 10", "output": "0" }, { "input": "4 40\n39 40 40 40", "output": "0" }, { "input": "3 4\n3 4 4", "output": "0" }, { "input": "9 9\n9 9 9 9 9 9 9 9 9", "output": "0" }, { "input": "1 4\n4", "output": "0" }, { "input": "4 7\n1 1 1 1", "output": "44" }, { "input": "1 5\n5", "output": "0" }, { "input": "3 1\n1 1 1", "output": "0" }, { "input": "1 100\n100", "output": "0" }, { "input": "2 7\n3 5", "output": "10" }, { "input": "3 6\n6 6 6", "output": "0" }, { "input": "4 2\n1 2 2 2", "output": "0" }, { "input": "4 5\n4 5 5 5", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "35" }, { "input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1", "output": "0" }, { "input": "2 2\n2 1", "output": "0" }, { "input": "5 5\n5 5 5 4 5", "output": "0" }, { "input": "3 7\n1 1 1", "output": "33" }, { "input": "2 5\n5 5", "output": "0" }, { "input": "1 7\n1", "output": "11" }, { "input": "6 7\n1 1 1 1 1 1", "output": "66" }, { "input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64", "output": "10077" }, { "input": "8 7\n1 1 1 1 1 1 1 1", "output": "88" }, { "input": "3 2\n2 2 2", "output": "0" }, { "input": "6 5\n5 5 5 5 5 5", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 4 1 1", "output": "8" }, { "input": "1 5\n1", "output": "7" }, { "input": "10 10\n10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "2 3\n2 3", "output": "0" }, { "input": "1 9\n9", "output": "0" }, { "input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2", "output": "0" }, { "input": "5 5\n5 5 5 5 4", "output": "0" } ]
1,590,263,240
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
29
1,000
102,400
n, k = map(int,input().split()) A = list(map(int,input().split())) count = 0 while sum(A) / n < k - 0.5: A.append(k) n += 1 count += 1 print(count)
Title: Straight <<A>> Time Limit: None seconds Memory Limit: None megabytes Problem Description: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. Output Specification: Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. Demo Input: ['2 10\n8 9\n', '3 5\n4 4 4\n'] Demo Output: ['4', '3'] Note: Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
```python n, k = map(int,input().split()) A = list(map(int,input().split())) count = 0 while sum(A) / n < k - 0.5: A.append(k) n += 1 count += 1 print(count) ```
0
346
E
Doodle Jump
PROGRAMMING
3,000
[ "math", "number theory" ]
null
null
In Doodle Jump the aim is to guide a four-legged creature called "The Doodler" up a never-ending series of platforms without falling. — Wikipedia. It is a very popular game and xiaodao likes it very much. One day when playing the game she wondered whether there exists a platform that the doodler couldn't reach due to the limits of its jumping ability. Consider the following problem. There are *n* platforms. The height of the *x*-th (1<=≤<=*x*<=≤<=*n*) platform is *a*·*x* mod *p*, where *a* and *p* are positive co-prime integers. The maximum possible height of a Doodler's jump is *h*. That is, it can jump from height *h*1 to height *h*2 (*h*1<=&lt;<=*h*2) if *h*2<=-<=*h*1<=≤<=*h*. Initially, the Doodler is on the ground, the height of which is 0. The question is whether it can reach the highest platform or not. For example, when *a*<==<=7, *n*<==<=4, *p*<==<=12, *h*<==<=2, the heights of the platforms are 7, 2, 9, 4 as in the picture below. With the first jump the Doodler can jump to the platform at height 2, with the second one the Doodler can jump to the platform at height 4, but then it can't jump to any of the higher platforms. So, it can't reach the highest platform. User xiaodao thought about the problem for a long time but didn't solve it, so she asks you for help. Also, she has a lot of instances of the problem. Your task is solve all of these instances.
The first line contains an integer *t* (1<=≤<=*t*<=≤<=104) — the number of problem instances. Each of the next *t* lines contains four integers *a*, *n*, *p* and *h* (1<=≤<=*a*<=≤<=109, 1<=≤<=*n*<=&lt;<=*p*<=≤<=109, 0<=≤<=*h*<=≤<=109). It's guaranteed that *a* and *p* are co-prime.
For each problem instance, if the Doodler can reach the highest platform, output "YES", otherwise output "NO".
[ "3\n7 4 12 2\n7 1 9 4\n7 4 12 3\n" ]
[ "NO\nNO\nYES\n" ]
none
2,500
[]
1,689,600,754
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1689600754.4636743")# 1689600754.4636924
Title: Doodle Jump Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Doodle Jump the aim is to guide a four-legged creature called "The Doodler" up a never-ending series of platforms without falling. — Wikipedia. It is a very popular game and xiaodao likes it very much. One day when playing the game she wondered whether there exists a platform that the doodler couldn't reach due to the limits of its jumping ability. Consider the following problem. There are *n* platforms. The height of the *x*-th (1<=≤<=*x*<=≤<=*n*) platform is *a*·*x* mod *p*, where *a* and *p* are positive co-prime integers. The maximum possible height of a Doodler's jump is *h*. That is, it can jump from height *h*1 to height *h*2 (*h*1<=&lt;<=*h*2) if *h*2<=-<=*h*1<=≤<=*h*. Initially, the Doodler is on the ground, the height of which is 0. The question is whether it can reach the highest platform or not. For example, when *a*<==<=7, *n*<==<=4, *p*<==<=12, *h*<==<=2, the heights of the platforms are 7, 2, 9, 4 as in the picture below. With the first jump the Doodler can jump to the platform at height 2, with the second one the Doodler can jump to the platform at height 4, but then it can't jump to any of the higher platforms. So, it can't reach the highest platform. User xiaodao thought about the problem for a long time but didn't solve it, so she asks you for help. Also, she has a lot of instances of the problem. Your task is solve all of these instances. Input Specification: The first line contains an integer *t* (1<=≤<=*t*<=≤<=104) — the number of problem instances. Each of the next *t* lines contains four integers *a*, *n*, *p* and *h* (1<=≤<=*a*<=≤<=109, 1<=≤<=*n*<=&lt;<=*p*<=≤<=109, 0<=≤<=*h*<=≤<=109). It's guaranteed that *a* and *p* are co-prime. Output Specification: For each problem instance, if the Doodler can reach the highest platform, output "YES", otherwise output "NO". Demo Input: ['3\n7 4 12 2\n7 1 9 4\n7 4 12 3\n'] Demo Output: ['NO\nNO\nYES\n'] Note: none
```python print("_RANDOM_GUESS_1689600754.4636743")# 1689600754.4636924 ```
0
552
B
Vanya and Books
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels the books.
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Print the number of digits needed to number all the books.
[ "13\n", "4\n" ]
[ "17\n", "4\n" ]
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
1,000
[ { "input": "13", "output": "17" }, { "input": "4", "output": "4" }, { "input": "100", "output": "192" }, { "input": "99", "output": "189" }, { "input": "1000000000", "output": "8888888899" }, { "input": "1000000", "output": "5888896" }, { "input": "999", "output": "2889" }, { "input": "55", "output": "101" }, { "input": "222222222", "output": "1888888896" }, { "input": "8", "output": "8" }, { "input": "13", "output": "17" }, { "input": "313", "output": "831" }, { "input": "1342", "output": "4261" }, { "input": "30140", "output": "139594" }, { "input": "290092", "output": "1629447" }, { "input": "2156660", "output": "13985516" }, { "input": "96482216", "output": "760746625" }, { "input": "943006819", "output": "8375950269" }, { "input": "1", "output": "1" }, { "input": "7", "output": "7" }, { "input": "35", "output": "61" }, { "input": "996", "output": "2880" }, { "input": "6120", "output": "23373" }, { "input": "30660", "output": "142194" }, { "input": "349463", "output": "1985673" }, { "input": "8171970", "output": "56092686" }, { "input": "36123011", "output": "277872985" }, { "input": "986747865", "output": "8769619683" }, { "input": "9", "output": "9" }, { "input": "10", "output": "11" }, { "input": "11", "output": "13" }, { "input": "101", "output": "195" }, { "input": "1000", "output": "2893" }, { "input": "1001", "output": "2897" }, { "input": "9999", "output": "38889" }, { "input": "10000", "output": "38894" }, { "input": "10001", "output": "38899" }, { "input": "99999", "output": "488889" }, { "input": "100000", "output": "488895" }, { "input": "100001", "output": "488901" }, { "input": "999999", "output": "5888889" }, { "input": "1000001", "output": "5888903" }, { "input": "9999999", "output": "68888889" }, { "input": "10000000", "output": "68888897" }, { "input": "10000001", "output": "68888905" }, { "input": "99999999", "output": "788888889" }, { "input": "100000000", "output": "788888898" }, { "input": "100000001", "output": "788888907" }, { "input": "999999999", "output": "8888888889" }, { "input": "95", "output": "181" }, { "input": "995", "output": "2877" }, { "input": "9995", "output": "38873" }, { "input": "99995", "output": "488869" }, { "input": "999999995", "output": "8888888853" }, { "input": "999999998", "output": "8888888880" } ]
1,647,923,041
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
n = int(input()) k = 1 cnt = 0 x = 9 while True: if n > x: cnt += x * k x += x * 10 k += 1 else: cnt += (x - (x - (n - (x - 9) // 10))) * k break print(cnt)
Title: Vanya and Books Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels the books. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. Output Specification: Print the number of digits needed to number all the books. Demo Input: ['13\n', '4\n'] Demo Output: ['17\n', '4\n'] Note: Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
```python n = int(input()) k = 1 cnt = 0 x = 9 while True: if n > x: cnt += x * k x += x * 10 k += 1 else: cnt += (x - (x - (n - (x - 9) // 10))) * k break print(cnt) ```
0
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,696,290,875
2,147,483,647
PyPy 3
OK
TESTS
37
186
1,024,000
# LUOGU_RID: 127188383 a=input() if '0' in a: e=a.index('0') a=a+'0' a=a[:e]+a[e+1:][:-1] else: a=a[1:] print(a)
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 # LUOGU_RID: 127188383 a=input() if '0' in a: e=a.index('0') a=a+'0' a=a[:e]+a[e+1:][:-1] else: a=a[1:] print(a) ```
3
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", "output": "18" }, { "input": "z\na", "output": "2" }, { "input": "ama\nsama", "output": "1" }, { "input": "aaabc\nbc", "output": "3" }, { "input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa", "output": "32" }, { "input": "ahmedaly\naly", "output": "5" }, { "input": "aa\na", "output": "1" }, { "input": "aa\nba", "output": "2" }, { "input": "cccba\nba", "output": "3" }, { "input": "a\nab", "output": "3" }, { "input": "dadc\ndddc", "output": "4" }, { "input": "aacaaab\nb", "output": "6" }, { "input": "dddc\ncdcde", "output": "9" }, { "input": "bbdab\ndab", "output": "2" }, { "input": "a\naa", "output": "1" }, { "input": "aa\nab", "output": "4" }, { "input": "codeforces\nces", "output": "7" } ]
1,640,258,213
2,147,483,647
PyPy 3-64
OK
TESTS
28
155
2,355,200
import sys input = sys.stdin.readline def main(): S = input() T = input() ls = len(S) lt = len(T) S = S[::-1] T = T[::-1] for i in range(min(ls, lt)): if S[i] != T[i]: break else: i += 1 print(ls + lt - i * 2) for _ in range(1): main()
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. Input Specification: The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. Output Specification: Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. Demo Input: ['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n'] Demo Output: ['2\n', '9\n', '7\n', '1\n'] Note: In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
```python import sys input = sys.stdin.readline def main(): S = input() T = input() ls = len(S) lt = len(T) S = S[::-1] T = T[::-1] for i in range(min(ls, lt)): if S[i] != T[i]: break else: i += 1 print(ls + lt - i * 2) for _ in range(1): main() ```
3
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82", "output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0" }, { "input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46", "output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0" }, { "input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38", "output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0" }, { "input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37", "output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37" }, { "input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61", "output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61" }, { "input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66", "output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0" }, { "input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82", "output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0" }, { "input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22", "output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20" }, { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41", "output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0" }, { "input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935", "output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0" }, { "input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952", "output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961" }, { "input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0", "output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673" }, { "input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0", "output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182" }, { "input": "5\n-1 -2 -3 -4 0", "output": "1 -1\n2 -4 -3\n2 0 -2" }, { "input": "3\n-101 101 0", "output": "1 -101\n1 101\n1 0" }, { "input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000", "output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000" }, { "input": "4\n0 -1 -2 -3", "output": "1 -1\n2 -3 -2\n1 0" } ]
1,591,970,933
2,147,483,647
PyPy 3
OK
TESTS
20
280
0
#A. Array n = int(input()) a,b,c =[],[],[] l = list(map(int,input().split())) for i in l: if i<0: a.append(i) elif i>0: b.append(i) else: c.append(i) if len(b)==0 and len(a)>2: b.append(a.pop()) b.append(a.pop()) if len(a)%2==0: c.append(a.pop()) print(len(a),*a) print(len(b),*b) print(len(c),*c)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. Output Specification: In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Demo Input: ['3\n-1 2 0\n', '4\n-1 -2 -3 0\n'] Demo Output: ['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n'] Note: none
```python #A. Array n = int(input()) a,b,c =[],[],[] l = list(map(int,input().split())) for i in l: if i<0: a.append(i) elif i>0: b.append(i) else: c.append(i) if len(b)==0 and len(a)>2: b.append(a.pop()) b.append(a.pop()) if len(a)%2==0: c.append(a.pop()) print(len(a),*a) print(len(b),*b) print(len(c),*c) ```
3
534
C
Polycarpus' Dice
PROGRAMMING
1,600
[ "math" ]
null
null
Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough to make a series of statements of the following type: dice *i* couldn't show number *r*. For example, if Polycarp had two six-faced dice and the total sum is *A*<==<=11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is *A*.
The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the *i*-th dice can show.
Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them.
[ "2 8\n4 4\n", "1 3\n5\n", "2 3\n2 3\n" ]
[ "3 3 ", "4 ", "0 1 " ]
In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement *A* equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
1,500
[ { "input": "2 8\n4 4", "output": "3 3 " }, { "input": "1 3\n5", "output": "4 " }, { "input": "2 3\n2 3", "output": "0 1 " }, { "input": "1 1\n3", "output": "2 " }, { "input": "1 2\n3", "output": "2 " }, { "input": "2 2\n2 3", "output": "1 2 " }, { "input": "2 4\n2 3", "output": "0 1 " }, { "input": "3 3\n5 1 5", "output": "4 0 4 " }, { "input": "3 4\n5 1 5", "output": "3 0 3 " }, { "input": "3 5\n5 1 5", "output": "2 0 2 " }, { "input": "3 6\n5 1 5", "output": "1 0 1 " }, { "input": "3 7\n5 1 5", "output": "0 0 0 " }, { "input": "3 8\n5 1 5", "output": "1 0 1 " }, { "input": "3 5\n1 2 100", "output": "0 0 98 " }, { "input": "10 20\n1 1 1 1 5 100 1 1 1 1", "output": "0 0 0 0 0 95 0 0 0 0 " }, { "input": "5 50\n1 1 1 1 1000000", "output": "0 0 0 0 999999 " }, { "input": "5 50\n2 2 2 2 1000000", "output": "0 0 0 0 999995 " }, { "input": "5 50\n10 10 10 10 1000000", "output": "0 0 0 0 999963 " }, { "input": "10 19\n1 5 6 1 6 4 1 2 9 5", "output": "0 0 0 0 0 0 0 0 0 0 " }, { "input": "10 40\n1 5 6 1 6 4 1 2 9 5", "output": "0 4 5 0 5 3 0 1 8 4 " }, { "input": "10 16\n5 7 7 5 9 3 8 5 7 2", "output": "0 0 0 0 2 0 1 0 0 0 " }, { "input": "10 58\n5 7 7 5 9 3 8 5 7 2", "output": "4 6 6 4 8 2 7 4 6 1 " }, { "input": "10 13\n9 9 6 9 10 4 5 10 8 9", "output": "5 5 2 5 6 0 1 6 4 5 " }, { "input": "10 79\n9 9 6 9 10 4 5 10 8 9", "output": "8 8 5 8 9 3 4 9 7 8 " }, { "input": "10 16\n4 1 8 3 3 3 4 3 6 6", "output": "0 0 1 0 0 0 0 0 0 0 " }, { "input": "10 41\n4 1 8 3 3 3 4 3 6 6", "output": "3 0 7 2 2 2 3 2 5 5 " }, { "input": "10 18\n8 1 9 8 4 1 1 8 6 2", "output": "0 0 0 0 0 0 0 0 0 0 " }, { "input": "10 48\n8 1 9 8 4 1 1 8 6 2", "output": "7 0 8 7 3 0 0 7 5 1 " }, { "input": "1 5\n5", "output": "4 " } ]
1,542,744,352
2,147,483,647
PyPy 3
OK
TESTS
99
358
20,889,600
n, A = map(int, input().split()) d = [int(x) for x in input().split()] s = sum(d) print(' '.join([str(x - min(x, A - n + 1) + max(1, A - s + x) - 1) for x in d]))
Title: Polycarpus' Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough to make a series of statements of the following type: dice *i* couldn't show number *r*. For example, if Polycarp had two six-faced dice and the total sum is *A*<==<=11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is *A*. Input Specification: The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the *i*-th dice can show. Output Specification: Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them. Demo Input: ['2 8\n4 4\n', '1 3\n5\n', '2 3\n2 3\n'] Demo Output: ['3 3 ', '4 ', '0 1 '] Note: In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3. In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5. In the third sample from the statement *A* equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
```python n, A = map(int, input().split()) d = [int(x) for x in input().split()] s = sum(d) print(' '.join([str(x - min(x, A - n + 1) + max(1, A - s + x) - 1) for x in d])) ```
3
877
D
Olya and Energy Drinks
PROGRAMMING
2,100
[ "data structures", "dfs and similar", "graphs", "shortest paths" ]
null
null
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run *k* meters per second. Each second she chooses one of the four directions (up, down, left or right) and runs from 1 to *k* meters in this direction. Of course, she can only run through empty cells. Now Olya needs to get from cell (*x*1,<=*y*1) to cell (*x*2,<=*y*2). How many seconds will it take her if she moves optimally? It's guaranteed that cells (*x*1,<=*y*1) and (*x*2,<=*y*2) are empty. These cells can coincide.
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the sizes of the room and Olya's speed. Then *n* lines follow containing *m* characters each, the *i*-th of them contains on *j*-th position "#", if the cell (*i*,<=*j*) is littered with cans, and "." otherwise. The last line contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*x*2<=≤<=*n*, 1<=≤<=*y*1,<=*y*2<=≤<=*m*) — the coordinates of the first and the last cells.
Print a single integer — the minimum time it will take Olya to get from (*x*1,<=*y*1) to (*x*2,<=*y*2). If it's impossible to get from (*x*1,<=*y*1) to (*x*2,<=*y*2), print -1.
[ "3 4 4\n....\n###.\n....\n1 1 3 1\n", "3 4 1\n....\n###.\n....\n1 1 3 1\n", "2 2 1\n.#\n#.\n1 1 2 2\n" ]
[ "3", "8", "-1" ]
In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second. In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds. Olya does not recommend drinking energy drinks and generally believes that this is bad.
2,000
[ { "input": "3 4 4\n....\n###.\n....\n1 1 3 1", "output": "3" }, { "input": "3 4 1\n....\n###.\n....\n1 1 3 1", "output": "8" }, { "input": "2 2 1\n.#\n#.\n1 1 2 2", "output": "-1" }, { "input": "10 10 1\n##########\n#.........\n#.#######.\n#.#.....#.\n#.#.###.#.\n#.#.#.#.#.\n#.#.#.#.#.\n#.#.#...#.\n#.#.#####.\n#.#.......\n6 6 10 2", "output": "48" }, { "input": "10 10 3\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n#########.\n#########.\n####..###.\n10 6 10 5", "output": "1" }, { "input": "10 10 3\n...##..#..\n#.#..#...#\n..#.##.#..\n##..#..#.#\n..#...##..\n.#.#.#....\n#......#..\n.#.####.##\n......#...\n.#.##...##\n4 6 8 1", "output": "7" }, { "input": "10 10 1000\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n7 6 1 3", "output": "2" }, { "input": "10 10 1000\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n.....#....\n3 9 5 1", "output": "2" }, { "input": "10 10 10\n...#......\n##.#.#####\n...#...###\n.#####.###\n...#...###\n##.#.#####\n...#...###\n.#####.###\n.......###\n##########\n1 1 1 10", "output": "17" }, { "input": "2 5 5\n#####\n##.##\n2 3 2 3", "output": "0" }, { "input": "4 4 4\n...#\n.#.#\n....\n##..\n1 1 3 4", "output": "2" }, { "input": "6 6 100\n....##\n.##.##\n.##.##\n......\n###.##\n###.##\n1 1 4 6", "output": "2" } ]
1,698,625,344
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
30
307,200
from collections import deque n, m, k = map(int, input().split()) g = [list(input()) for _ in range(n)] x1, y1, x2, y2 = map(int, input().split()) # print(g) path = [[float('inf')] * (m) for _ in range(n)] path[x1 - 1][y1 - 1] = 0 q = deque([]) q.append((x1 - 1, y1 - 1)) def check(l, r, a, b): for i in range(1, l + 1): if g[a + i][b] =='#': return False for i in range(1, r + 1): if g[a][b + i] =='#': return False return True while q: a, b = q.pop() for c in range(k, 0, -1): for l, r in ((0, c), (c, 0), (0, -c), (-c, 0)): x = a + l y = b + r if 0 <= x < n and 0 <= y < m and check(l, r, a, b) : # print(11, a, b, path[x][y], path[a][b] + 1) if path[x][y] > path[a][b] + 1: q.append((x, y)) path[x][y] = path[a][b] + 1 # print(path, x2, y2) print(path[x2 - 1][y2 -1] if path[x2 - 1][y2 - 1] != float('inf') else -1)
Title: Olya and Energy Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run *k* meters per second. Each second she chooses one of the four directions (up, down, left or right) and runs from 1 to *k* meters in this direction. Of course, she can only run through empty cells. Now Olya needs to get from cell (*x*1,<=*y*1) to cell (*x*2,<=*y*2). How many seconds will it take her if she moves optimally? It's guaranteed that cells (*x*1,<=*y*1) and (*x*2,<=*y*2) are empty. These cells can coincide. Input Specification: The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the sizes of the room and Olya's speed. Then *n* lines follow containing *m* characters each, the *i*-th of them contains on *j*-th position "#", if the cell (*i*,<=*j*) is littered with cans, and "." otherwise. The last line contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*x*2<=≤<=*n*, 1<=≤<=*y*1,<=*y*2<=≤<=*m*) — the coordinates of the first and the last cells. Output Specification: Print a single integer — the minimum time it will take Olya to get from (*x*1,<=*y*1) to (*x*2,<=*y*2). If it's impossible to get from (*x*1,<=*y*1) to (*x*2,<=*y*2), print -1. Demo Input: ['3 4 4\n....\n###.\n....\n1 1 3 1\n', '3 4 1\n....\n###.\n....\n1 1 3 1\n', '2 2 1\n.#\n#.\n1 1 2 2\n'] Demo Output: ['3', '8', '-1'] Note: In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second. In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds. Olya does not recommend drinking energy drinks and generally believes that this is bad.
```python from collections import deque n, m, k = map(int, input().split()) g = [list(input()) for _ in range(n)] x1, y1, x2, y2 = map(int, input().split()) # print(g) path = [[float('inf')] * (m) for _ in range(n)] path[x1 - 1][y1 - 1] = 0 q = deque([]) q.append((x1 - 1, y1 - 1)) def check(l, r, a, b): for i in range(1, l + 1): if g[a + i][b] =='#': return False for i in range(1, r + 1): if g[a][b + i] =='#': return False return True while q: a, b = q.pop() for c in range(k, 0, -1): for l, r in ((0, c), (c, 0), (0, -c), (-c, 0)): x = a + l y = b + r if 0 <= x < n and 0 <= y < m and check(l, r, a, b) : # print(11, a, b, path[x][y], path[a][b] + 1) if path[x][y] > path[a][b] + 1: q.append((x, y)) path[x][y] = path[a][b] + 1 # print(path, x2, y2) print(path[x2 - 1][y2 -1] if path[x2 - 1][y2 - 1] != float('inf') else -1) ```
0
432
D
Prefixes and Suffixes
PROGRAMMING
2,000
[ "dp", "string suffix structures", "strings", "two pointers" ]
null
null
You have a string *s*<==<=*s*1*s*2...*s*|*s*|, where |*s*| is the length of string *s*, and *s**i* its *i*-th character. Let's introduce several definitions: - A substring *s*[*i*..*j*] (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|) of string *s* is string *s**i**s**i*<=+<=1...*s**j*. - The prefix of string *s* of length *l* (1<=≤<=*l*<=≤<=|*s*|) is string *s*[1..*l*]. - The suffix of string *s* of length *l* (1<=≤<=*l*<=≤<=|*s*|) is string *s*[|*s*|<=-<=*l*<=+<=1..|*s*|]. Your task is, for any prefix of string *s* which matches a suffix of string *s*, print the number of times it occurs in string *s* as a substring.
The single line contains a sequence of characters *s*1*s*2...*s*|*s*| (1<=≤<=|*s*|<=≤<=105) — string *s*. The string only consists of uppercase English letters.
In the first line, print integer *k* (0<=≤<=*k*<=≤<=|*s*|) — the number of prefixes that match a suffix of string *s*. Next print *k* lines, in each line print two integers *l**i* *c**i*. Numbers *l**i* *c**i* mean that the prefix of the length *l**i* matches the suffix of length *l**i* and occurs in string *s* as a substring *c**i* times. Print pairs *l**i* *c**i* in the order of increasing *l**i*.
[ "ABACABA\n", "AAA\n" ]
[ "3\n1 4\n3 2\n7 1\n", "3\n1 3\n2 2\n3 1\n" ]
none
2,000
[ { "input": "ABACABA", "output": "3\n1 4\n3 2\n7 1" }, { "input": "AAA", "output": "3\n1 3\n2 2\n3 1" }, { "input": "A", "output": "1\n1 1" }, { "input": "AAAAAAAAAAAAAAAAXAAAAAAAAAAAAAAAAAAAAAAA", "output": "17\n1 39\n2 37\n3 35\n4 33\n5 31\n6 29\n7 27\n8 25\n9 23\n10 21\n11 19\n12 17\n13 15\n14 13\n15 11\n16 9\n40 1" }, { "input": "AB", "output": "1\n2 1" }, { "input": "AXAXA", "output": "3\n1 3\n3 2\n5 1" }, { "input": "CODEFORCES", "output": "1\n10 1" }, { "input": "GERALDPAVELGERALDPAVEL", "output": "2\n11 2\n22 1" }, { "input": "ZZ", "output": "2\n1 2\n2 1" } ]
1,692,412,537
2,147,483,647
PyPy 3-64
OK
TESTS
30
389
64,204,800
from sys import stdin from collections import defaultdict,Counter def line(): return stdin.readline().strip() def rd(converter): return converter(line()) def rl(converter, delimeter = None): return list(map(converter, line().split(delimeter))) def rls(num_lines, converter): return [rd(converter) for i in range(num_lines)] def rg(num_lines, converter, delimeter = None): return [rl(converter,delimeter) for i in range(num_lines)] MULTIPLE_CASES = 0 def prefix_function(s): prefix_function_vals = [0]*len(s) for i in range(1,len(s)): prefix_len = prefix_function_vals[i-1] while prefix_len > 0 and s[i] != s[prefix_len]: prefix_len = prefix_function_vals[prefix_len-1] prefix_function_vals[i] = prefix_len + (s[i] == s[prefix_len]) return [None]+prefix_function_vals def main(): s = rd(str) prefix_function_vals = prefix_function(s) prefix_function_val_counts = Counter(prefix_function_vals) neighbors = defaultdict(list) for i,prefix_function_val in enumerate(prefix_function_vals): neighbors[prefix_function_val].append(i) subtree_prefix_function_val_counts = {} dfs = [0] seen = set() while dfs: node = dfs[-1] if node not in seen: seen.add(node) for neighbor in neighbors[node]: dfs.append(neighbor) else: dfs.pop() subtree_prefix_function_val_counts[node] = prefix_function_val_counts[node] + sum(map(subtree_prefix_function_val_counts.__getitem__,neighbors[node])) ans = [] cur_length = prefix_function_vals[len(s)] while cur_length != 0: ans.append([cur_length,subtree_prefix_function_val_counts[cur_length]+1]) cur_length = prefix_function_vals[cur_length] print(len(ans)+1) for l,c in reversed(ans): print(l,c) print(len(s),1) for i in range(rd(int) if MULTIPLE_CASES else 1): main()
Title: Prefixes and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a string *s*<==<=*s*1*s*2...*s*|*s*|, where |*s*| is the length of string *s*, and *s**i* its *i*-th character. Let's introduce several definitions: - A substring *s*[*i*..*j*] (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|) of string *s* is string *s**i**s**i*<=+<=1...*s**j*. - The prefix of string *s* of length *l* (1<=≤<=*l*<=≤<=|*s*|) is string *s*[1..*l*]. - The suffix of string *s* of length *l* (1<=≤<=*l*<=≤<=|*s*|) is string *s*[|*s*|<=-<=*l*<=+<=1..|*s*|]. Your task is, for any prefix of string *s* which matches a suffix of string *s*, print the number of times it occurs in string *s* as a substring. Input Specification: The single line contains a sequence of characters *s*1*s*2...*s*|*s*| (1<=≤<=|*s*|<=≤<=105) — string *s*. The string only consists of uppercase English letters. Output Specification: In the first line, print integer *k* (0<=≤<=*k*<=≤<=|*s*|) — the number of prefixes that match a suffix of string *s*. Next print *k* lines, in each line print two integers *l**i* *c**i*. Numbers *l**i* *c**i* mean that the prefix of the length *l**i* matches the suffix of length *l**i* and occurs in string *s* as a substring *c**i* times. Print pairs *l**i* *c**i* in the order of increasing *l**i*. Demo Input: ['ABACABA\n', 'AAA\n'] Demo Output: ['3\n1 4\n3 2\n7 1\n', '3\n1 3\n2 2\n3 1\n'] Note: none
```python from sys import stdin from collections import defaultdict,Counter def line(): return stdin.readline().strip() def rd(converter): return converter(line()) def rl(converter, delimeter = None): return list(map(converter, line().split(delimeter))) def rls(num_lines, converter): return [rd(converter) for i in range(num_lines)] def rg(num_lines, converter, delimeter = None): return [rl(converter,delimeter) for i in range(num_lines)] MULTIPLE_CASES = 0 def prefix_function(s): prefix_function_vals = [0]*len(s) for i in range(1,len(s)): prefix_len = prefix_function_vals[i-1] while prefix_len > 0 and s[i] != s[prefix_len]: prefix_len = prefix_function_vals[prefix_len-1] prefix_function_vals[i] = prefix_len + (s[i] == s[prefix_len]) return [None]+prefix_function_vals def main(): s = rd(str) prefix_function_vals = prefix_function(s) prefix_function_val_counts = Counter(prefix_function_vals) neighbors = defaultdict(list) for i,prefix_function_val in enumerate(prefix_function_vals): neighbors[prefix_function_val].append(i) subtree_prefix_function_val_counts = {} dfs = [0] seen = set() while dfs: node = dfs[-1] if node not in seen: seen.add(node) for neighbor in neighbors[node]: dfs.append(neighbor) else: dfs.pop() subtree_prefix_function_val_counts[node] = prefix_function_val_counts[node] + sum(map(subtree_prefix_function_val_counts.__getitem__,neighbors[node])) ans = [] cur_length = prefix_function_vals[len(s)] while cur_length != 0: ans.append([cur_length,subtree_prefix_function_val_counts[cur_length]+1]) cur_length = prefix_function_vals[cur_length] print(len(ans)+1) for l,c in reversed(ans): print(l,c) print(len(s),1) for i in range(rd(int) if MULTIPLE_CASES else 1): main() ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. 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,690,545,539
2,147,483,647
PyPy 3-64
OK
TESTS
40
154
0
s = str(input()) t = str(input()) w = len(s) y = ''.join(reversed(s)) flag = True for i in range(w): if t[i] != y[i]: flag = False break if flag: 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 s = str(input()) t = str(input()) w = len(s) y = ''.join(reversed(s)) flag = True for i in range(w): if t[i] != y[i]: flag = False break if flag: print("YES") else: print("NO") ```
3.9615
321
A
Ciel and Robot
PROGRAMMING
1,700
[ "binary search", "implementation", "math" ]
null
null
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string *s*. Each character of *s* is one move operation. There are four move operations at all: - 'U': go up, (x, y) <=→<= (x, y+1); - 'D': go down, (x, y) <=→<= (x, y-1); - 'L': go left, (x, y) <=→<= (x-1, y); - 'R': go right, (x, y) <=→<= (x+1, y). The robot will do the operations in *s* from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (*a*,<=*b*).
The first line contains two integers *a* and *b*, (<=-<=109<=≤<=*a*,<=*b*<=≤<=109). The second line contains a string *s* (1<=≤<=|*s*|<=≤<=100, *s* only contains characters 'U', 'D', 'L', 'R') — the command.
Print "Yes" if the robot will be located at (*a*,<=*b*), and "No" otherwise.
[ "2 2\nRU\n", "1 2\nRU\n", "-1 1000000000\nLRRLU\n", "0 0\nD\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n" ]
In the first and second test case, command string is "RU", so the robot will go right, then go up, then right, and then up and so on. The locations of its moves are (0, 0)  →  (1, 0)  →  (1, 1)  →  (2, 1)  →  (2, 2)  →  ... So it can reach (2, 2) but not (1, 2).
500
[ { "input": "2 2\nRU", "output": "Yes" }, { "input": "1 2\nRU", "output": "No" }, { "input": "-1 1000000000\nLRRLU", "output": "Yes" }, { "input": "0 0\nD", "output": "Yes" }, { "input": "0 0\nUURRDL", "output": "Yes" }, { "input": "987654321 987654321\nUURRDL", "output": "Yes" }, { "input": "4 2\nUURRDL", "output": "No" }, { "input": "4 3\nUURRDL", "output": "Yes" }, { "input": "4 4\nUURRDL", "output": "Yes" }, { "input": "4 6\nUURRDL", "output": "Yes" }, { "input": "4 7\nUURRDL", "output": "No" }, { "input": "1000000000 1000000000\nUURRDL", "output": "Yes" }, { "input": "-1 -1\nUR", "output": "No" }, { "input": "1 1\nUURRDDLL", "output": "No" }, { "input": "987654321 2\nUURDD", "output": "Yes" }, { "input": "0 123456789\nRRULL", "output": "Yes" }, { "input": "4 4\nUUUURRRRDDDDLLLL", "output": "Yes" }, { "input": "-491226083 -49122610\nUDRLDURLDLLLDUDURLRDUUDDUUULUDRDRDUULURDRLLDDDLUDUURLUUDLLDULLLLDDLDDUU", "output": "Yes" }, { "input": "-261597957 418556728\nLLLDLUDUULLRDDULLRRUDRDLULRLRLLRRUUDRRLRUDLRRLUDRDLLUUDUULRURLDLULUUULDDUURLRUDURRL", "output": "Yes" }, { "input": "-771928144 -3\nRUDULULDRDLLLULDDUDDDDUDULRULRUULDDDURUDLUURULLLDLLDDRDDRLRURUULRUURRUDLDLDDRLLULRRDRRLLUULUDRUUDRRD", "output": "Yes" }, { "input": "397346346 1\nDDURRUURLDLRRLULD", "output": "Yes" }, { "input": "-528551525 0\nUDRLRRLDLDLURRRRULDLRLRLURUUDDLRLLDRRULLUDLURDLUUULLLRUUUDRRURLDUDULDDRDDDRDL", "output": "Yes" }, { "input": "311692421 -129871846\nLLLDURULDDDDUDDURRLUUDRLDDRDURDDRUDUURLUDUDLDRUDDDUUURDRRUDRDRDURLLDURUUDRLDLDURRRRRRDULURDRU", "output": "Yes" }, { "input": "485940814 728911221\nURURU", "output": "Yes" }, { "input": "-843450986 632588242\nLURLULULRUDUDULRDDLUL", "output": "Yes" }, { "input": "647999516 -809999401\nUDLDDLLULUDDLLDUULRRRDLUDDLDDLRLRRDRURURDRRDRULUDRDULRULLRRLLDDRLRRUDRURDUULUDLRRLRDR", "output": "Yes" }, { "input": "352820537 -764444491\nRDDUDLUDDUDLRRRDRRRDRRDUDUDDURLRRLDRLLRLLLLUULUDRURRDRLDDLLDRDURDUDRUDDLUDRLURUDRURDRDDLDRLDLDLLU", "output": "Yes" }, { "input": "-284973644 -1\nDLULLDLRUUDRR", "output": "Yes" }, { "input": "356922591 -2\nRRLDLDUDRUUUULUUDDULDDUDD", "output": "No" }, { "input": "27033101 54066203\nUDDDRDLLLRUUDDLRDLDRLRUDDULRLLRULR", "output": "No" }, { "input": "-199335150 39867031\nLLURRDUULRUDDRDUUULDLDRDDLURDRLDRLLLRRRRRULRRRUUDD", "output": "No" }, { "input": "609504072 609504074\nULRLUDLDDR", "output": "No" }, { "input": "497684357 829473929\nRRLDUUURULURRLLRRLRLURRLDU", "output": "Yes" }, { "input": "551922835 183974295\nDUDUUULDRLRURRDULRRUDDLRLLUULLRLRDRDRR", "output": "No" }, { "input": "825368095 -825368096\nRD", "output": "No" }, { "input": "-458990423 -229495204\nDLLDDRLUDLRLUL", "output": "No" }, { "input": "285102789 570205594\nRRDULRULULRRDUURRLURUDDULLRDUL", "output": "No" }, { "input": "109928480 219856920\nLRURLRLURDRDLDRDLRDDUUDDLULDRRUUURRUDLLUULUUUR", "output": "No" }, { "input": "-532674020 532674026\nUURLLL", "output": "No" }, { "input": "999999999 0\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "Yes" }, { "input": "0 0\nUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLR", "output": "Yes" }, { "input": "1 1\nUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLRUDLR", "output": "No" }, { "input": "-1000000000 -1000000000\nDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDLDL", "output": "Yes" }, { "input": "3 3\nUURR", "output": "No" }, { "input": "-2 -2\nUR", "output": "No" }, { "input": "5 5\nUDLR", "output": "No" }, { "input": "0 -1\nU", "output": "No" }, { "input": "-1 0\nR", "output": "No" }, { "input": "1000000000 1000000000\nURURURUR", "output": "Yes" }, { "input": "-1 -1\nRU", "output": "No" }, { "input": "1 1\nLD", "output": "No" }, { "input": "-2 -2\nUURR", "output": "No" }, { "input": "1000000000 0\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "Yes" }, { "input": "2 6\nRUUUURLDDDL", "output": "Yes" }, { "input": "0 1\nLUUR", "output": "No" }, { "input": "1 1\nURDLDL", "output": "Yes" }, { "input": "-10 -10\nRU", "output": "No" }, { "input": "1000000000 1000000000\nRURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURURU", "output": "Yes" }, { "input": "-1000000000 -500000000\nURR", "output": "No" }, { "input": "-2 0\nULLLDDRRRR", "output": "Yes" }, { "input": "999999999 -999999999\nRRRRRRRRRRRRRRRRRRRRRRRRRDDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLUUUUUUUUUUUUUUUUUUUUUUU", "output": "Yes" }, { "input": "-100 -100\nRU", "output": "No" }, { "input": "100 100\nRUL", "output": "No" }, { "input": "0 1\nUDLR", "output": "Yes" }, { "input": "0 1\nD", "output": "No" }, { "input": "0 -3\nRDDL", "output": "No" } ]
1,482,520,801
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
4,608,000
a,b=map(int,input().split()) ch=input() x=y=u=d=l=r=0 for z in ch: if z=='U': u=u+1 elif z=='D': d=d+1 elif z=='L': l=l+1 else: r=r+1 x=x+r-l y=y+u-d if ((x==a)and(y==b)): print('Yes') elif (y==b): if ((y/x)==((b-y)/(a-x))): print('Yes') else: print('No') elif(x==a): if((x/y)==((a-x)/(b-y))): print('No') else: print('No')
Title: Ciel and Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string *s*. Each character of *s* is one move operation. There are four move operations at all: - 'U': go up, (x, y) <=→<= (x, y+1); - 'D': go down, (x, y) <=→<= (x, y-1); - 'L': go left, (x, y) <=→<= (x-1, y); - 'R': go right, (x, y) <=→<= (x+1, y). The robot will do the operations in *s* from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (*a*,<=*b*). Input Specification: The first line contains two integers *a* and *b*, (<=-<=109<=≤<=*a*,<=*b*<=≤<=109). The second line contains a string *s* (1<=≤<=|*s*|<=≤<=100, *s* only contains characters 'U', 'D', 'L', 'R') — the command. Output Specification: Print "Yes" if the robot will be located at (*a*,<=*b*), and "No" otherwise. Demo Input: ['2 2\nRU\n', '1 2\nRU\n', '-1 1000000000\nLRRLU\n', '0 0\nD\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'Yes\n'] Note: In the first and second test case, command string is "RU", so the robot will go right, then go up, then right, and then up and so on. The locations of its moves are (0, 0)  →  (1, 0)  →  (1, 1)  →  (2, 1)  →  (2, 2)  →  ... So it can reach (2, 2) but not (1, 2).
```python a,b=map(int,input().split()) ch=input() x=y=u=d=l=r=0 for z in ch: if z=='U': u=u+1 elif z=='D': d=d+1 elif z=='L': l=l+1 else: r=r+1 x=x+r-l y=y+u-d if ((x==a)and(y==b)): print('Yes') elif (y==b): if ((y/x)==((b-y)/(a-x))): print('Yes') else: print('No') elif(x==a): if((x/y)==((a-x)/(b-y))): print('No') else: print('No') ```
0
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26", "output": "14" }, { "input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26", "output": "12" }, { "input": "a\n3", "output": "impossible" }, { "input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1", "output": "0" }, { "input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4", "output": "1" }, { "input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20", "output": "18" }, { "input": "swmkwaruyv\n5", "output": "0" }, { "input": "tnbqpsuhkczmejirvyfdolxwga\n22", "output": "0" }, { "input": "abcde\n3", "output": "0" }, { "input": "abb\n1", "output": "0" }, { "input": "aaaa\n1", "output": "0" }, { "input": "abcde\n2", "output": "0" }, { "input": "yandex\n4", "output": "0" }, { "input": "aaabbbccc\n1", "output": "0" }, { "input": "abcd\n2", "output": "0" }, { "input": "asdfgh\n2", "output": "0" }, { "input": "aab\n1", "output": "0" }, { "input": "mynameissako\n5", "output": "0" }, { "input": "abcde\n1", "output": "0" }, { "input": "abcd\n3", "output": "0" }, { "input": "abcdef\n2", "output": "0" }, { "input": "abcdefg\n4", "output": "0" }, { "input": "abc\n1", "output": "0" }, { "input": "asdafjsgljdllgjdgkl\n5", "output": "0" }, { "input": "yaay\n3", "output": "1" }, { "input": "yaay\n4", "output": "2" }, { "input": "zzzzzz\n2", "output": "1" } ]
1,626,774,601
2,147,483,647
PyPy 3
OK
TESTS
41
93
20,172,800
s=input() n=int(input()) if(n<=len(s)): print(max(0,n-len(set(s)))) else: print('impossible')
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input Specification: First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). Output Specification: Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. Demo Input: ['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n'] Demo Output: ['0\n', '1\n', 'impossible\n'] Note: In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
```python s=input() n=int(input()) if(n<=len(s)): print(max(0,n-len(set(s)))) else: print('impossible') ```
3
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 900", "output": "-1 -1" }, { "input": "1 9", "output": "9 9" }, { "input": "1 0", "output": "0 0" }, { "input": "1 1", "output": "1 1" }, { "input": "1 2", "output": "2 2" }, { "input": "1 8", "output": "8 8" }, { "input": "1 10", "output": "-1 -1" }, { "input": "1 11", "output": "-1 -1" }, { "input": "2 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "2 2", "output": "11 20" }, { "input": "2 8", "output": "17 80" }, { "input": "2 10", "output": "19 91" }, { "input": "2 11", "output": "29 92" }, { "input": "2 16", "output": "79 97" }, { "input": "2 17", "output": "89 98" }, { "input": "2 18", "output": "99 99" }, { "input": "2 19", "output": "-1 -1" }, { "input": "2 20", "output": "-1 -1" }, { "input": "2 900", "output": "-1 -1" }, { "input": "3 1", "output": "100 100" }, { "input": "3 2", "output": "101 200" }, { "input": "3 3", "output": "102 300" }, { "input": "3 9", "output": "108 900" }, { "input": "3 10", "output": "109 910" }, { "input": "3 20", "output": "299 992" }, { "input": "3 21", "output": "399 993" }, { "input": "3 26", "output": "899 998" }, { "input": "3 27", "output": "999 999" }, { "input": "3 28", "output": "-1 -1" }, { "input": "3 100", "output": "-1 -1" }, { "input": "100 0", "output": "-1 -1" }, { "input": "100 1", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 2", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 9", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 10", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 11", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 296", "output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 297", "output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 298", "output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 299", "output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 300", "output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 301", "output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 895", "output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994" }, { "input": "100 896", "output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995" }, { "input": "100 897", "output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996" }, { "input": "100 898", "output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997" }, { "input": "100 899", "output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998" }, { "input": "100 900", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "99 900", "output": "-1 -1" }, { "input": "99 891", "output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "99 892", "output": "-1 -1" }, { "input": "96 364", "output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000" }, { "input": "97 206", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "98 250", "output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "99 96", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 215", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "5 18", "output": "10089 99000" }, { "input": "2 19", "output": "-1 -1" }, { "input": "3 3", "output": "102 300" } ]
1,679,003,633
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
m, s = map(int, input().split()) # m -- len, s -- sum of digits def maxx(m, s): if s <= 0 or s > 9 * m: return -1 new_num = '' for i in range(m): if s > 0: if s > 9: new_num += '9' s -= 9 else: new_num += str(s) s = 0 else: new_num += '0' return new_num def minn(m, s): if s <= 0 or s > 9 * m: return -1 digits = [1] + [0] * (m - 1) remaining_sum = s - 1 for i in range(m - 1, -1, -1): digit_sum = min(9, remaining_sum) digits[i] += digit_sum print(digits[i]) remaining_sum -= digit_sum if remaining_sum == 0: break return ''.join(map(str, digits)) print(minn(m, s), maxx(m, s))
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. Input Specification: The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. Output Specification: In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). Demo Input: ['2 15\n', '3 0\n'] Demo Output: ['69 96\n', '-1 -1\n'] Note: none
```python m, s = map(int, input().split()) # m -- len, s -- sum of digits def maxx(m, s): if s <= 0 or s > 9 * m: return -1 new_num = '' for i in range(m): if s > 0: if s > 9: new_num += '9' s -= 9 else: new_num += str(s) s = 0 else: new_num += '0' return new_num def minn(m, s): if s <= 0 or s > 9 * m: return -1 digits = [1] + [0] * (m - 1) remaining_sum = s - 1 for i in range(m - 1, -1, -1): digit_sum = min(9, remaining_sum) digits[i] += digit_sum print(digits[i]) remaining_sum -= digit_sum if remaining_sum == 0: break return ''.join(map(str, digits)) print(minn(m, s), maxx(m, s)) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,689,010,574
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
w = input() length = len(w) arr = list(w) if length < 10: print(length) else: print(arr[0] + str(length - 2) + arr[length - 1])
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python w = input() length = len(w) arr = list(w) if length < 10: print(length) else: print(arr[0] + str(length - 2) + arr[length - 1]) ```
0
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "output": "12" }, { "input": "25\ntcqpchnqskqjacruoaqilgebu", "output": "7" }, { "input": "13\naebaecedabbee", "output": "8" }, { "input": "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "10\nbababbdaee", "output": "6" }, { "input": "11\ndbadcdbdbca", "output": "7" }, { "input": "12\nacceaabddaaa", "output": "7" }, { "input": "13\nabddfbfaeecfa", "output": "7" }, { "input": "14\neeceecacdbcbbb", "output": "9" }, { "input": "15\ndcbceaaggabaheb", "output": "8" }, { "input": "16\nhgiegfbadgcicbhd", "output": "7" }, { "input": "17\nabhfibbdddfghgfdi", "output": "10" }, { "input": "26\nbbbbbabbaababaaabaaababbaa", "output": "24" }, { "input": "26\nahnxdnbfbcrirerssyzydihuee", "output": "11" }, { "input": "26\nhwqeqhkpxwulbsiwmnlfyhgknc", "output": "8" }, { "input": "26\nrvxmulriorilidecqwmfaemifj", "output": "10" }, { "input": "26\naowpmreooavnmamogdoopuisge", "output": "12" }, { "input": "26\ninimevtuefhvuefirdehmmfudh", "output": "15" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "27\nqdcfjtblgglnilgassirrjekcjt", "output": "-1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyza", "output": "-1" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "0" }, { "input": "5\nzzzzz", "output": "4" }, { "input": "27\naaaaaaaaaaaaaaaaabaaaaaaaaa", "output": "-1" }, { "input": "1\nq", "output": "0" }, { "input": "27\nqwertyuioplkjhgfdsazxcvbnmm", "output": "-1" }, { "input": "9\nxxxyyyzzz", "output": "6" }, { "input": "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk", "output": "-1" }, { "input": "27\nqwertyuiopasdfghjklzxcvbnmm", "output": "-1" }, { "input": "26\nabcdefghijklmnopqrstuvwxyz", "output": "0" }, { "input": "26\nabcdefghijklmnopqrstuvwxya", "output": "1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyzz", "output": "-1" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "26\nqwertyuioplkjhgfdsazxcvbnm", "output": "0" }, { "input": "10\nzzzzzzzzzz", "output": "9" }, { "input": "1\na", "output": "0" }, { "input": "30\nabcdefghtyabcdefghtyabcdefghty", "output": "-1" } ]
1,679,149,201
2,147,483,647
PyPy 3
OK
TESTS
47
93
2,764,800
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) s = list(input().rstrip()) cnt = [0] * 26 for i in s: cnt[i - 97] += 1 ans = 0 for i in cnt: ans += max(i - 1, 0) if n > 26: ans = -1 print(ans)
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters. Output Specification: If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. Demo Input: ['2\naa\n', '4\nkoko\n', '5\nmurat\n'] Demo Output: ['1\n', '2\n', '0\n'] Note: In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) s = list(input().rstrip()) cnt = [0] * 26 for i in s: cnt[i - 97] += 1 ans = 0 for i in cnt: ans += max(i - 1, 0) if n > 26: ans = -1 print(ans) ```
3
49
A
Sleuth
PROGRAMMING
800
[ "implementation" ]
A. Sleuth
2
256
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that. Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them. The English alphabet vowels are: A, E, I, O, U, Y The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z
The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.
Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.
[ "Is it a melon?\n", "Is it an apple?\n", "Is it a banana ?\n", "Is it an apple and a banana simultaneouSLY?\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n" ]
none
500
[ { "input": "Is it a melon?", "output": "NO" }, { "input": "Is it an apple?", "output": "YES" }, { "input": " Is it a banana ?", "output": "YES" }, { "input": "Is it an apple and a banana simultaneouSLY?", "output": "YES" }, { "input": "oHtSbDwzHb?", "output": "NO" }, { "input": "sZecYdUvZHrXx?", "output": "NO" }, { "input": "uMtXK?", "output": "NO" }, { "input": "U?", "output": "YES" }, { "input": "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?", "output": "NO" }, { "input": "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlxUJHqCUzzCmcAvMiKL NunwOXnKeIxUZmBVwiCUfPkjRAkTPbkYCmwRRnDSLaz?", "output": "NO" }, { "input": "gxzXbdcAQMuFKuuiPohtMgeypr wpDIoDSyOYTdvylcg SoEBZjnMHHYZGEqKgCgBeTbyTwyGuPZxkxsnSczotBdYyfcQsOVDVC?", "output": "NO" }, { "input": "FQXBisXaJFMiHFQlXjixBDMaQuIbyqSBKGsBfTmBKCjszlGVZxEOqYYqRTUkGpSDDAoOXyXcQbHcPaegeOUBNeSD JiKOdECPOF?", "output": "NO" }, { "input": "YhCuZnrWUBEed?", "output": "NO" }, { "input": "hh?", "output": "NO" }, { "input": "whU?", "output": "YES" }, { "input": "fgwg?", "output": "NO" }, { "input": "GlEmEPKrYcOnBNJUIFjszWUyVdvWw DGDjoCMtRJUburkPToCyDrOtMr?", "output": "NO" }, { "input": "n?", "output": "NO" }, { "input": "BueDOlxgzeNlxrzRrMbKiQdmGujEKmGxclvaPpTuHmTqBp?", "output": "NO" }, { "input": "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?", "output": "NO" }, { "input": " J ?", "output": "NO" }, { "input": " j ?", "output": "NO" }, { "input": " o ?", "output": "YES" }, { "input": " T ?", "output": "NO" }, { "input": " q ?", "output": "NO" }, { "input": " j ?", "output": "NO" }, { "input": " c ?", "output": "NO" }, { "input": " B ?", "output": "NO" }, { "input": "LuhxDHVwMPTtUIUMIQTuQETgXCOQPsfdFlyHvpfOVedjUTpGLAZGOHloIjJJtOLAlHPivzA?", "output": "YES" }, { "input": "wmztmzFfwbGyOmNHENUFMTsFEMWYA?", "output": "YES" }, { "input": "wGsfZCSwN PEUhNUrLfABrxA?", "output": "YES" }, { "input": "mCDHENXjYbgMdBimAdPnewaHfpGWowjWrVAdvWczjw iDcUbyzMsmsnwbviiKiAyGVA?", "output": "YES" }, { "input": "ARIWnwqFqxsQXsXXzHqvFjxOCttAGPUzDtWzsenPYdNXuFOIUGYZsLLK IaoxiyjBBRThoelwdPTkuCQfcBLUEJpCPIrVZlvUWA?", "output": "YES" }, { "input": " PslvVpgpN BXkMFBEVXsyZFIQbBEFxGkYTeXKrOdcmhbiTUatYRUoYAayrchqbksswIlfIjerZPqptvCGnMUhyrQSvwltRhFzA?", "output": "YES" }, { "input": "HpBkttwSjBXDmyleGiRWNUMPaAIE uzTrp KJDzaUiCdsMYOoWKHoUhWUoecCPmACymMUUbGav UMRpCytPETwNFAObZJA?", "output": "YES" } ]
1,605,784,031
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
0
t = int(input()) string = input() for j in range(1,t): for i in string[ : :-1]: if(i=='?' or i=='.'): continue elif(i=='a' or i=='e'or i=='i'or i=='o'or i=='u' or i=='A'or i=='E'or i=='I'or i=='O'or i=='U'): print("YES") else: print("NO")
Title: Sleuth Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that. Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them. The English alphabet vowels are: A, E, I, O, U, Y The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z Input Specification: The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. Output Specification: Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. Demo Input: ['Is it a melon?\n', 'Is it an apple?\n', 'Is it a banana ?\n', 'Is it an apple and a banana simultaneouSLY?\n'] Demo Output: ['NO\n', 'YES\n', 'YES\n', 'YES\n'] Note: none
```python t = int(input()) string = input() for j in range(1,t): for i in string[ : :-1]: if(i=='?' or i=='.'): continue elif(i=='a' or i=='e'or i=='i'or i=='o'or i=='u' or i=='A'or i=='E'or i=='I'or i=='O'or i=='U'): print("YES") else: print("NO") ```
-1
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
1,691,254,480
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
w = input() if w%2 or w==2: #odd print('NO') else: print('YES')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python w = input() if w%2 or w==2: #odd print('NO') else: print('YES') ```
-1
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1 900", "output": "-1 -1" }, { "input": "1 9", "output": "9 9" }, { "input": "1 0", "output": "0 0" }, { "input": "1 1", "output": "1 1" }, { "input": "1 2", "output": "2 2" }, { "input": "1 8", "output": "8 8" }, { "input": "1 10", "output": "-1 -1" }, { "input": "1 11", "output": "-1 -1" }, { "input": "2 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "2 2", "output": "11 20" }, { "input": "2 8", "output": "17 80" }, { "input": "2 10", "output": "19 91" }, { "input": "2 11", "output": "29 92" }, { "input": "2 16", "output": "79 97" }, { "input": "2 17", "output": "89 98" }, { "input": "2 18", "output": "99 99" }, { "input": "2 19", "output": "-1 -1" }, { "input": "2 20", "output": "-1 -1" }, { "input": "2 900", "output": "-1 -1" }, { "input": "3 1", "output": "100 100" }, { "input": "3 2", "output": "101 200" }, { "input": "3 3", "output": "102 300" }, { "input": "3 9", "output": "108 900" }, { "input": "3 10", "output": "109 910" }, { "input": "3 20", "output": "299 992" }, { "input": "3 21", "output": "399 993" }, { "input": "3 26", "output": "899 998" }, { "input": "3 27", "output": "999 999" }, { "input": "3 28", "output": "-1 -1" }, { "input": "3 100", "output": "-1 -1" }, { "input": "100 0", "output": "-1 -1" }, { "input": "100 1", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 2", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 9", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 10", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 11", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 296", "output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 297", "output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 298", "output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 299", "output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 300", "output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 301", "output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 895", "output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994" }, { "input": "100 896", "output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995" }, { "input": "100 897", "output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996" }, { "input": "100 898", "output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997" }, { "input": "100 899", "output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998" }, { "input": "100 900", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "99 900", "output": "-1 -1" }, { "input": "99 891", "output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "99 892", "output": "-1 -1" }, { "input": "96 364", "output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000" }, { "input": "97 206", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "98 250", "output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "99 96", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100 215", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "5 18", "output": "10089 99000" }, { "input": "2 19", "output": "-1 -1" }, { "input": "3 3", "output": "102 300" } ]
1,696,099,535
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin def can(m, s): return s > 0 and s < 9*m def mirror(num): str_val = str(num) return str_val+' '+str_val[::-1] m, s = [int(i) for i in stream.readline().split()] base = int('1'*m) s -= m answer = mirror(int(str(s%8)+'8'*int(s/8))+base) if can(m,s) else '-1 -1' print(answer)
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. Input Specification: The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. Output Specification: In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). Demo Input: ['2 15\n', '3 0\n'] Demo Output: ['69 96\n', '-1 -1\n'] Note: none
```python from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin def can(m, s): return s > 0 and s < 9*m def mirror(num): str_val = str(num) return str_val+' '+str_val[::-1] m, s = [int(i) for i in stream.readline().split()] base = int('1'*m) s -= m answer = mirror(int(str(s%8)+'8'*int(s/8))+base) if can(m,s) else '-1 -1' print(answer) ```
0
204
B
Little Elephant and Cards
PROGRAMMING
1,500
[ "binary search", "data structures" ]
null
null
The Little Elephant loves to play with color cards. He has *n* cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of *n* cards funny.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of the cards. The following *n* lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces.
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
[ "3\n4 7\n4 7\n7 4\n", "5\n4 7\n7 4\n2 11\n9 7\n1 1\n" ]
[ "0\n", "2\n" ]
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
500
[ { "input": "3\n4 7\n4 7\n7 4", "output": "0" }, { "input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2" }, { "input": "1\n1 1", "output": "0" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8", "output": "-1" }, { "input": "2\n1 2\n2 1", "output": "0" }, { "input": "3\n7 7\n1 2\n2 1", "output": "1" }, { "input": "3\n1 1\n2 5\n3 6", "output": "-1" }, { "input": "4\n1000000000 1000000000\n999999999 1000000000\n999999997 999999998\n47 74", "output": "1" }, { "input": "6\n1 2\n3 1\n4 7\n4 1\n9 1\n7 2", "output": "2" }, { "input": "4\n1 2\n1 2\n2 1\n2 1", "output": "0" }, { "input": "7\n4 7\n7 4\n4 7\n1 1\n2 2\n3 3\n4 4", "output": "1" }, { "input": "10\n1000000000 999999999\n47 74\n47474 75785445\n8798878 458445\n1 2\n888888888 777777777\n99999999 1000000000\n9999999 1000000000\n999999 1000000000\n99999 1000000000", "output": "4" }, { "input": "10\n9 1000000000\n47 74\n47474 75785445\n8798878 458445\n1 2\n888888888 777777777\n99999999 1000000000\n9999999 1000000000\n999999 1000000000\n99999 1000000000", "output": "5" }, { "input": "10\n1 10\n1 10\n1 1\n7 8\n6 7\n9 5\n4 1\n2 3\n3 10\n2 8", "output": "-1" }, { "input": "10\n262253762 715261903\n414831157 8354405\n419984358 829693421\n376600467 175941985\n367533995 350629286\n681027822 408529849\n654503328 717740407\n539773033 704670473\n55322828 380422378\n46174018 186723478", "output": "-1" }, { "input": "10\n2 2\n1 1\n1 1\n1 2\n1 2\n2 2\n2 1\n1 1\n1 2\n1 1", "output": "0" }, { "input": "12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "0" }, { "input": "47\n53 63\n43 57\n69 52\n66 47\n74 5\n5 2\n6 56\n19 27\n46 27\n31 45\n41 38\n20 20\n69 43\n17 74\n39 43\n28 70\n73 24\n73 59\n23 11\n56 49\n51 37\n70 16\n66 36\n4 7\n1 49\n7 65\n38 5\n47 74\n34 38\n17 22\n59 3\n70 40\n21 15\n10 5\n17 30\n9 12\n28 48\n70 42\n39 70\n18 53\n71 49\n66 25\n37 51\n10 62\n55 7\n18 53\n40 50", "output": "-1" }, { "input": "100\n1 2\n2 1\n2 1\n1 2\n1 1\n1 2\n2 1\n1 1\n2 2\n2 1\n2 1\n1 1\n1 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 1\n2 1\n1 1\n1 1\n2 2\n1 2\n1 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n2 2\n1 1\n2 1\n1 2\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2\n2 1\n1 1\n1 2\n1 1\n1 1\n2 2\n2 2\n2 1\n2 1\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n1 2\n2 2\n2 1\n2 1\n2 2\n1 1\n1 1\n2 1\n2 1\n2 1\n2 2\n2 2\n2 1\n1 1\n1 2\n2 1\n2 2\n2 1\n1 1\n2 1\n2 1\n1 1\n1 2\n1 2\n2 1\n2 1\n2 1\n2 2\n1 2\n1 2\n2 1\n1 1\n1 1\n1 2\n2 1\n1 2\n2 2\n1 2\n2 1\n2 2\n2 1", "output": "0" }, { "input": "7\n1 1\n1 1\n1 1\n2 3\n4 5\n6 7\n8 9", "output": "-1" }, { "input": "1\n1 2", "output": "0" }, { "input": "7\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999", "output": "0" }, { "input": "2\n1 2\n2 3", "output": "0" }, { "input": "2\n47 74\n47 85874", "output": "0" }, { "input": "5\n5 8\n9 10\n5 17\n5 24\n1 147", "output": "0" }, { "input": "5\n1 7\n2 7\n3 7\n4 7\n5 7", "output": "3" }, { "input": "5\n1 10\n2 10\n3 10\n4 10\n5 10", "output": "3" }, { "input": "3\n2 1\n3 1\n4 1", "output": "2" }, { "input": "5\n1 2\n1 3\n4 1\n5 1\n6 7", "output": "1" }, { "input": "5\n4 7\n4 7\n2 7\n9 7\n1 1", "output": "3" }, { "input": "8\n1 2\n2 1\n2 1\n3 1\n4 2\n5 2\n6 2\n7 2", "output": "2" }, { "input": "3\n98751 197502\n296253 395004\n493755 592506", "output": "-1" }, { "input": "5\n1 5\n2 5\n3 5\n4 7\n2 5", "output": "3" }, { "input": "10\n1 10\n2 10\n3 10\n4 10\n5 10\n10 1\n10 2\n10 3\n10 4\n10 5", "output": "0" }, { "input": "7\n1 2\n1 2\n1 2\n3 1\n3 1\n3 1\n2 1", "output": "1" }, { "input": "5\n1 6\n2 6\n3 6\n4 6\n5 6", "output": "3" }, { "input": "5\n1 6\n2 6\n3 6\n4 4\n5 5", "output": "3" }, { "input": "5\n1 1\n1 1\n2 2\n2 2\n3 3", "output": "-1" }, { "input": "4\n1 5\n2 5\n3 5\n4 4", "output": "2" } ]
1,606,311,103
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
186
307,200
n=int(input()) m={} v=[] for i in range(n): a=input().split() v.append(a) m[a[0]]=[0,0] m[a[1]]=[0,0] for i in range(n): m[v[i][0]][0]+=1 m[v[i][1]][1]+=1 min=99999999 for i in m: if sum(m[i])>=(n+1)//2: if (n+1)//2-m[i][0]<min: if (n+1)//2-m[i][0]<=0: print(0) exit() else: min=(n+1)//2-m[i][0] print(min)
Title: Little Elephant and Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves to play with color cards. He has *n* cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of *n* cards funny. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of the cards. The following *n* lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output Specification: On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1. Demo Input: ['3\n4 7\n4 7\n7 4\n', '5\n4 7\n7 4\n2 11\n9 7\n1 1\n'] Demo Output: ['0\n', '2\n'] Note: In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
```python n=int(input()) m={} v=[] for i in range(n): a=input().split() v.append(a) m[a[0]]=[0,0] m[a[1]]=[0,0] for i in range(n): m[v[i][0]][0]+=1 m[v[i][1]][1]+=1 min=99999999 for i in m: if sum(m[i])>=(n+1)//2: if (n+1)//2-m[i][0]<min: if (n+1)//2-m[i][0]<=0: print(0) exit() else: min=(n+1)//2-m[i][0] print(min) ```
0
740
B
Alyona and flowers
PROGRAMMING
1,200
[ "constructive algorithms" ]
null
null
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in. For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then: - the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays. Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this! Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100). The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Each subarray can encounter more than once.
Print single integer — the maximum possible value added to the Alyona's happiness.
[ "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n", "4 3\n1 2 3 4\n1 3\n2 4\n1 1\n", "2 2\n-1 -2\n1 1\n1 2\n" ]
[ "7\n", "16\n", "0\n" ]
The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
1,000
[ { "input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "output": "7" }, { "input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "output": "16" }, { "input": "2 2\n-1 -2\n1 1\n1 2", "output": "0" }, { "input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5", "output": "8" }, { "input": "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3", "output": "10" }, { "input": "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8", "output": "0" }, { "input": "3 6\n0 0 0\n1 1\n1 1\n1 3\n3 3\n2 3\n1 2", "output": "0" }, { "input": "3 3\n1 -1 3\n1 2\n2 3\n1 3", "output": "5" }, { "input": "6 8\n0 6 -5 8 -3 -2\n6 6\n2 3\n5 6\n4 6\n3 4\n2 5\n3 3\n5 6", "output": "13" }, { "input": "10 4\n6 5 5 -1 0 5 0 -3 5 -4\n3 6\n4 9\n1 6\n1 4", "output": "50" }, { "input": "9 1\n-1 -1 -1 -1 2 -1 2 0 0\n2 5", "output": "0" }, { "input": "3 8\n3 4 4\n1 2\n1 3\n2 3\n1 2\n2 2\n1 1\n2 3\n1 3", "output": "59" }, { "input": "3 8\n6 7 -1\n1 1\n1 3\n2 2\n1 3\n1 3\n1 1\n2 3\n2 3", "output": "67" }, { "input": "53 7\n-43 57 92 97 85 -29 28 -8 -37 -47 51 -53 -95 -50 -39 -87 43 36 60 -95 93 8 67 -22 -78 -46 99 93 27 -72 -84 77 96 -47 1 -12 21 -98 -34 -88 57 -43 5 -15 20 -66 61 -29 30 -85 52 53 82\n15 26\n34 43\n37 41\n22 34\n19 43\n2 15\n13 35", "output": "170" }, { "input": "20 42\n61 86 5 -87 -33 51 -79 17 -3 65 -42 74 -94 40 -35 22 58 81 -75 5\n3 6\n12 13\n3 16\n3 16\n5 7\n5 16\n2 15\n6 18\n4 18\n10 17\n14 16\n4 15\n4 11\n13 20\n5 6\n5 15\n16 17\n3 14\n9 10\n5 19\n5 14\n2 4\n17 20\n10 11\n5 18\n10 11\n1 14\n1 6\n1 10\n8 16\n11 14\n12 20\n11 13\n4 5\n2 13\n1 5\n11 15\n1 18\n3 8\n8 20\n1 4\n10 13", "output": "1502" }, { "input": "64 19\n-47 13 19 51 -25 72 38 32 54 7 -49 -50 -59 73 45 -87 -15 -72 -32 -10 -7 47 -34 35 48 -73 79 25 -80 -34 4 77 60 30 61 -25 23 17 -73 -73 69 29 -50 -55 53 15 -33 7 -46 -5 85 -86 77 -51 87 -69 -64 -24 -64 29 -20 -58 11 -26\n6 53\n13 28\n15 47\n20 52\n12 22\n6 49\n31 54\n2 39\n32 49\n27 64\n22 63\n33 48\n49 58\n39 47\n6 29\n21 44\n24 59\n20 24\n39 54", "output": "804" }, { "input": "1 10\n-46\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "0" }, { "input": "10 7\n44 18 9 -22 -23 7 -25 -2 15 35\n6 8\n6 7\n3 3\n2 6\n9 10\n2 2\n1 5", "output": "103" }, { "input": "4 3\n10 -2 68 35\n4 4\n1 1\n1 3", "output": "121" }, { "input": "3 6\n27 -31 -81\n2 3\n2 3\n1 1\n1 2\n1 2\n2 2", "output": "27" }, { "input": "7 3\n-24 -12 16 -43 -30 31 16\n3 6\n3 4\n1 7", "output": "0" }, { "input": "10 7\n-33 -24 -86 -20 5 -91 38 -12 -90 -67\n7 8\n7 10\n4 7\n1 3\n6 10\n6 6\n3 5", "output": "26" }, { "input": "4 4\n95 35 96 -27\n3 4\n3 3\n4 4\n3 3", "output": "261" }, { "input": "7 7\n-33 26 -25 44 -20 -50 33\n4 6\n4 4\n3 7\n5 7\n1 4\n2 5\n4 6", "output": "81" }, { "input": "5 3\n-35 -39 93 59 -4\n2 2\n2 3\n2 5", "output": "163" }, { "input": "3 7\n0 0 0\n1 2\n1 2\n2 3\n3 3\n1 3\n1 2\n2 3", "output": "0" }, { "input": "8 2\n17 32 30 -6 -39 -15 33 74\n6 6\n8 8", "output": "74" }, { "input": "8 1\n-20 -15 21 -21 1 -12 -7 9\n4 7", "output": "0" }, { "input": "7 9\n-23 -4 -44 -47 -35 47 25\n1 6\n3 5\n4 7\n6 7\n2 4\n2 3\n2 7\n1 2\n5 5", "output": "72" }, { "input": "8 8\n0 6 -25 -15 29 -24 31 23\n2 8\n5 5\n3 3\n2 8\n6 6\n3 6\n3 4\n2 4", "output": "79" }, { "input": "4 3\n-39 -63 9 -16\n1 4\n1 3\n2 4", "output": "0" }, { "input": "9 1\n-3 -13 -13 -19 -4 -11 8 -11 -3\n9 9", "output": "0" }, { "input": "9 6\n25 18 -62 0 33 62 -23 4 -15\n7 9\n2 3\n1 4\n2 6\n1 6\n2 3", "output": "127" }, { "input": "4 5\n-12 39 8 -12\n1 4\n3 4\n1 3\n1 3\n2 3", "output": "140" }, { "input": "3 9\n-9 7 3\n1 2\n1 1\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n3 3", "output": "22" }, { "input": "10 7\n0 4 3 3 -2 -2 -4 -2 -3 -2\n5 6\n1 10\n2 10\n7 10\n1 1\n6 7\n3 4", "output": "6" }, { "input": "86 30\n16 -12 11 16 8 14 7 -29 18 30 -32 -10 20 29 -14 -21 23 -19 -15 17 -2 25 -22 2 26 15 -7 -12 -4 -28 21 -4 -2 22 28 -32 9 -20 23 38 -21 21 37 -13 -30 25 31 6 18 29 29 29 27 38 -15 -32 32 -7 -8 -33 -11 24 23 -19 -36 -36 -18 9 -1 32 -34 -26 1 -1 -16 -14 17 -17 15 -24 38 5 -27 -12 8 -38\n60 66\n29 48\n32 51\n38 77\n17 79\n23 74\n39 50\n14 29\n26 76\n9 76\n2 67\n23 48\n17 68\n33 75\n59 78\n46 78\n9 69\n16 83\n18 21\n17 34\n24 61\n15 79\n4 31\n62 63\n46 76\n79 82\n25 39\n5 81\n19 77\n26 71", "output": "3076" }, { "input": "33 17\n11 6 -19 14 23 -23 21 15 29 19 13 -18 -19 20 16 -10 26 -22 3 17 13 -10 19 22 -5 21 12 6 28 -13 -27 25 6\n4 17\n12 16\n9 17\n25 30\n31 32\n4 28\n11 24\n16 19\n3 27\n7 17\n1 16\n15 28\n30 33\n9 31\n14 30\n13 23\n27 27", "output": "1366" }, { "input": "16 44\n32 23 -27 -2 -10 -42 32 -14 -13 4 9 -2 19 35 16 22\n6 12\n8 11\n13 15\n12 12\n3 10\n9 13\n7 15\n2 11\n1 13\n5 6\n9 14\n3 16\n10 13\n3 15\n6 10\n14 16\n4 5\n7 10\n5 14\n1 16\n2 5\n1 6\n9 10\n4 7\n4 12\n2 5\n7 10\n7 9\n2 8\n9 10\n4 10\n7 12\n10 11\n6 6\n15 15\n8 12\n9 10\n3 3\n4 15\n10 12\n7 16\n4 14\n14 16\n5 6", "output": "777" }, { "input": "63 24\n-23 -46 0 33 24 13 39 -6 -4 49 19 -18 -11 -38 0 -3 -33 -17 -4 -44 -22 -12 -16 42 16 -10 7 37 -6 16 -41 -18 -20 51 -49 28 -14 -22 -37 -7 -50 31 -41 -47 18 -8 -39 -29 35 -32 14 -29 44 -29 -19 -25 -47 -8 16 11 20 12 38\n21 61\n35 61\n29 61\n21 34\n12 48\n32 33\n9 27\n4 42\n4 60\n37 61\n19 44\n46 60\n51 53\n31 34\n23 32\n5 29\n43 59\n7 31\n29 48\n15 50\n19 51\n7 28\n17 41\n1 62", "output": "82" }, { "input": "6 51\n45 -33 -17 -48 2 2\n2 5\n1 1\n1 3\n5 5\n4 6\n1 2\n2 3\n3 4\n1 6\n4 6\n3 5\n1 5\n2 2\n2 6\n4 6\n1 5\n1 5\n1 5\n1 6\n6 6\n3 5\n6 6\n1 6\n3 4\n3 3\n2 4\n3 3\n1 4\n2 4\n5 6\n4 5\n2 4\n1 5\n1 2\n4 5\n1 5\n5 6\n2 2\n3 4\n1 3\n1 2\n2 5\n3 6\n4 6\n3 4\n2 4\n1 4\n1 1\n4 6\n3 5\n1 4", "output": "140" }, { "input": "3 5\n2 -1 3\n2 3\n2 3\n2 3\n2 3\n1 2", "output": "9" }, { "input": "4 30\n1 1 1 1\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4", "output": "120" } ]
1,479,921,957
3,057
Python 3
OK
TESTS
53
62
0
n,m=map(int,input().split()) d=input().split() d=[int(x) for x in d] c=0 for i in range(m): l=input().split() l=[int(x) for x in l] k=0 for j in range(l[0]-1,l[1]): k+=d[j] if k>0: c+=k print(c)
Title: Alyona and flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in. For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then: - the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays. Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this! Alyona can choose any number of the subarrays, even 0 or all suggested by her mother. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100). The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Each subarray can encounter more than once. Output Specification: Print single integer — the maximum possible value added to the Alyona's happiness. Demo Input: ['5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n', '4 3\n1 2 3 4\n1 3\n2 4\n1 1\n', '2 2\n-1 -2\n1 1\n1 2\n'] Demo Output: ['7\n', '16\n', '0\n'] Note: The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
```python n,m=map(int,input().split()) d=input().split() d=[int(x) for x in d] c=0 for i in range(m): l=input().split() l=[int(x) for x in l] k=0 for j in range(l[0]-1,l[1]): k+=d[j] if k>0: c+=k print(c) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "10000220" }, { "input": ".", "output": "0" }, { "input": "-.", "output": "1" }, { "input": "--", "output": "2" }, { "input": "..", "output": "00" }, { "input": "--.", "output": "20" }, { "input": ".--.", "output": "020" }, { "input": ".-.-..", "output": "0110" }, { "input": "----.-.", "output": "2201" }, { "input": "-..--.-.", "output": "10201" }, { "input": "..--..--.", "output": "0020020" }, { "input": "-.-.---.--..-..-.-.-..-..-.--.", "output": "112120010111010120" }, { "input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.", "output": "21112220010101011012011011221011" }, { "input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------", "output": "11020111110111222212021020002022111100201121222020012022110010222" }, { "input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..", "output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110" }, { "input": ".-..-.-.---.-----.--.---...-.--.-.-....-..", "output": "01011212212021001201100010" }, { "input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..", "output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210" }, { "input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.", "output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220" }, { "input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----", "output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122" }, { "input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..", "output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110" }, { "input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.", "output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020" }, { "input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..", "output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200" }, { "input": "-.---...----...--.--...-.--.----", "output": "121002200020200012022" }, { "input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.", "output": "202020212012111010201021100001021221200011222112012201012220" } ]
1,682,973,783
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
60
0
s,i = input(), 0 while i < len(s): if s[i] == '.': print(0, end = '') i+=1 if s[i] == '-': if s[i+1] == '.': print(1, end = '') i += 2 else: print(2, end = '') i+=2
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python s,i = input(), 0 while i < len(s): if s[i] == '.': print(0, end = '') i+=1 if s[i] == '-': if s[i+1] == '.': print(1, end = '') i += 2 else: print(2, end = '') i+=2 ```
-1
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,691,606,894
2,147,483,647
Python 3
OK
TESTS
20
46
0
import math N, M, A = input().split() n = int(N) m = int(M) a = int(A) print(math.ceil(m/a)*math.ceil(n/a))
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 import math N, M, A = input().split() n = int(N) m = int(M) a = int(A) print(math.ceil(m/a)*math.ceil(n/a)) ```
3.977
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 6" }, { "input": "5\n1 1 1 1 1", "output": "0 10" }, { "input": "5\n2 2 2 2 2", "output": "0 10" }, { "input": "10\n2 2 2 2 2 2 2 2 2 2", "output": "0 45" }, { "input": "3\n2 2 2", "output": "0 3" }, { "input": "3\n3 3 3", "output": "0 3" }, { "input": "2\n10000000 100000000", "output": "90000000 1" }, { "input": "5\n5 5 5 5 5", "output": "0 10" }, { "input": "5\n3 3 3 3 3", "output": "0 10" }, { "input": "6\n1 1 1 1 1 1", "output": "0 15" }, { "input": "2\n5 6", "output": "1 1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "0 45" }, { "input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0 45" }, { "input": "4\n4 4 4 4", "output": "0 6" }, { "input": "7\n1 1 1 1 1 1 1", "output": "0 21" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "0 55" }, { "input": "8\n8 8 8 8 8 8 8 8", "output": "0 28" }, { "input": "2\n3 2", "output": "1 1" } ]
1,694,049,871
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
108
17,100,800
input() A=list(map(int, input().split())) m=min(A) n=max(A) k=n-m r=A.count(m)*A.count(n) print(str(k)+' '+str(r))
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). Output Specification: The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. Demo Input: ['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n'] Demo Output: ['1 1', '4 1', '2 4'] Note: In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
```python input() A=list(map(int, input().split())) m=min(A) n=max(A) k=n-m r=A.count(m)*A.count(n) print(str(k)+' '+str(r)) ```
0
549
A
Face Detection
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively. Next *n* lines define the image. Each line contains *m* lowercase Latin letters.
In the single line print the number of faces on the image.
[ "4 4\nxxxx\nxfax\nxcex\nxxxx\n", "4 2\nxx\ncf\nae\nxx\n", "2 3\nfac\ncef\n", "1 4\nface\n" ]
[ "1\n", "1\n", "2\n", "0\n" ]
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: In the fourth sample the image has no faces on it.
250
[ { "input": "4 4\nxxxx\nxfax\nxcex\nxxxx", "output": "1" }, { "input": "4 2\nxx\ncf\nae\nxx", "output": "1" }, { "input": "2 3\nfac\ncef", "output": "2" }, { "input": "1 4\nface", "output": "0" }, { "input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx", "output": "0" }, { "input": "5 5\nkjxbw\neacra\nxefhx\nucmcz\npgtjk", "output": "1" }, { "input": "1 1\np", "output": "0" }, { "input": "2 5\nacdmw\nefazb", "output": "1" }, { "input": "5 2\ndz\nda\nsx\nyu\nzz", "output": "0" }, { "input": "5 5\nxeljd\nwriac\nveief\nlcacf\nbqefn", "output": "2" }, { "input": "5 5\nacnbx\nefacp\nlrefa\norqce\nzvbay", "output": "3" }, { "input": "5 5\nbyjvu\nkmaca\nalefe\nwcacg\nrefez", "output": "5" }, { "input": "5 5\npuxac\nbbaef\naccfa\nefaec\nligsr", "output": "5" }, { "input": "37 4\nacjo\nefac\nacef\nefac\nwpef\nicac\naefe\ncfac\naece\ncfaf\nyqce\nmiaf\nirce\nycaf\naefc\ncfae\nrsnc\nbacz\nqefb\npdhs\nffac\nfaef\nacfd\nacmi\nefvm\nacaz\nefpn\nacao\nefer\nacap\nefec\nacaf\nefef\nacbj\nefac\nacef\nefoz", "output": "49" }, { "input": "7 3\njac\naef\ncfa\naec\ncfq\ndig\nxyq", "output": "5" }, { "input": "35 1\ny\na\nk\ng\ni\nd\nv\nn\nl\nx\nu\nx\nu\no\nd\nf\nk\nj\nr\nm\nq\ns\nc\nd\nc\nm\nv\nh\nn\ne\nl\nt\nz\ny\no", "output": "0" }, { "input": "9 46\nuuexbaacesjclggslacermcbkxlcxhdgqtacdwfryxzuxc\naclrsaefakndbnzlkefenuphgcgoedhkaxefjtnkgfeaca\nefuqunpmfxdyyffyhvracozzrxlpekhtsrfhlilfmyhefg\numyacfzffvicqtdpiulefnwcojuwtfbvlxkfsiapdnzpqo\nactefvuxqptremlqjhdbdwacjxdxitxjktecvefacamjcz\neflarseklqrkayhosverpfefzirqigzlxezabhzeferkwm\nztpypwxyohtacsnnvoigqwcachtaceyxlkhfhgwbnfmklb\nfzpqeymhljiefctvqtbgcdjefkxefarbciyosmktmoziac\nbssxizyrzyhacszttwhrzspbfkgfcejybdjcpuczhrkqef", "output": "20" }, { "input": "7 30\nmjfracgaacacctacrreyrlkacuacay\nrlacefacefeftaeftkacacaefcefev\nacefacefacraccfaeaefefecaeacaf\nefacefacefaefaecfcfacacaecfefa\nncefacefacecacfaeaecefefcaeace\nfafaceacuafaefadcfcafacaefcfea\nzsvefafukcecfarkaeaecefecailgu", "output": "95" }, { "input": "2 2\nff\nee", "output": "0" }, { "input": "2 2\nfa\ncc", "output": "0" }, { "input": "2 2\nfa\naa", "output": "0" }, { "input": "2 2\nfa\nea", "output": "0" }, { "input": "2 2\nfa\ndd", "output": "0" }, { "input": "2 2\nee\nff", "output": "0" }, { "input": "2 2\ncc\ncf", "output": "0" }, { "input": "2 2\naa\nae", "output": "0" }, { "input": "2 2\nef\nac", "output": "1" }, { "input": "2 2\nfe\nca", "output": "1" } ]
1,666,624,613
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
61
2,764,800
n, m = int(input()) charr = ['f', 'a', 'c', 'e'] strr = [] for i in range(n): strr.append(str(input())) count = 0 for i in range(n - 1): for j in range(m - 1): if strr[i][j] != 'x': count1 = 0 ls = [strr[i][j], strr[i + 1][j], strr[i + 1][j + 1], strr[i][j + 1]] for x in charr: if x in ls == True: count1 += 1 if count1 == 4: count += 1 print(count)
Title: Face Detection Time Limit: None seconds Memory Limit: None megabytes Problem Description: The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. Input Specification: The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively. Next *n* lines define the image. Each line contains *m* lowercase Latin letters. Output Specification: In the single line print the number of faces on the image. Demo Input: ['4 4\nxxxx\nxfax\nxcex\nxxxx\n', '4 2\nxx\ncf\nae\nxx\n', '2 3\nfac\ncef\n', '1 4\nface\n'] Demo Output: ['1\n', '1\n', '2\n', '0\n'] Note: In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column: In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column. In the third sample two faces are shown: In the fourth sample the image has no faces on it.
```python n, m = int(input()) charr = ['f', 'a', 'c', 'e'] strr = [] for i in range(n): strr.append(str(input())) count = 0 for i in range(n - 1): for j in range(m - 1): if strr[i][j] != 'x': count1 = 0 ls = [strr[i][j], strr[i + 1][j], strr[i + 1][j + 1], strr[i][j + 1]] for x in charr: if x in ls == True: count1 += 1 if count1 == 4: count += 1 print(count) ```
-1
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number — the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, { "input": "1022 584 112", "output": "380" }, { "input": "66 174 319", "output": "184" }, { "input": "912 276 1748", "output": "444" }, { "input": "65 156 60", "output": "120" }, { "input": "1 10000 10000", "output": "40008" }, { "input": "1485 55 27", "output": "332" }, { "input": "152 108 4104", "output": "528" }, { "input": "1656 6900 1350", "output": "740" }, { "input": "12 14 42", "output": "60" }, { "input": "615 18 1230", "output": "856" }, { "input": "680 60 408", "output": "336" }, { "input": "644 966 6", "output": "1308" }, { "input": "1 432 432", "output": "1736" }, { "input": "2239 2239 1", "output": "8964" }, { "input": "4106 8212 2", "output": "16436" }, { "input": "10000 10000 10000", "output": "1200" }, { "input": "3623 3623 1", "output": "14500" }, { "input": "9801 9801 9801", "output": "1188" }, { "input": "10000 1 10000", "output": "40008" }, { "input": "9 9 9", "output": "36" }, { "input": "9801 9702 9702", "output": "1184" } ]
1,659,529,746
2,147,483,647
PyPy 3-64
OK
TESTS
27
124
0
from math import sqrt x, y, z = map(int, input().split()) a = sqrt (int((x * y) / z)) b = sqrt (int((x * z) / y)) c = sqrt (int((y * z) / x)) print(int((a + b + c) * 4))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input Specification: The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. Output Specification: Print a single number — the sum of all edges of the parallelepiped. Demo Input: ['1 1 1\n', '4 6 6\n'] Demo Output: ['12\n', '28\n'] Note: In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
```python from math import sqrt x, y, z = map(int, input().split()) a = sqrt (int((x * y) / z)) b = sqrt (int((x * z) / y)) c = sqrt (int((y * z) / x)) print(int((a + b + c) * 4)) ```
3
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,667,992,558
2,147,483,647
Python 3
OK
TESTS
35
46
0
n = input().split() n[0] = int(n[0]) n[1] = int(n[1]) m = input().split() for i in range(0, n[0]): m[i] = int(m[i]) m.sort() s = 0 for j in range(0, n[0]): p = 5 - m[j] if p >= n[1]: s = s + 1 c = s//3 print(c)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python n = input().split() n[0] = int(n[0]) n[1] = int(n[1]) m = input().split() for i in range(0, n[0]): m[i] = int(m[i]) m.sort() s = 0 for j in range(0, n[0]): p = 5 - m[j] if p >= n[1]: s = s + 1 c = s//3 print(c) ```
3
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "499999999" }, { "input": "1924704072", "output": "481176017" }, { "input": "73740586", "output": "18435146" }, { "input": "1925088820", "output": "481272204" }, { "input": "593070992", "output": "148267747" }, { "input": "1925473570", "output": "481368392" }, { "input": "629490186", "output": "157372546" }, { "input": "1980649112", "output": "495162277" }, { "input": "36661322", "output": "9165330" }, { "input": "1943590793", "output": "0" }, { "input": "71207034", "output": "17801758" }, { "input": "1757577394", "output": "439394348" }, { "input": "168305294", "output": "42076323" }, { "input": "1934896224", "output": "483724055" }, { "input": "297149088", "output": "74287271" }, { "input": "1898001634", "output": "474500408" }, { "input": "176409698", "output": "44102424" }, { "input": "1873025522", "output": "468256380" }, { "input": "5714762", "output": "1428690" }, { "input": "1829551192", "output": "457387797" }, { "input": "16269438", "output": "4067359" }, { "input": "1663283390", "output": "415820847" }, { "input": "42549941", "output": "0" }, { "input": "1967345604", "output": "491836400" }, { "input": "854000", "output": "213499" }, { "input": "1995886626", "output": "498971656" }, { "input": "10330019", "output": "0" }, { "input": "1996193634", "output": "499048408" }, { "input": "9605180", "output": "2401294" }, { "input": "1996459740", "output": "499114934" }, { "input": "32691948", "output": "8172986" }, { "input": "1975903308", "output": "493975826" }, { "input": "1976637136", "output": "494159283" }, { "input": "29803038", "output": "7450759" }, { "input": "1977979692", "output": "494494922" }, { "input": "1978595336", "output": "494648833" }, { "input": "27379344", "output": "6844835" }, { "input": "1979729912", "output": "494932477" }, { "input": "1980253780", "output": "495063444" }, { "input": "1980751584", "output": "495187895" }, { "input": "53224878", "output": "13306219" }, { "input": "5", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "1" }, { "input": "9", "output": "0" }, { "input": "10", "output": "2" }, { "input": "11", "output": "0" }, { "input": "12", "output": "2" }, { "input": "13", "output": "0" }, { "input": "14", "output": "3" }, { "input": "15", "output": "0" }, { "input": "16", "output": "3" }, { "input": "17", "output": "0" }, { "input": "18", "output": "4" }, { "input": "19", "output": "0" }, { "input": "21", "output": "0" }, { "input": "22", "output": "5" }, { "input": "23", "output": "0" }, { "input": "24", "output": "5" }, { "input": "25", "output": "0" }, { "input": "26", "output": "6" }, { "input": "27", "output": "0" }, { "input": "28", "output": "6" }, { "input": "29", "output": "0" }, { "input": "30", "output": "7" }, { "input": "111", "output": "0" }, { "input": "55", "output": "0" }, { "input": "105", "output": "0" }, { "input": "199", "output": "0" }, { "input": "151", "output": "0" } ]
1,655,703,089
2,147,483,647
Python 3
OK
TESTS
76
46
0
n=int(input()) if n%2!=0: print(0) elif n<6: print(0) else: c=0 n=n//2 c=n-1 print(c//2)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. Output Specification: The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Demo Input: ['6\n', '20\n'] Demo Output: ['1\n', '4\n'] Note: There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
```python n=int(input()) if n%2!=0: print(0) elif n<6: print(0) else: c=0 n=n//2 c=n-1 print(c//2) ```
3
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output": "1 2" }, { "input": "5\n4 24 6 1 15", "output": "3 4" }, { "input": "2\n511 32", "output": "1 2" }, { "input": "3\n907 452 355", "output": "2 3" }, { "input": "4\n303 872 764 401", "output": "4 1" }, { "input": "10\n684 698 429 694 956 812 594 170 937 764", "output": "1 2" }, { "input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695", "output": "7 8" }, { "input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000", "output": "12 13" }, { "input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58", "output": "16 17" }, { "input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000", "output": "1 2" }, { "input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4", "output": "1 2" }, { "input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438", "output": "86 87" }, { "input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25", "output": "7 8" }, { "input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964", "output": "1 2" }, { "input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967", "output": "81 82" }, { "input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17", "output": "36 37" } ]
1,632,896,859
2,147,483,647
Python 3
OK
TESTS
20
124
6,963,200
a=input();a,b,c=list(map(int,input().split())),1000,0;a.append(a[0]) for i in range(len(a)-1): if abs(a[i]-a[i+1])<b: b,c=abs(a[i]-a[i+1]),i if c-len(a)+2: print(c+1,c+2) else: print(c+1,1)
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. Output Specification: Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Demo Input: ['5\n10 12 13 15 10\n', '4\n10 20 30 40\n'] Demo Output: ['5 1\n', '1 2\n'] Note: none
```python a=input();a,b,c=list(map(int,input().split())),1000,0;a.append(a[0]) for i in range(len(a)-1): if abs(a[i]-a[i+1])<b: b,c=abs(a[i]-a[i+1]),i if c-len(a)+2: print(c+1,c+2) else: print(c+1,1) ```
3.95603
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat.
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "0" }, { "input": "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS", "output": "0" }, { "input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS", "output": "30" }, { "input": "10 10\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..", "output": "80" }, { "input": "9 5\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS", "output": "0" }, { "input": "9 9\n...S.....\nS.S.....S\n.S....S..\n.S.....SS\n.........\n..S.S..S.\n.SS......\n....S....\n..S...S..", "output": "17" }, { "input": "5 6\nSSSSSS\nSSSSSS\nSSSSSS\nSS.S..\nS.S.SS", "output": "0" }, { "input": "9 8\n........\n.......S\n........\nS.......\n........\n........\nS.......\n........\n.......S", "output": "64" }, { "input": "9 7\n......S\n......S\nS.S.S..\n.......\n.......\n.S.....\n.S....S\n..S....\n.S....S", "output": "28" }, { "input": "10 10\n.....S....\n....SS..S.\n.S...S....\n........SS\n.S.......S\nSS..S.....\n.SS.....SS\nS..S......\n.......SSS\nSSSSS....S", "output": "10" }, { "input": "6 7\n..S.SS.\n......S\n....S.S\nSS..S..\nS..SS.S\n.....S.", "output": "0" }, { "input": "10 6\n.SSSSS\nSSS.SS\nSSSSSS\nS.SSSS\nSSSSS.\nS.SSSS\nSS.SSS\n.SSS.S\n.SSS..\nSS..SS", "output": "0" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "3 2\nS.\n.S\nS.", "output": "0" }, { "input": "3 2\nS.\n.S\nS.", "output": "0" }, { "input": "4 3\n.S.\nS.S\n.S.\nS.S", "output": "0" }, { "input": "2 3\n...\nSSS", "output": "3" }, { "input": "2 4\nS.SS\nS.SS", "output": "2" }, { "input": "2 2\n..\n.S", "output": "3" }, { "input": "3 2\n.S\n.S\nSS", "output": "0" }, { "input": "2 4\nSS.S\n..S.", "output": "0" }, { "input": "2 3\n...\nS..", "output": "5" } ]
1,642,310,047
2,147,483,647
Python 3
OK
TESTS
42
92
0
if __name__ == "__main__": r, c = input().strip().split() r = int(r) c = int(c) count = 0 cake = [] for i in range(r): temp = [char for char in input().strip()] if 'S' not in temp: count += c r -= 1 else: cake.append(temp) for i in range(c): arr = [cake[j][i] for j in range(r)] if 'S' not in arr: count += r print(count)
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat. Input Specification: The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry. Output Specification: Output the maximum number of cake cells that the cakeminator can eat. Demo Input: ['3 4\nS...\n....\n..S.\n'] Demo Output: ['8\n'] Note: For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
```python if __name__ == "__main__": r, c = input().strip().split() r = int(r) c = int(c) count = 0 cake = [] for i in range(r): temp = [char for char in input().strip()] if 'S' not in temp: count += c r -= 1 else: cake.append(temp) for i in range(c): arr = [cake[j][i] for j in range(r)] if 'S' not in arr: count += r print(count) ```
3
770
B
Maximize Sum of Digits
PROGRAMMING
1,300
[ "*special", "implementation", "math" ]
null
null
Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.
The first line contains the positive integer *x* (1<=≤<=*x*<=≤<=1018) — the integer which Anton has.
Print the positive integer which doesn't exceed *x* and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.
[ "100\n", "48\n", "521\n" ]
[ "99\n", "48\n", "499\n" ]
none
1,000
[ { "input": "100", "output": "99" }, { "input": "48", "output": "48" }, { "input": "521", "output": "499" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "3" }, { "input": "39188", "output": "38999" }, { "input": "5", "output": "5" }, { "input": "6", "output": "6" }, { "input": "7", "output": "7" }, { "input": "8", "output": "8" }, { "input": "9", "output": "9" }, { "input": "10", "output": "9" }, { "input": "59999154", "output": "59998999" }, { "input": "1000", "output": "999" }, { "input": "10000", "output": "9999" }, { "input": "100000", "output": "99999" }, { "input": "1000000", "output": "999999" }, { "input": "10000000", "output": "9999999" }, { "input": "100000000", "output": "99999999" }, { "input": "1000000000", "output": "999999999" }, { "input": "10000000000", "output": "9999999999" }, { "input": "100000000000", "output": "99999999999" }, { "input": "1000000000000", "output": "999999999999" }, { "input": "10000000000000", "output": "9999999999999" }, { "input": "100000000000000", "output": "99999999999999" }, { "input": "1000000000000000", "output": "999999999999999" }, { "input": "10000000000000000", "output": "9999999999999999" }, { "input": "100000000000000000", "output": "99999999999999999" }, { "input": "1000000000000000000", "output": "999999999999999999" }, { "input": "999999990", "output": "999999989" }, { "input": "666666899789879", "output": "599999999999999" }, { "input": "65499992294999000", "output": "59999999999999999" }, { "input": "9879100000000099", "output": "8999999999999999" }, { "input": "9991919190909919", "output": "9989999999999999" }, { "input": "978916546899999999", "output": "899999999999999999" }, { "input": "5684945999999999", "output": "4999999999999999" }, { "input": "999999999999999999", "output": "999999999999999999" }, { "input": "999999999999990999", "output": "999999999999989999" }, { "input": "999999999999999990", "output": "999999999999999989" }, { "input": "909999999999999999", "output": "899999999999999999" }, { "input": "199999999999999999", "output": "199999999999999999" }, { "input": "299999999999999999", "output": "299999999999999999" }, { "input": "999999990009999999", "output": "999999989999999999" }, { "input": "999000000001999999", "output": "998999999999999999" }, { "input": "999999999991", "output": "999999999989" }, { "input": "999999999992", "output": "999999999989" }, { "input": "79320", "output": "78999" }, { "input": "99004", "output": "98999" }, { "input": "99088", "output": "98999" }, { "input": "99737", "output": "98999" }, { "input": "29652", "output": "28999" }, { "input": "59195", "output": "58999" }, { "input": "19930", "output": "19899" }, { "input": "49533", "output": "48999" }, { "input": "69291", "output": "68999" }, { "input": "59452", "output": "58999" }, { "input": "11", "output": "9" }, { "input": "110", "output": "99" }, { "input": "111", "output": "99" }, { "input": "119", "output": "99" }, { "input": "118", "output": "99" }, { "input": "1100", "output": "999" }, { "input": "1199", "output": "999" }, { "input": "1109", "output": "999" }, { "input": "1190", "output": "999" }, { "input": "12", "output": "9" }, { "input": "120", "output": "99" }, { "input": "121", "output": "99" }, { "input": "129", "output": "99" }, { "input": "128", "output": "99" }, { "input": "1200", "output": "999" }, { "input": "1299", "output": "999" }, { "input": "1209", "output": "999" }, { "input": "1290", "output": "999" }, { "input": "13", "output": "9" }, { "input": "130", "output": "99" }, { "input": "131", "output": "99" }, { "input": "139", "output": "99" }, { "input": "138", "output": "99" }, { "input": "1300", "output": "999" }, { "input": "1399", "output": "999" }, { "input": "1309", "output": "999" }, { "input": "1390", "output": "999" }, { "input": "14", "output": "9" }, { "input": "140", "output": "99" }, { "input": "141", "output": "99" }, { "input": "149", "output": "99" }, { "input": "148", "output": "99" }, { "input": "1400", "output": "999" }, { "input": "1499", "output": "999" }, { "input": "1409", "output": "999" }, { "input": "1490", "output": "999" }, { "input": "15", "output": "9" }, { "input": "150", "output": "99" }, { "input": "151", "output": "99" }, { "input": "159", "output": "99" }, { "input": "158", "output": "99" }, { "input": "1500", "output": "999" }, { "input": "1599", "output": "999" }, { "input": "1509", "output": "999" }, { "input": "1590", "output": "999" }, { "input": "16", "output": "9" }, { "input": "160", "output": "99" }, { "input": "161", "output": "99" }, { "input": "169", "output": "99" }, { "input": "168", "output": "99" }, { "input": "1600", "output": "999" }, { "input": "1699", "output": "999" }, { "input": "1609", "output": "999" }, { "input": "1690", "output": "999" }, { "input": "17", "output": "9" }, { "input": "170", "output": "99" }, { "input": "171", "output": "99" }, { "input": "179", "output": "99" }, { "input": "178", "output": "99" }, { "input": "1700", "output": "999" }, { "input": "1799", "output": "999" }, { "input": "1709", "output": "999" }, { "input": "1790", "output": "999" }, { "input": "18", "output": "18" }, { "input": "180", "output": "99" }, { "input": "181", "output": "99" }, { "input": "189", "output": "189" }, { "input": "188", "output": "99" }, { "input": "1800", "output": "999" }, { "input": "1899", "output": "1899" }, { "input": "1809", "output": "999" }, { "input": "1890", "output": "999" }, { "input": "19", "output": "19" }, { "input": "190", "output": "189" }, { "input": "191", "output": "189" }, { "input": "199", "output": "199" }, { "input": "198", "output": "198" }, { "input": "1900", "output": "1899" }, { "input": "1999", "output": "1999" }, { "input": "1909", "output": "1899" }, { "input": "1990", "output": "1989" }, { "input": "20", "output": "19" }, { "input": "200", "output": "199" }, { "input": "201", "output": "199" }, { "input": "209", "output": "199" }, { "input": "208", "output": "199" }, { "input": "2000", "output": "1999" }, { "input": "2099", "output": "1999" }, { "input": "2009", "output": "1999" }, { "input": "2090", "output": "1999" }, { "input": "21", "output": "19" }, { "input": "210", "output": "199" }, { "input": "211", "output": "199" }, { "input": "219", "output": "199" }, { "input": "218", "output": "199" }, { "input": "2100", "output": "1999" }, { "input": "2199", "output": "1999" }, { "input": "2109", "output": "1999" }, { "input": "2190", "output": "1999" }, { "input": "22", "output": "19" }, { "input": "220", "output": "199" }, { "input": "221", "output": "199" }, { "input": "229", "output": "199" }, { "input": "228", "output": "199" }, { "input": "2200", "output": "1999" }, { "input": "2299", "output": "1999" }, { "input": "2209", "output": "1999" }, { "input": "2290", "output": "1999" }, { "input": "23", "output": "19" }, { "input": "230", "output": "199" }, { "input": "231", "output": "199" }, { "input": "239", "output": "199" }, { "input": "238", "output": "199" }, { "input": "2300", "output": "1999" }, { "input": "2399", "output": "1999" }, { "input": "2309", "output": "1999" }, { "input": "2390", "output": "1999" }, { "input": "24", "output": "19" }, { "input": "240", "output": "199" }, { "input": "241", "output": "199" }, { "input": "249", "output": "199" }, { "input": "248", "output": "199" }, { "input": "2400", "output": "1999" }, { "input": "2499", "output": "1999" }, { "input": "2409", "output": "1999" }, { "input": "2490", "output": "1999" }, { "input": "25", "output": "19" }, { "input": "250", "output": "199" }, { "input": "251", "output": "199" }, { "input": "259", "output": "199" }, { "input": "258", "output": "199" }, { "input": "2500", "output": "1999" }, { "input": "2599", "output": "1999" }, { "input": "2509", "output": "1999" }, { "input": "2590", "output": "1999" }, { "input": "26", "output": "19" }, { "input": "260", "output": "199" }, { "input": "261", "output": "199" }, { "input": "269", "output": "199" }, { "input": "268", "output": "199" }, { "input": "2600", "output": "1999" }, { "input": "2699", "output": "1999" }, { "input": "2609", "output": "1999" }, { "input": "2690", "output": "1999" }, { "input": "27", "output": "19" }, { "input": "270", "output": "199" }, { "input": "271", "output": "199" }, { "input": "279", "output": "199" }, { "input": "278", "output": "199" }, { "input": "2700", "output": "1999" }, { "input": "2799", "output": "1999" }, { "input": "2709", "output": "1999" }, { "input": "2790", "output": "1999" }, { "input": "28", "output": "28" }, { "input": "280", "output": "199" }, { "input": "281", "output": "199" }, { "input": "289", "output": "289" }, { "input": "288", "output": "199" }, { "input": "2800", "output": "1999" }, { "input": "2899", "output": "2899" }, { "input": "2809", "output": "1999" }, { "input": "2890", "output": "1999" }, { "input": "29", "output": "29" }, { "input": "290", "output": "289" }, { "input": "291", "output": "289" }, { "input": "299", "output": "299" }, { "input": "298", "output": "298" }, { "input": "2900", "output": "2899" }, { "input": "2999", "output": "2999" }, { "input": "2909", "output": "2899" }, { "input": "2990", "output": "2989" }, { "input": "999", "output": "999" }, { "input": "999", "output": "999" }, { "input": "890", "output": "889" }, { "input": "995", "output": "989" }, { "input": "999", "output": "999" }, { "input": "989", "output": "989" }, { "input": "999", "output": "999" }, { "input": "999", "output": "999" }, { "input": "991", "output": "989" }, { "input": "999", "output": "999" }, { "input": "9929", "output": "9899" }, { "input": "4999", "output": "4999" }, { "input": "9690", "output": "8999" }, { "input": "8990", "output": "8989" }, { "input": "9982", "output": "9899" }, { "input": "9999", "output": "9999" }, { "input": "1993", "output": "1989" }, { "input": "9367", "output": "8999" }, { "input": "8939", "output": "8899" }, { "input": "9899", "output": "9899" }, { "input": "99999", "output": "99999" }, { "input": "93929", "output": "89999" }, { "input": "99999", "output": "99999" }, { "input": "38579", "output": "29999" }, { "input": "79096", "output": "78999" }, { "input": "72694", "output": "69999" }, { "input": "99999", "output": "99999" }, { "input": "99999", "output": "99999" }, { "input": "99992", "output": "99989" }, { "input": "27998", "output": "19999" }, { "input": "460999", "output": "399999" }, { "input": "999999", "output": "999999" }, { "input": "999999", "output": "999999" }, { "input": "998999", "output": "998999" }, { "input": "999999", "output": "999999" }, { "input": "999929", "output": "999899" }, { "input": "999999", "output": "999999" }, { "input": "999999", "output": "999999" }, { "input": "979199", "output": "899999" }, { "input": "999999", "output": "999999" }, { "input": "9899999", "output": "9899999" }, { "input": "9699959", "output": "8999999" }, { "input": "9999999", "output": "9999999" }, { "input": "9997099", "output": "9989999" }, { "input": "8992091", "output": "8989999" }, { "input": "9599295", "output": "8999999" }, { "input": "2999902", "output": "2999899" }, { "input": "9999953", "output": "9999899" }, { "input": "9999999", "output": "9999999" }, { "input": "9590999", "output": "8999999" } ]
1,658,183,045
2,147,483,647
PyPy 3-64
OK
TESTS
278
62
0
import sys input = sys.stdin.readline x = input()[:-1] n = len(x) d = [int(x)] for i in range(1, n+1): d.append(int(str(int(x[:i])-1) + '9'*(n-i))) d.sort(reverse=True) for i in range(len(d)): if d[i] <= int(x): c = sum([int(a) for a in str(d[i])]) d[i] = [c, d[i]] c = max(i for i, j in d) for i, j in d: if i == c: print(j) break
Title: Maximize Sum of Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. Input Specification: The first line contains the positive integer *x* (1<=≤<=*x*<=≤<=1018) — the integer which Anton has. Output Specification: Print the positive integer which doesn't exceed *x* and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros. Demo Input: ['100\n', '48\n', '521\n'] Demo Output: ['99\n', '48\n', '499\n'] Note: none
```python import sys input = sys.stdin.readline x = input()[:-1] n = len(x) d = [int(x)] for i in range(1, n+1): d.append(int(str(int(x[:i])-1) + '9'*(n-i))) d.sort(reverse=True) for i in range(len(d)): if d[i] <= int(x): c = sum([int(a) for a in str(d[i])]) d[i] = [c, d[i]] c = max(i for i, j in d) for i, j in d: if i == c: print(j) break ```
3
496
A
Minimum Difficulty
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height. Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions. Help Mike determine the minimum difficulty of the track after removing one hold.
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Print a single number — the minimum difficulty of the track after removing a single hold.
[ "3\n1 4 6\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n" ]
[ "5\n", "2\n", "4\n" ]
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5. In the second test after removing every hold the difficulty equals 2. In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4.
500
[ { "input": "3\n1 4 6", "output": "5" }, { "input": "5\n1 2 3 4 5", "output": "2" }, { "input": "5\n1 2 3 7 8", "output": "4" }, { "input": "3\n1 500 1000", "output": "999" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "2" }, { "input": "10\n1 4 9 16 25 36 49 64 81 100", "output": "19" }, { "input": "10\n300 315 325 338 350 365 379 391 404 416", "output": "23" }, { "input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112", "output": "2" }, { "input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500", "output": "310" }, { "input": "3\n159 282 405", "output": "246" }, { "input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741", "output": "241" }, { "input": "10\n218 300 388 448 535 629 680 740 836 925", "output": "111" }, { "input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996", "output": "20" }, { "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 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000", "output": "901" }, { "input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978", "output": "605" }, { "input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999", "output": "803" }, { "input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932", "output": "17" }, { "input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000", "output": "54" }, { "input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000", "output": "74" } ]
1,418,834,497
697
Python 3
OK
TESTS
19
61
0
n, a = int(input()), list(map(int, input().split())) ans = 20000 for i in range(1, n - 1): b = a[:i] + a[i + 1:] ans = min(ans, max(b[j + 1] - b[j] for j in range(n - 2))) print(ans)
Title: Minimum Difficulty Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height. Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions. Help Mike determine the minimum difficulty of the track after removing one hold. Input Specification: The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). Output Specification: Print a single number — the minimum difficulty of the track after removing a single hold. Demo Input: ['3\n1 4 6\n', '5\n1 2 3 4 5\n', '5\n1 2 3 7 8\n'] Demo Output: ['5\n', '2\n', '4\n'] Note: In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5. In the second test after removing every hold the difficulty equals 2. In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4.
```python n, a = int(input()), list(map(int, input().split())) ans = 20000 for i in range(1, n - 1): b = a[:i] + a[i + 1:] ans = min(ans, max(b[j + 1] - b[j] for j in range(n - 2))) print(ans) ```
3
493
B
Vasya and Wrestling
PROGRAMMING
1,400
[ "implementation" ]
null
null
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105). The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points. The techniques are given in chronological order.
If the first wrestler wins, print string "first", otherwise print "second"
[ "5\n1\n2\n-3\n-4\n3\n", "3\n-1\n-2\n3\n", "2\n4\n-4\n" ]
[ "second\n", "first\n", "second\n" ]
Sequence *x*  =  *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*  =  *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|  &gt;  |*y*| and *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>, ... ,  *x*<sub class="lower-index">|*y*|</sub>  =  *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r*  &lt;  |*x*|, *r*  &lt;  |*y*|), that *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>,  ... ,  *x*<sub class="lower-index">*r*</sub>  =  *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r*  +  1</sub>  &gt;  *y*<sub class="lower-index">*r*  +  1</sub>. We use notation |*a*| to denote length of sequence *a*.
1,000
[ { "input": "5\n1\n2\n-3\n-4\n3", "output": "second" }, { "input": "3\n-1\n-2\n3", "output": "first" }, { "input": "2\n4\n-4", "output": "second" }, { "input": "7\n1\n2\n-3\n4\n5\n-6\n7", "output": "first" }, { "input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14", "output": "second" }, { "input": "4\n16\n12\n19\n-98", "output": "second" }, { "input": "5\n-6\n-1\n-1\n5\n3", "output": "second" }, { "input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1", "output": "first" }, { "input": "1\n-534365", "output": "second" }, { "input": "1\n10253033", "output": "first" }, { "input": "3\n-1\n-2\n3", "output": "first" }, { "input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8", "output": "second" }, { "input": "2\n1\n-1", "output": "second" }, { "input": "5\n1\n2\n3\n4\n5", "output": "first" }, { "input": "5\n-1\n-2\n-3\n-4\n-5", "output": "second" }, { "input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1", "output": "first" }, { "input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2", "output": "first" }, { "input": "6\n-1\n-2\n-3\n1\n2\n3", "output": "first" }, { "input": "3\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "4\n1000000000\n1000000000\n1000000000\n-1000000000", "output": "first" }, { "input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000", "output": "second" }, { "input": "4\n1\n-1000000000\n-1000000000\n-1000000000", "output": "second" }, { "input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000", "output": "first" }, { "input": "4\n-1\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "output": "first" }, { "input": "2\n-4\n4", "output": "first" }, { "input": "3\n-12\n3\n9", "output": "second" }, { "input": "3\n9\n1\n-10", "output": "second" }, { "input": "3\n1\n2\n-3", "output": "second" }, { "input": "4\n55\n5\n-5\n-55", "output": "first" }, { "input": "4\n5\n-1\n1\n-5", "output": "first" }, { "input": "2\n-5\n6", "output": "first" }, { "input": "4\n5\n-4\n3\n-40", "output": "second" }, { "input": "4\n1000000000\n1000000000\n1000000000\n-5", "output": "first" }, { "input": "6\n3\n2\n1\n-3\n-1\n-2", "output": "first" }, { "input": "5\n4\n1\n1\n-3\n-3", "output": "first" }, { "input": "5\n208\n-52\n-52\n-52\n-52", "output": "first" }, { "input": "3\n-100\n-200\n300", "output": "first" }, { "input": "3\n400\n-200\n-200", "output": "first" }, { "input": "3\n208\n-207\n-1", "output": "first" }, { "input": "3\n98888887\n98888888\n-197777775", "output": "second" } ]
1,624,125,216
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
11,571,200
s1 = '' s2 = '' cnt1 = 0 cnt2 = 0 last = None n = int(input()) for i in range(n): x = int(input()) if x > 0: s1 += str(x) cnt1 += x last = 0 else: x = abs(x) s2 += str(x) cnt2 += x last = 1 if cnt1 > cnt2: print('first') elif cnt1 < cnt2: print('second') else: if s1 > s2: print('first') elif s1 < s2: print('second') else: if last == 0: print('first') else: print('second')
Title: Vasya and Wrestling Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. Input Specification: The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105). The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points. The techniques are given in chronological order. Output Specification: If the first wrestler wins, print string "first", otherwise print "second" Demo Input: ['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n'] Demo Output: ['second\n', 'first\n', 'second\n'] Note: Sequence *x*  =  *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*  =  *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|  &gt;  |*y*| and *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>, ... ,  *x*<sub class="lower-index">|*y*|</sub>  =  *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r*  &lt;  |*x*|, *r*  &lt;  |*y*|), that *x*<sub class="lower-index">1</sub>  =  *y*<sub class="lower-index">1</sub>,  *x*<sub class="lower-index">2</sub>  =  *y*<sub class="lower-index">2</sub>,  ... ,  *x*<sub class="lower-index">*r*</sub>  =  *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r*  +  1</sub>  &gt;  *y*<sub class="lower-index">*r*  +  1</sub>. We use notation |*a*| to denote length of sequence *a*.
```python s1 = '' s2 = '' cnt1 = 0 cnt2 = 0 last = None n = int(input()) for i in range(n): x = int(input()) if x > 0: s1 += str(x) cnt1 += x last = 0 else: x = abs(x) s2 += str(x) cnt2 += x last = 1 if cnt1 > cnt2: print('first') elif cnt1 < cnt2: print('second') else: if s1 > s2: print('first') elif s1 < s2: print('second') else: if last == 0: print('first') else: print('second') ```
0
820
A
Mister B and Book Reading
PROGRAMMING
900
[ "implementation" ]
null
null
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at second — *v*0<=+<=*a* pages, at third — *v*0<=+<=2*a* pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than *v*1 pages per day. Also, to refresh his memory, every day, starting from the second, Mister B had to reread last *l* pages he read on the previous day. Mister B finished the book when he read the last page for the first time. Help Mister B to calculate how many days he needed to finish the book.
First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=&lt;<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.
Print one integer — the number of days Mister B needed to finish the book.
[ "5 5 10 5 4\n", "12 4 12 4 1\n", "15 1 100 0 0\n" ]
[ "1\n", "3\n", "15\n" ]
In the first sample test the book contains 5 pages, so Mister B read it right at the first day. In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book. In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.
500
[ { "input": "5 5 10 5 4", "output": "1" }, { "input": "12 4 12 4 1", "output": "3" }, { "input": "15 1 100 0 0", "output": "15" }, { "input": "1 1 1 0 0", "output": "1" }, { "input": "1000 999 1000 1000 998", "output": "2" }, { "input": "1000 2 2 5 1", "output": "999" }, { "input": "1000 1 1 1000 0", "output": "1000" }, { "input": "737 41 74 12 11", "output": "13" }, { "input": "1000 1000 1000 0 999", "output": "1" }, { "input": "765 12 105 5 7", "output": "17" }, { "input": "15 2 2 1000 0", "output": "8" }, { "input": "1000 1 1000 1000 0", "output": "2" }, { "input": "20 3 7 1 2", "output": "6" }, { "input": "1000 500 500 1000 499", "output": "501" }, { "input": "1 1000 1000 1000 0", "output": "1" }, { "input": "1000 2 1000 56 0", "output": "7" }, { "input": "1000 2 1000 802 0", "output": "3" }, { "input": "16 1 8 2 0", "output": "4" }, { "input": "20 6 10 2 2", "output": "3" }, { "input": "8 2 12 4 1", "output": "3" }, { "input": "8 6 13 2 5", "output": "2" }, { "input": "70 4 20 87 0", "output": "5" }, { "input": "97 8 13 234 5", "output": "13" }, { "input": "16 4 23 8 3", "output": "3" }, { "input": "65 7 22 7 4", "output": "5" }, { "input": "93 10 18 11 7", "output": "9" }, { "input": "86 13 19 15 9", "output": "9" }, { "input": "333 17 50 10 16", "output": "12" }, { "input": "881 16 55 10 12", "output": "23" }, { "input": "528 11 84 3 9", "output": "19" }, { "input": "896 2 184 8 1", "output": "16" }, { "input": "236 10 930 9 8", "output": "8" }, { "input": "784 1 550 14 0", "output": "12" }, { "input": "506 1 10 4 0", "output": "53" }, { "input": "460 1 3 2 0", "output": "154" }, { "input": "701 1 3 1 0", "output": "235" }, { "input": "100 49 50 1000 2", "output": "3" }, { "input": "100 1 100 100 0", "output": "2" }, { "input": "12 1 4 2 0", "output": "4" }, { "input": "22 10 12 0 0", "output": "3" }, { "input": "20 10 15 1 4", "output": "3" }, { "input": "1000 5 10 1 4", "output": "169" }, { "input": "1000 1 1000 1 0", "output": "45" }, { "input": "4 1 2 2 0", "output": "3" }, { "input": "1 5 5 1 1", "output": "1" }, { "input": "19 10 11 0 2", "output": "3" }, { "input": "1 2 3 0 0", "output": "1" }, { "input": "10 1 4 10 0", "output": "4" }, { "input": "20 3 100 1 1", "output": "5" }, { "input": "1000 5 9 5 0", "output": "112" }, { "input": "1 11 12 0 10", "output": "1" }, { "input": "1 1 1 1 0", "output": "1" }, { "input": "1000 1 20 1 0", "output": "60" }, { "input": "9 1 4 2 0", "output": "4" }, { "input": "129 2 3 4 0", "output": "44" }, { "input": "4 2 2 0 1", "output": "3" }, { "input": "1000 1 10 100 0", "output": "101" }, { "input": "100 1 100 1 0", "output": "14" }, { "input": "8 3 4 2 0", "output": "3" }, { "input": "20 1 6 4 0", "output": "5" }, { "input": "8 2 4 2 0", "output": "3" }, { "input": "11 5 6 7 2", "output": "3" }, { "input": "100 120 130 120 0", "output": "1" }, { "input": "7 1 4 1 0", "output": "4" }, { "input": "5 3 10 0 2", "output": "3" }, { "input": "5 2 2 0 0", "output": "3" }, { "input": "1000 10 1000 10 0", "output": "14" }, { "input": "25 3 50 4 2", "output": "4" }, { "input": "9 10 10 10 9", "output": "1" }, { "input": "17 10 12 6 5", "output": "2" }, { "input": "15 5 10 3 0", "output": "3" }, { "input": "8 3 5 1 0", "output": "3" }, { "input": "19 1 12 5 0", "output": "4" }, { "input": "1000 10 1000 1 0", "output": "37" }, { "input": "100 1 2 1000 0", "output": "51" }, { "input": "20 10 11 1000 9", "output": "6" }, { "input": "16 2 100 1 1", "output": "5" }, { "input": "18 10 13 2 5", "output": "3" }, { "input": "12 3 5 3 1", "output": "4" }, { "input": "17 3 11 2 0", "output": "4" }, { "input": "4 2 100 1 1", "output": "2" }, { "input": "7 4 5 2 3", "output": "3" }, { "input": "100 1 2 2 0", "output": "51" }, { "input": "50 4 5 5 0", "output": "11" }, { "input": "1 2 2 0 1", "output": "1" }, { "input": "1000 2 3 10 1", "output": "500" }, { "input": "500 10 500 1000 0", "output": "2" }, { "input": "1000 4 12 1 0", "output": "87" }, { "input": "18 10 13 1 5", "output": "3" }, { "input": "7 3 6 2 2", "output": "3" }, { "input": "15 5 100 1 2", "output": "4" }, { "input": "100 1 10 1 0", "output": "15" }, { "input": "8 2 7 5 1", "output": "2" }, { "input": "11 2 4 1 1", "output": "5" }, { "input": "1000 500 900 100 300", "output": "3" }, { "input": "7 1 2 5 0", "output": "4" }, { "input": "7 3 5 3 2", "output": "3" }, { "input": "7 3 10 2 1", "output": "2" }, { "input": "1000 501 510 1 499", "output": "50" }, { "input": "1000 1 1000 2 0", "output": "32" }, { "input": "1 5 5 0 0", "output": "1" }, { "input": "18 10 15 1 5", "output": "3" }, { "input": "100 4 1000 1 2", "output": "13" }, { "input": "20 2 40 1 1", "output": "6" }, { "input": "1 11 1000 100 1", "output": "1" }, { "input": "6 4 4 1 2", "output": "2" }, { "input": "8 3 5 3 1", "output": "3" }, { "input": "10 5 7 1 2", "output": "3" }, { "input": "400 100 198 1 99", "output": "25" }, { "input": "3 1 2 5 0", "output": "2" } ]
1,570,429,127
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
26
109
0
def MisterBandBookReading(c,v0,v1,a,l): n = 0 cntOfPagesRead = 0 while cntOfPagesRead<c: PagesRead = v0 + n * a if n!=0: PagesRead -= l if PagesRead <= v1: cntOfPagesRead += PagesRead else: cntOfPagesRead += (v1 - l) n+=1 return n c,v0,v1,a,l = [int(x) for x in input().split()] print(MisterBandBookReading(c,v0,v1,a,l))
Title: Mister B and Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at second — *v*0<=+<=*a* pages, at third — *v*0<=+<=2*a* pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than *v*1 pages per day. Also, to refresh his memory, every day, starting from the second, Mister B had to reread last *l* pages he read on the previous day. Mister B finished the book when he read the last page for the first time. Help Mister B to calculate how many days he needed to finish the book. Input Specification: First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=&lt;<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading. Output Specification: Print one integer — the number of days Mister B needed to finish the book. Demo Input: ['5 5 10 5 4\n', '12 4 12 4 1\n', '15 1 100 0 0\n'] Demo Output: ['1\n', '3\n', '15\n'] Note: In the first sample test the book contains 5 pages, so Mister B read it right at the first day. In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book. In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.
```python def MisterBandBookReading(c,v0,v1,a,l): n = 0 cntOfPagesRead = 0 while cntOfPagesRead<c: PagesRead = v0 + n * a if n!=0: PagesRead -= l if PagesRead <= v1: cntOfPagesRead += PagesRead else: cntOfPagesRead += (v1 - l) n+=1 return n c,v0,v1,a,l = [int(x) for x in input().split()] print(MisterBandBookReading(c,v0,v1,a,l)) ```
0
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "output": "GBBGBB" }, { "input": "8 3\nBBGBGBGB", "output": "GGBGBBBB" }, { "input": "10 3\nBBGBBBBBBG", "output": "GBBBBBGBBB" }, { "input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB", "output": "GGGGGGGGBGGBGGBBBBBBBB" }, { "input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG", "output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB" }, { "input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG", "output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB" }, { "input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB", "output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB" }, { "input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB", "output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB" }, { "input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB", "output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB" }, { "input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "1 1\nB", "output": "B" }, { "input": "1 1\nG", "output": "G" }, { "input": "1 50\nB", "output": "B" }, { "input": "1 50\nG", "output": "G" }, { "input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB", "output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB" }, { "input": "6 3\nGGBBBG", "output": "GGGBBB" }, { "input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG", "output": "GGBBBBGBGBGBGGGBGBGGGBGBBB" }, { "input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB", "output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB" }, { "input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB", "output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB", "output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB" }, { "input": "17 42\nBBGBGBGGGGGGBBGGG", "output": "GGGGGGGGGGGBBBBBB" }, { "input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG", "output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB" }, { "input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB", "output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB" }, { "input": "2 2\nBG", "output": "GB" }, { "input": "8 8\nGGGBGGBB", "output": "GGGGGBBB" }, { "input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB", "output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB" }, { "input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG", "output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG", "output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "10 10\nGGGGGGGGGG", "output": "GGGGGGGGGG" }, { "input": "10 10\nBBBBBBBBBB", "output": "BBBBBBBBBB" }, { "input": "10 10\nBGBGBGBGBG", "output": "GGGGGBBBBB" }, { "input": "1 1\nB", "output": "B" } ]
1,697,054,683
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
def queue(): n=int(input()) t=int(input()) c=str(input()) i=0 for j in range (t): s="" while i<n: if i<n-1 and c[i]=="B" and c[i+1]=="G" : s=s+"G"+"B" i=i+2 else: s=s+c[i] i=i+1 i=0 #!!!!!!!! c=s[0:] print(c) queue()
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". Output Specification: Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". Demo Input: ['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n'] Demo Output: ['GBGGB\n', 'GGBGB\n', 'GGGB\n'] Note: none
```python def queue(): n=int(input()) t=int(input()) c=str(input()) i=0 for j in range (t): s="" while i<n: if i<n-1 and c[i]=="B" and c[i+1]=="G" : s=s+"G"+"B" i=i+2 else: s=s+c[i] i=i+1 i=0 #!!!!!!!! c=s[0:] print(c) queue() ```
-1
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,587,021,440
2,147,483,647
Python 3
OK
TESTS
34
124
0
n=int(input()) a=input() if (a[0]=='S' and a[-1]=='F'): print('YES') else: 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]=='S' and a[-1]=='F'): print('YES') else: print('NO') ```
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,676,975,213
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
20
2,000
9,932,800
# your code goes here import math s =input() s=s.lstrip('0') ans='' for i in range(len(s)): new_s = s[:i]+s[i+1:] if new_s>ans: ans=new_s print(ans)
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 # your code goes here import math s =input() s=s.lstrip('0') ans='' for i in range(len(s)): new_s = s[:i]+s[i+1:] if new_s>ans: ans=new_s print(ans) ```
0
431
A
Black Square
PROGRAMMING
800
[ "implementation" ]
null
null
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Print a single integer — the total number of calories that Jury wastes.
[ "1 2 3 4\n123214\n", "1 5 3 2\n11221\n" ]
[ "13\n", "13\n" ]
none
500
[ { "input": "1 2 3 4\n123214", "output": "13" }, { "input": "1 5 3 2\n11221", "output": "13" }, { "input": "5 5 5 1\n3422", "output": "16" }, { "input": "4 3 2 1\n2", "output": "3" }, { "input": "5651 6882 6954 4733\n2442313421", "output": "60055" }, { "input": "0 0 0 0\n4132", "output": "0" }, { "input": "3163 5778 83 7640\n11141442444", "output": "64270" }, { "input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442", "output": "420780" }, { "input": "0 0 0 0\n1", "output": "0" }, { "input": "1 2 3 4\n4", "output": "4" }, { "input": "2343 7653 1242 5432\n1", "output": "2343" }, { "input": "2343 7653 1242 5432\n2", "output": "7653" }, { "input": "2343 7653 1242 5432\n3", "output": "1242" }, { "input": "2343 7653 1242 5432\n4", "output": "5432" }, { "input": "1 2 3 4\n123412", "output": "13" }, { "input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111", "output": "2650" }, { "input": "1 2 3 4\n11111111111111111111111111111111111111111111111111", "output": "50" }, { "input": "1 2 3 4\n23123231321231231231231231221232123121312321", "output": "87" }, { "input": "1 2 3 4\n1111111111111222222222233333333333444444444444444", "output": "126" }, { "input": "2 3 1 4\n121321232412342112312313213123123412131231231232", "output": "105" } ]
1,666,158,989
2,147,483,647
PyPy 3-64
OK
TESTS
49
62
1,740,800
a=[*map(int,input().split())] b=input() x=0 for i in b: x+=a[int(i)-1] print(x)
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip. You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? Input Specification: The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104). The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. Output Specification: Print a single integer — the total number of calories that Jury wastes. Demo Input: ['1 2 3 4\n123214\n', '1 5 3 2\n11221\n'] Demo Output: ['13\n', '13\n'] Note: none
```python a=[*map(int,input().split())] b=input() x=0 for i in b: x+=a[int(i)-1] print(x) ```
3
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "NO" }, { "input": "256\n16777217", "output": "NO" }, { "input": "4638\n21511044", "output": "YES\n1" }, { "input": "24\n191102976", "output": "YES\n5" }, { "input": "52010\n557556453", "output": "NO" }, { "input": "61703211\n1750753082", "output": "NO" }, { "input": "137\n2571353", "output": "YES\n2" }, { "input": "8758\n1746157336", "output": "NO" }, { "input": "2\n64", "output": "YES\n5" }, { "input": "96\n884736", "output": "YES\n2" }, { "input": "1094841453\n1656354409", "output": "NO" }, { "input": "1154413\n1229512809", "output": "NO" }, { "input": "2442144\n505226241", "output": "NO" }, { "input": "11548057\n1033418098", "output": "NO" }, { "input": "581\n196122941", "output": "YES\n2" }, { "input": "146\n1913781536", "output": "NO" }, { "input": "945916\n1403881488", "output": "NO" }, { "input": "68269\n365689065", "output": "NO" }, { "input": "30\n900", "output": "YES\n1" }, { "input": "6\n1296", "output": "YES\n3" }, { "input": "1470193122\n1420950405", "output": "NO" }, { "input": "90750\n1793111557", "output": "NO" }, { "input": "1950054\n1664545956", "output": "NO" }, { "input": "6767692\n123762320", "output": "NO" }, { "input": "1437134\n1622348229", "output": "NO" }, { "input": "444103\n1806462642", "output": "NO" }, { "input": "2592\n6718464", "output": "YES\n1" }, { "input": "50141\n366636234", "output": "NO" }, { "input": "835\n582182875", "output": "YES\n2" }, { "input": "156604\n902492689", "output": "NO" }, { "input": "27385965\n1742270058", "output": "NO" }, { "input": "3\n9", "output": "YES\n1" }, { "input": "35\n1838265625", "output": "YES\n5" }, { "input": "8\n4096", "output": "YES\n3" }, { "input": "85955\n945811082", "output": "NO" }, { "input": "54958832\n956670209", "output": "NO" }, { "input": "1475381\n1348159738", "output": "NO" }, { "input": "7313241\n413670642", "output": "NO" }, { "input": "582470\n2116368165", "output": "NO" }, { "input": "26859739\n595086170", "output": "NO" }, { "input": "249766393\n1582130", "output": "NO" }, { "input": "11734\n137686756", "output": "YES\n1" }, { "input": "925093\n1098566745", "output": "NO" }, { "input": "40\n1600", "output": "YES\n1" }, { "input": "2147483647\n2147483647", "output": "YES\n0" }, { "input": "2147483646\n2147483647", "output": "NO" }, { "input": "2147483647\n2147483646", "output": "NO" }, { "input": "2\n2147483647", "output": "NO" }, { "input": "2\n1073741825", "output": "NO" }, { "input": "2\n1073741824", "output": "YES\n29" }, { "input": "10000\n10", "output": "NO" }, { "input": "10\n10000", "output": "YES\n3" }, { "input": "10\n2000000000", "output": "NO" }, { "input": "10\n1000000000", "output": "YES\n8" }, { "input": "5\n1808548329", "output": "NO" }, { "input": "2\n2147483646", "output": "NO" }, { "input": "25\n125", "output": "NO" }, { "input": "6\n18", "output": "NO" }, { "input": "5\n30", "output": "NO" } ]
1,592,822,709
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
186
0
k=int(input()) l=int(input()) flag=0 i=0 while k**i<l: i+=1 if l>k**i: print("NO") else: print('YES') print(i-1)
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. Input Specification: The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). Output Specification: You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. Demo Input: ['5\n25\n', '3\n8\n'] Demo Output: ['YES\n1\n', 'NO\n'] Note: none
```python k=int(input()) l=int(input()) flag=0 i=0 while k**i<l: i+=1 if l>k**i: print("NO") else: print('YES') print(i-1) ```
0
1,008
B
Turn the Rectangles
PROGRAMMING
1,000
[ "greedy", "sortings" ]
null
null
There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles. Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rectangles. Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle.
Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO". You can print each letter in any case (upper or lower).
[ "3\n3 4\n4 6\n3 5\n", "2\n3 4\n5 5\n" ]
[ "YES\n", "NO\n" ]
In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3]. In the second test, there is no way the second rectangle will be not higher than the first one.
1,000
[ { "input": "3\n3 4\n4 6\n3 5", "output": "YES" }, { "input": "2\n3 4\n5 5", "output": "NO" }, { "input": "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 5\n7 9\n9 2\n4 10\n10 1", "output": "NO" }, { "input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 859188055\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685", "output": "NO" }, { "input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n553496707 152702033\n105991807 76314740\n61409204 244301685", "output": "YES" }, { "input": "1\n1 1", "output": "YES" }, { "input": "4\n10 10\n8 8\n8 15\n9 9", "output": "NO" }, { "input": "4\n10 10\n8 8\n8 9\n9 9", "output": "NO" }, { "input": "3\n3 4\n4 5\n5 5", "output": "NO" }, { "input": "3\n10 10\n5 5\n10 10", "output": "NO" }, { "input": "3\n5 5\n4 6\n5 5", "output": "NO" }, { "input": "3\n5 7\n3 9\n8 10", "output": "NO" }, { "input": "3\n10 10\n1 1\n2 2", "output": "NO" }, { "input": "3\n3 5\n1 2\n3 4", "output": "NO" }, { "input": "3\n4 8\n6 25\n12 12", "output": "NO" }, { "input": "3\n3 5\n4 10\n6 6", "output": "NO" }, { "input": "3\n200 200\n300 20\n50 50", "output": "NO" }, { "input": "3\n5 3\n6 4\n5 5", "output": "NO" }, { "input": "4\n5 5\n4 6\n4 4\n5 5", "output": "NO" }, { "input": "3\n10 10\n1 100\n20 20", "output": "NO" }, { "input": "4\n1 3\n2 4\n3 5\n4 6", "output": "NO" }, { "input": "3\n1 60\n70 55\n56 80", "output": "NO" }, { "input": "3\n5 6\n5 7\n6 8", "output": "NO" }, { "input": "3\n6 6\n5 7\n6 6", "output": "NO" } ]
1,678,455,819
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
21
280
0
n=int(input()) c=0 for i in range(n): w,h=map(int,input().split()) if c==0: c=max(w,h) else: if max(w,h)<=c: c=max(w,h) elif min(w,h)<=c: c=max(w,h) else: print('NO') exit(0) print('YES')
Title: Turn the Rectangles Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles. Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such). Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rectangles. Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle. Output Specification: Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO". You can print each letter in any case (upper or lower). Demo Input: ['3\n3 4\n4 6\n3 5\n', '2\n3 4\n5 5\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3]. In the second test, there is no way the second rectangle will be not higher than the first one.
```python n=int(input()) c=0 for i in range(n): w,h=map(int,input().split()) if c==0: c=max(w,h) else: if max(w,h)<=c: c=max(w,h) elif min(w,h)<=c: c=max(w,h) else: print('NO') exit(0) print('YES') ```
0
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, { "input": "7\n3 2 1 6 5 7 4", "output": "8" }, { "input": "8\n2 8 3 7 6 9 1 5", "output": "4" }, { "input": "9\n10 5 9 3 8 7 1 2 4", "output": "6" }, { "input": "10\n7 2 3 8 9 6 5 4 1 10", "output": "11" }, { "input": "1\n1", "output": "2" }, { "input": "2\n1 2", "output": "3" }, { "input": "3\n2 4 1", "output": "3" }, { "input": "4\n4 2 3 1", "output": "5" }, { "input": "5\n3 1 4 2 5", "output": "6" }, { "input": "6\n1 3 6 7 2 4", "output": "5" }, { "input": "7\n1 5 4 7 2 3 6", "output": "8" }, { "input": "8\n12 1 6 5 2 8 3 4", "output": "7" }, { "input": "9\n3 2 7 5 6 4 1 9 10", "output": "8" }, { "input": "10\n1 7 13 6 5 10 3 8 2 4", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n3", "output": "1" }, { "input": "1\n3000", "output": "1" }, { "input": "2\n2 3", "output": "1" }, { "input": "2\n3000 1", "output": "2" } ]
1,596,001,638
2,147,483,647
PyPy 3
OK
TESTS
30
280
21,504,000
n = int(input()) a = list(map(int,input().split())) a.sort() ans, f = 0, 0 if a[0]>1: print(1) else: for i in range(1,n): if a[i]!=(a[i-1]+1): ans = a[i-1]+1 f = 1 break if f==1: print(ans) else: print(a[-1]+1)
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. Output Specification: Output the required default value for the next test index. Demo Input: ['3\n1 7 2\n'] Demo Output: ['3\n'] Note: none
```python n = int(input()) a = list(map(int,input().split())) a.sort() ans, f = 0, 0 if a[0]>1: print(1) else: for i in range(1,n): if a[i]!=(a[i-1]+1): ans = a[i-1]+1 f = 1 break if f==1: print(ans) else: print(a[-1]+1) ```
3.889946
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,657,336,292
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
30
0
nums = [int(a) for a in input().split()] n = nums[0] m = nums[1] a = nums[2] print((n//a) * (m//a))
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 nums = [int(a) for a in input().split()] n = nums[0] m = nums[1] a = nums[2] print((n//a) * (m//a)) ```
0
375
A
Divisible by Seven
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.
The first line contains positive integer *a* in the decimal record. It is guaranteed that the record of number *a* contains digits: 1, 6, 8, 9. Number *a* doesn't contain any leading zeroes. The decimal representation of number *a* contains at least 4 and at most 106 characters.
Print a number in the decimal notation without leading zeroes — the result of the permutation. If it is impossible to rearrange the digits of the number *a* in the required manner, print 0.
[ "1689\n", "18906\n" ]
[ "1869\n", "18690\n" ]
none
500
[ { "input": "1689", "output": "1869" }, { "input": "18906", "output": "18690" }, { "input": "2419323689", "output": "2432391689" }, { "input": "8589157262", "output": "5857221986" }, { "input": "2717172350336955863014903670481525170997949309274087058935108848979319747543008692128164875210350026", "output": "2771723503355630149036704815251709979493092740870589351088489793197475430086921281648752103500261986" }, { "input": "9825995656040286793128006047268547610068699214477842995873286607346639816314908021369221299622234988", "output": "2599556040286793280060472685476100686992144778429958732866073466398163149080213692212996222349881968" }, { "input": "100000000689", "output": "186900000000" }, { "input": "16891", "output": "16198" }, { "input": "16892", "output": "21896" }, { "input": "16893", "output": "31689" }, { "input": "16894", "output": "41986" }, { "input": "16895", "output": "51968" }, { "input": "16896", "output": "61698" }, { "input": "16897", "output": "71869" }, { "input": "16898", "output": "86198" }, { "input": "16899", "output": "91896" }, { "input": "4048169", "output": "4041968" }, { "input": "10994168", "output": "94116890" }, { "input": "168903", "output": "316890" }, { "input": "11689", "output": "16198" }, { "input": "91111168", "output": "11111968" }, { "input": "16890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "18690000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1689999999999", "output": "9999999991968" }, { "input": "9883291673084", "output": "8329730841698" }, { "input": "6198", "output": "1869" } ]
1,613,935,531
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
13,824,000
#prefix = [1869,6189,1689,6198,1698,9861,1896] # 0 5 3 1 6 4 2 prefix = ["1869", "6198", "1896", "1689", "9861", "6189","1698"] strs = input() dicts = {} for i in strs: if i not in dicts: dicts[i] = 1 else: dicts[i] += 1 left = [] right = [] if "0" in dicts: for i in range(dicts["0"]): right.append("0") del dicts["0"] for key, value in dicts.items(): if key == "1" or key == "6" or key == "8" or key == "9": value -= 1 for i in range(value): left.append(key) # print(dicts) # print(left) left = sorted(left) # print(left) leftstr = "".join(left) if len(left) == 0 and len(right) == 0 : print(1869) elif len(left) == 0 : print(str(1869) + "0" * len(right) ) elif len(right) == 0 : leftnum= int(leftstr) rem = leftnum % 7 print(leftstr + prefix[rem]) else: leftnum= int(leftstr) rem = leftnum % 7 ans = leftstr + prefix[rem] + "0" * len(right) print(ans)
Title: Divisible by Seven Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes. Input Specification: The first line contains positive integer *a* in the decimal record. It is guaranteed that the record of number *a* contains digits: 1, 6, 8, 9. Number *a* doesn't contain any leading zeroes. The decimal representation of number *a* contains at least 4 and at most 106 characters. Output Specification: Print a number in the decimal notation without leading zeroes — the result of the permutation. If it is impossible to rearrange the digits of the number *a* in the required manner, print 0. Demo Input: ['1689\n', '18906\n'] Demo Output: ['1869\n', '18690\n'] Note: none
```python #prefix = [1869,6189,1689,6198,1698,9861,1896] # 0 5 3 1 6 4 2 prefix = ["1869", "6198", "1896", "1689", "9861", "6189","1698"] strs = input() dicts = {} for i in strs: if i not in dicts: dicts[i] = 1 else: dicts[i] += 1 left = [] right = [] if "0" in dicts: for i in range(dicts["0"]): right.append("0") del dicts["0"] for key, value in dicts.items(): if key == "1" or key == "6" or key == "8" or key == "9": value -= 1 for i in range(value): left.append(key) # print(dicts) # print(left) left = sorted(left) # print(left) leftstr = "".join(left) if len(left) == 0 and len(right) == 0 : print(1869) elif len(left) == 0 : print(str(1869) + "0" * len(right) ) elif len(right) == 0 : leftnum= int(leftstr) rem = leftnum % 7 print(leftstr + prefix[rem]) else: leftnum= int(leftstr) rem = leftnum % 7 ans = leftstr + prefix[rem] + "0" * len(right) print(ans) ```
0
886
B
Vlad and Cafes
PROGRAMMING
1,000
[]
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.
1,000
[ { "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,696,340,596
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
0
n = int(input()) a = list(map(int, input().split())) s = set(a) for i in range(len(a) -1, -1, -1): if a[i] in s: s.remove(a[i]) elif a[i] == a[i+1]: continue else: print(i+1) break
Title: Vlad and Cafes 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 n = int(input()) a = list(map(int, input().split())) s = set(a) for i in range(len(a) -1, -1, -1): if a[i] in s: s.remove(a[i]) elif a[i] == a[i+1]: continue else: print(i+1) break ```
0
304
A
Pythagorean Theorem II
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation: where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides. Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*.
The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above.
Print a single integer — the answer to the problem.
[ "5\n", "74\n" ]
[ "1\n", "35\n" ]
none
500
[ { "input": "5", "output": "1" }, { "input": "74", "output": "35" }, { "input": "1000", "output": "881" }, { "input": "586", "output": "472" }, { "input": "2", "output": "0" }, { "input": "362", "output": "258" }, { "input": "778", "output": "653" }, { "input": "194", "output": "120" }, { "input": "906", "output": "786" }, { "input": "659", "output": "535" }, { "input": "75", "output": "37" }, { "input": "787", "output": "664" }, { "input": "851", "output": "730" }, { "input": "563", "output": "446" }, { "input": "979", "output": "862" }, { "input": "395", "output": "291" }, { "input": "755", "output": "634" }, { "input": "171", "output": "103" }, { "input": "883", "output": "759" }, { "input": "400", "output": "294" }, { "input": "817", "output": "693" }, { "input": "177", "output": "107" }, { "input": "593", "output": "476" }, { "input": "305", "output": "214" }, { "input": "721", "output": "595" }, { "input": "785", "output": "664" }, { "input": "497", "output": "383" }, { "input": "913", "output": "791" }, { "input": "625", "output": "507" }, { "input": "334", "output": "236" }, { "input": "10000", "output": "12471" }, { "input": "9999", "output": "12467" } ]
1,697,047,265
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
import java.util.Scanner; public class even_odd { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int count = 0; for (int i = 1; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { int req = i * i + j * j; int req1 = (int)Math.sqrt(req); if (req1*req1==req && req1<= n) { count = count + 1; } } } System.out.print(count); } }
Title: Pythagorean Theorem II Time Limit: None seconds Memory Limit: None megabytes Problem Description: In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation: where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides. Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*. Input Specification: The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['5\n', '74\n'] Demo Output: ['1\n', '35\n'] Note: none
```python import java.util.Scanner; public class even_odd { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int count = 0; for (int i = 1; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { int req = i * i + j * j; int req1 = (int)Math.sqrt(req); if (req1*req1==req && req1<= n) { count = count + 1; } } } System.out.print(count); } } ```
-1
0
none
none
none
0
[ "none" ]
null
null
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively.
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps.
[ "5 2\n", "1 10\n" ]
[ "10\n", "0\n" ]
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0.
0
[ { "input": "5 2", "output": "10" }, { "input": "1 10", "output": "0" }, { "input": "100000 2", "output": "399990" }, { "input": "1 1", "output": "0" }, { "input": "8 3", "output": "27" }, { "input": "7 1", "output": "11" }, { "input": "100000 40000", "output": "4799960000" }, { "input": "1 1000", "output": "0" }, { "input": "100 45", "output": "4905" }, { "input": "9 2", "output": "26" }, { "input": "456 78", "output": "58890" }, { "input": "100000 50000", "output": "4999950000" }, { "input": "100000 50001", "output": "4999950000" }, { "input": "100000 50002", "output": "4999950000" }, { "input": "100000 50003", "output": "4999950000" }, { "input": "100000 49998", "output": "4999949994" }, { "input": "100000 49997", "output": "4999949985" }, { "input": "99999 49998", "output": "4999849998" }, { "input": "99999 49997", "output": "4999849991" }, { "input": "99999 49996", "output": "4999849980" }, { "input": "99999 50000", "output": "4999850001" }, { "input": "99999 50001", "output": "4999850001" }, { "input": "99999 50002", "output": "4999850001" }, { "input": "30062 9", "output": "540945" }, { "input": "13486 3", "output": "80895" }, { "input": "29614 7", "output": "414491" }, { "input": "13038 8", "output": "208472" }, { "input": "96462 6", "output": "1157466" }, { "input": "22599 93799", "output": "255346101" }, { "input": "421 36817", "output": "88410" }, { "input": "72859 65869", "output": "2654180511" }, { "input": "37916 5241", "output": "342494109" }, { "input": "47066 12852", "output": "879423804" }, { "input": "84032 21951", "output": "2725458111" }, { "input": "70454 75240", "output": "2481847831" }, { "input": "86946 63967", "output": "3779759985" }, { "input": "71128 11076", "output": "1330260828" }, { "input": "46111 64940", "output": "1063089105" }, { "input": "46111 64940", "output": "1063089105" }, { "input": "56500 84184", "output": "1596096750" }, { "input": "60108 83701", "output": "1806455778" }, { "input": "1 2", "output": "0" }, { "input": "1 3", "output": "0" }, { "input": "1 4", "output": "0" }, { "input": "1 5", "output": "0" }, { "input": "1 6", "output": "0" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "2 3", "output": "1" }, { "input": "2 4", "output": "1" }, { "input": "2 5", "output": "1" }, { "input": "3 1", "output": "3" }, { "input": "3 2", "output": "3" }, { "input": "3 3", "output": "3" }, { "input": "3 4", "output": "3" }, { "input": "3 5", "output": "3" }, { "input": "4 1", "output": "5" }, { "input": "4 2", "output": "6" }, { "input": "4 3", "output": "6" }, { "input": "4 4", "output": "6" }, { "input": "4 5", "output": "6" }, { "input": "5 1", "output": "7" }, { "input": "5 3", "output": "10" }, { "input": "5 4", "output": "10" }, { "input": "5 5", "output": "10" }, { "input": "6 1", "output": "9" }, { "input": "6 2", "output": "14" }, { "input": "6 3", "output": "15" }, { "input": "7 2", "output": "18" }, { "input": "7 3", "output": "21" }, { "input": "7 4", "output": "21" }, { "input": "10 2", "output": "30" }, { "input": "60982 2", "output": "243918" }, { "input": "23426 23", "output": "1076515" }, { "input": "444 3", "output": "2643" }, { "input": "18187 433", "output": "15374531" }, { "input": "6895 3544", "output": "23767065" }, { "input": "56204 22352", "output": "1513297456" }, { "input": "41977 5207", "output": "382917573" }, { "input": "78147 2321", "output": "351981971" }, { "input": "99742 62198", "output": "4974183411" }, { "input": "72099 38339", "output": "2599096851" }, { "input": "82532 4838", "output": "751762306" }, { "input": "79410 33144", "output": "3066847464" }, { "input": "11021 3389", "output": "51726307" }, { "input": "66900 7572", "output": "898455660" }, { "input": "99999 49999", "output": "4999850001" }, { "input": "100000 49999", "output": "4999949999" }, { "input": "100000 100000", "output": "4999950000" }, { "input": "100000 1", "output": "199997" }, { "input": "4 100", "output": "6" }, { "input": "100000 1234", "output": "243753254" } ]
1,464,935,891
2,147,483,647
Python 3
OK
TESTS
92
62
4,812,800
n,k = [int(i) for i in input().split()] if n == 1: print(0) elif k>=(n//2): print(((n*(n-1))//2)) else: print(2*(n-k)*k-k)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. Output Specification: Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. Demo Input: ['5 2\n', '1 10\n'] Demo Output: ['10\n', '0\n'] Note: In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0.
```python n,k = [int(i) for i in input().split()] if n == 1: print(0) elif k>=(n//2): print(((n*(n-1))//2)) else: print(2*(n-k)*k-k) ```
3
499
A
Watching a movie
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?
The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*.
Output a single number — the answer to the problem.
[ "2 3\n5 6\n10 12\n", "1 1\n1 100000\n" ]
[ "6\n", "100000\n" ]
In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
500
[ { "input": "2 3\n5 6\n10 12", "output": "6" }, { "input": "1 1\n1 100000", "output": "100000" }, { "input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53974" }, { "input": "10 3\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53983" }, { "input": "10 10\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "54038" }, { "input": "10 1000\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "58728" }, { "input": "12 14\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41870" }, { "input": "12 17\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41872" }, { "input": "18 111\n1449 2156\n3497 4784\n7775 14575\n23857 24593\n29211 30739\n31932 33447\n35902 36426\n36991 38506\n39679 47202\n48772 60016\n60522 61868\n63340 63982\n68417 78537\n79445 86568\n86918 87940\n90081 90310\n90629 94325\n95728 96263", "output": "58967" }, { "input": "1 1\n14575 60522", "output": "45948" }, { "input": "1 10\n14575 60522", "output": "45952" }, { "input": "2 10\n14575 36426\n60522 79445", "output": "40785" }, { "input": "3 1\n14575 36426\n48772 60522\n79445 90081", "output": "44240" }, { "input": "1 100000\n1 100000", "output": "100000" }, { "input": "1 2\n2 100000", "output": "100000" }, { "input": "1 3\n4 100000", "output": "99997" }, { "input": "2 100\n5 6\n7 7", "output": "7" }, { "input": "1 10000\n500 600", "output": "600" }, { "input": "2 3\n1 3\n4 8", "output": "8" }, { "input": "3 1\n1 2\n3 4\n6 7", "output": "6" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 3\n5 6", "output": "3" }, { "input": "1 5\n7 10", "output": "5" }, { "input": "1 100\n5 6", "output": "6" }, { "input": "1 2\n1 1", "output": "1" }, { "input": "1 100000\n100000 100000", "output": "100000" }, { "input": "2 3\n1 1\n5 6", "output": "3" } ]
1,594,468,609
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
124
20,172,800
n , x = map(int,input().split()) ans = 0 curm = 1 for i in range(n): l , r = map(int,input().split()) if curm + x <= l : l = curm + x ans += r - l + 1 curm = r + 1 else: ans += r - curm + 1 curm = r + 1 print(ans)
Title: Watching a movie Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments? Input Specification: The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*. Output Specification: Output a single number — the answer to the problem. Demo Input: ['2 3\n5 6\n10 12\n', '1 1\n1 100000\n'] Demo Output: ['6\n', '100000\n'] Note: In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
```python n , x = map(int,input().split()) ans = 0 curm = 1 for i in range(n): l , r = map(int,input().split()) if curm + x <= l : l = curm + x ans += r - l + 1 curm = r + 1 else: ans += r - curm + 1 curm = r + 1 print(ans) ```
0
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "output": "-1" }, { "input": "1000000000000000 1000000000", "output": "-1" }, { "input": "1000000000000000 100", "output": "1953125" }, { "input": "1 2", "output": "-1" }, { "input": "4 3", "output": "4" }, { "input": "4 4", "output": "-1" }, { "input": "9 3", "output": "9" }, { "input": "21 3", "output": "7" }, { "input": "67280421310721 1", "output": "1" }, { "input": "6 3", "output": "3" }, { "input": "3 3", "output": "-1" }, { "input": "16 3", "output": "4" }, { "input": "1 1000", "output": "-1" }, { "input": "16 4", "output": "8" }, { "input": "36 8", "output": "18" }, { "input": "49 4", "output": "-1" }, { "input": "9 4", "output": "-1" }, { "input": "16 1", "output": "1" }, { "input": "16 6", "output": "-1" }, { "input": "16 5", "output": "16" }, { "input": "25 4", "output": "-1" }, { "input": "4010815561 2", "output": "63331" }, { "input": "49 3", "output": "49" }, { "input": "36 6", "output": "9" }, { "input": "36 10", "output": "-1" }, { "input": "25 3", "output": "25" }, { "input": "22876792454961 28", "output": "7625597484987" }, { "input": "1234 2", "output": "2" }, { "input": "179458711 2", "output": "179458711" }, { "input": "900104343024121 100000", "output": "-1" }, { "input": "8 3", "output": "4" }, { "input": "100 6", "output": "20" }, { "input": "15500 26", "output": "-1" }, { "input": "111111 1", "output": "1" }, { "input": "100000000000000 200", "output": "160000000000" }, { "input": "1000000000000 100", "output": "6400000" }, { "input": "100 10", "output": "-1" }, { "input": "1000000000039 2", "output": "1000000000039" }, { "input": "64 5", "output": "16" }, { "input": "999999961946176 33", "output": "63245552" }, { "input": "376219076689 3", "output": "376219076689" }, { "input": "999999961946176 63", "output": "999999961946176" }, { "input": "1048576 12", "output": "2048" }, { "input": "745 21", "output": "-1" }, { "input": "748 6", "output": "22" }, { "input": "999999961946176 50", "output": "161082468097" }, { "input": "10 3", "output": "5" }, { "input": "1099511627776 22", "output": "2097152" }, { "input": "1000000007 100010", "output": "-1" }, { "input": "3 1", "output": "1" }, { "input": "100 8", "output": "50" }, { "input": "100 7", "output": "25" }, { "input": "7 2", "output": "7" }, { "input": "999999961946176 64", "output": "-1" }, { "input": "20 5", "output": "10" }, { "input": "999999999999989 2", "output": "999999999999989" }, { "input": "100000000000000 114", "output": "10240000" }, { "input": "99999640000243 3", "output": "9999991" }, { "input": "999998000001 566", "output": "333332666667" }, { "input": "99999820000081 2", "output": "9999991" }, { "input": "49000042000009 3", "output": "49000042000009" }, { "input": "151491429961 4", "output": "-1" }, { "input": "32416190071 2", "output": "32416190071" }, { "input": "1000 8", "output": "25" }, { "input": "1999967841 15", "output": "1999967841" }, { "input": "26880 26880", "output": "-1" }, { "input": "151491429961 3", "output": "151491429961" }, { "input": "90000000000 300", "output": "100000000" }, { "input": "98765004361 10", "output": "-1" }, { "input": "15 2", "output": "3" }, { "input": "16 2", "output": "2" }, { "input": "1996 2", "output": "2" }, { "input": "1997 2", "output": "1997" }, { "input": "1999 2", "output": "1999" }, { "input": "1998 2", "output": "2" }, { "input": "1998 1", "output": "1" }, { "input": "1998 7", "output": "27" }, { "input": "1998 8", "output": "37" }, { "input": "100000380000361 2", "output": "10000019" }, { "input": "15 1", "output": "1" }, { "input": "100000000000000 226", "output": "-1" }, { "input": "844030857550613 517", "output": "-1" }, { "input": "4567890 14", "output": "430" }, { "input": "123123123 123123123", "output": "-1" }, { "input": "24 4", "output": "4" }, { "input": "999999993568952 17", "output": "31622777" }, { "input": "99999999994190 9", "output": "241656799" }, { "input": "999997874844049 4", "output": "-1" }, { "input": "99999999999931 2", "output": "99999999999931" }, { "input": "2 3", "output": "-1" }, { "input": "67280421310721 2", "output": "67280421310721" } ]
1,625,865,735
2,147,483,647
PyPy 3
OK
TESTS
96
1,045
11,673,600
import sys input = sys.stdin.readline def I(): return input().strip() def II(): return int(input().strip()) def LI(): return [*map(int, input().strip().split())] import copy import re import string, math, time, functools, random, fractions from heapq import heappush, heappop, heapify from bisect import bisect_left, bisect_right from collections import deque, defaultdict, Counter, OrderedDict from itertools import permutations, combinations, groupby, count, filterfalse from operator import itemgetter for _ in range(1): n,k = LI() l = [] import math def printDivisors(n): list = [] for i in range(1, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): list.append(i) else: list.append(i) list.append(int(n / i)) return list z = printDivisors(n) z.sort() x = len(z) if k > x: print(-1) else: print(z[k - 1])
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). Output Specification: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Demo Input: ['4 2\n', '5 3\n', '12 5\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
```python import sys input = sys.stdin.readline def I(): return input().strip() def II(): return int(input().strip()) def LI(): return [*map(int, input().strip().split())] import copy import re import string, math, time, functools, random, fractions from heapq import heappush, heappop, heapify from bisect import bisect_left, bisect_right from collections import deque, defaultdict, Counter, OrderedDict from itertools import permutations, combinations, groupby, count, filterfalse from operator import itemgetter for _ in range(1): n,k = LI() l = [] import math def printDivisors(n): list = [] for i in range(1, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): list.append(i) else: list.append(i) list.append(int(n / i)) return list z = printDivisors(n) z.sort() x = len(z) if k > x: print(-1) else: print(z[k - 1]) ```
3
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,662,201,018
2,147,483,647
Python 3
OK
TESTS
20
46
0
n,m,a=map(int,input().split()) if n%a!=0: p=(n//a)+1 else: p=n//a if m%a!=0: l=(m//a)+1 else: l=m//a print(p*l)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n,m,a=map(int,input().split()) if n%a!=0: p=(n//a)+1 else: p=n//a if m%a!=0: l=(m//a)+1 else: l=m//a print(p*l) ```
3.977
545
D
Queue
PROGRAMMING
1,300
[ "greedy", "implementation", "sortings" ]
null
null
Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces.
Print a single number — the maximum number of not disappointed people in the queue.
[ "5\n15 2 1 5 3\n" ]
[ "4\n" ]
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.
1,750
[ { "input": "5\n15 2 1 5 3", "output": "4" }, { "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10\n13 2 5 55 21 34 1 8 1 3", "output": "6" }, { "input": "10\n8 256 16 1 2 1 64 4 128 32", "output": "10" }, { "input": "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500", "output": "6" }, { "input": "1\n1000000000", "output": "1" }, { "input": "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39", "output": "6" }, { "input": "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 6994983 67700784 16562412 82163675 46178521 33914268 91966607 93976858 84100064", "output": "5" }, { "input": "26\n1000 4110030 64221 131521030 942374833 1003 2055015 32110 513757 16440130 263042057 32880256 128439 557559573 16051 8220066 469240078 65760513 256878 790176315 4012 2005 1027508 928528684 8030 805074697", "output": "21" } ]
1,698,139,424
2,147,483,647
Python 3
OK
TESTS
61
109
13,619,200
input() l = list(map(int, input().split())) l.sort() sums = 0 cnt = 0 for i in l: if i >= sums: cnt += 1 sums += i print(cnt)
Title: Queue Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. Output Specification: Print a single number — the maximum number of not disappointed people in the queue. Demo Input: ['5\n15 2 1 5 3\n'] Demo Output: ['4\n'] Note: Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.
```python input() l = list(map(int, input().split())) l.sort() sums = 0 cnt = 0 for i in l: if i >= sums: cnt += 1 sums += i print(cnt) ```
3
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B.
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input": "A>B\nB>C\nC<A", "output": "CBA" }, { "input": "A>C\nA>B\nB<C", "output": "BCA" }, { "input": "C<B\nB>A\nA<C", "output": "ACB" }, { "input": "C<B\nA>B\nC<A", "output": "CBA" }, { "input": "C>B\nB>A\nA<C", "output": "ABC" }, { "input": "C<B\nB<A\nC>A", "output": "Impossible" }, { "input": "B<C\nC<A\nA>B", "output": "BCA" }, { "input": "A>B\nC<B\nC<A", "output": "CBA" }, { "input": "B>A\nC>B\nA>C", "output": "Impossible" }, { "input": "B<A\nC>B\nC>A", "output": "BAC" }, { "input": "A<B\nC>B\nA<C", "output": "ABC" }, { "input": "A<B\nC<A\nB<C", "output": "Impossible" }, { "input": "A>C\nC<B\nB>A", "output": "CAB" }, { "input": "C>A\nA<B\nB>C", "output": "ACB" }, { "input": "C>A\nC<B\nB>A", "output": "ACB" }, { "input": "B>C\nB>A\nA<C", "output": "ACB" }, { "input": "C<B\nC<A\nB<A", "output": "CBA" }, { "input": "A<C\nA<B\nB>C", "output": "ACB" }, { "input": "B>A\nA>C\nB>C", "output": "CAB" }, { "input": "B<A\nA<C\nC<B", "output": "Impossible" }, { "input": "A<C\nB>C\nA>B", "output": "Impossible" }, { "input": "B>A\nC<A\nC>B", "output": "Impossible" }, { "input": "A>C\nC>B\nB<A", "output": "BCA" }, { "input": "B<C\nB<A\nA>C", "output": "BCA" }, { "input": "A>B\nC>B\nA<C", "output": "BAC" }, { "input": "C<B\nC<A\nB<A", "output": "CBA" }, { "input": "A<C\nA>B\nB>C", "output": "Impossible" }, { "input": "B>A\nB>C\nA<C", "output": "ACB" }, { "input": "B>C\nC<A\nB<A", "output": "CBA" }, { "input": "C>A\nB>A\nB>C", "output": "ACB" }, { "input": "B<A\nB>C\nA<C", "output": "Impossible" }, { "input": "B<C\nA<B\nC>A", "output": "ABC" }, { "input": "C<B\nB>A\nA>C", "output": "CAB" }, { "input": "A>B\nC>A\nB<C", "output": "BAC" }, { "input": "A>B\nB>C\nC<A", "output": "CBA" }, { "input": "B>C\nC>A\nA>B", "output": "Impossible" }, { "input": "B<A\nB>C\nC<A", "output": "CBA" }, { "input": "C>B\nB>A\nC>A", "output": "ABC" }, { "input": "A>C\nA>B\nB>C", "output": "CBA" }, { "input": "B<C\nA>B\nA<C", "output": "BAC" }, { "input": "C>A\nC<B\nB>A", "output": "ACB" }, { "input": "C>B\nA<B\nC<A", "output": "Impossible" }, { "input": "A<C\nC<B\nA>B", "output": "Impossible" }, { "input": "B>C\nA<B\nA<C", "output": "ACB" }, { "input": "C>A\nA<B\nC>B", "output": "ABC" } ]
1,688,764,732
2,147,483,647
Python 3
OK
TESTS
50
62
0
my_dict = {'A' : 0, 'B' : 0, 'C' : 0} for _ in range(3): a = input() if a[1] == '>': my_dict[a[0]] += 1 else: my_dict[a[2]] += 1 ans = set() res = ['', '', ''] for key, value in my_dict.items(): if value in ans: print("Impossible") break else: ans.add(value) else: for key, value in my_dict.items(): res[value] += key print(''.join(res))
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. Input Specification: The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B. Output Specification: It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. Demo Input: ['A&gt;B\nC&lt;B\nA&gt;C\n', 'A&lt;B\nB&gt;C\nC&gt;A\n'] Demo Output: ['CBA', 'ACB'] Note: none
```python my_dict = {'A' : 0, 'B' : 0, 'C' : 0} for _ in range(3): a = input() if a[1] == '>': my_dict[a[0]] += 1 else: my_dict[a[2]] += 1 ans = set() res = ['', '', ''] for key, value in my_dict.items(): if value in ans: print("Impossible") break else: ans.add(value) else: for key, value in my_dict.items(): res[value] += key print(''.join(res)) ```
3.9845
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,694,888,271
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
77
2,867,200
while True: n = int(input()) if n in range(1, 101): break for i in range(n): while True: w = input() if len(w) <= 10: print(w) else: print(w[0], len(w) - 2, w[-1], sep='')
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python while True: n = int(input()) if n in range(1, 101): break for i in range(n): while True: w = input() if len(w) <= 10: print(w) else: print(w[0], len(w) - 2, w[-1], sep='') ```
-1
165
B
Burning Midnight Oil
PROGRAMMING
1,500
[ "binary search", "implementation" ]
null
null
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ... The expression is regarded as the integral part from dividing number *a* by number *b*. The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished. Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep.
The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10.
Print the only integer — the minimum value of *v* that lets Vasya write the program in one night.
[ "7 2\n", "59 9\n" ]
[ "4\n", "54\n" ]
In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task. In the second sample the answer is *v* = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than *n* = 59.
1,000
[ { "input": "7 2", "output": "4" }, { "input": "59 9", "output": "54" }, { "input": "1 9", "output": "1" }, { "input": "11 2", "output": "7" }, { "input": "747 2", "output": "376" }, { "input": "6578 2", "output": "3293" }, { "input": "37212 2", "output": "18609" }, { "input": "12357 2", "output": "6181" }, { "input": "7998332 2", "output": "3999172" }, { "input": "86275251 2", "output": "43137632" }, { "input": "75584551 2", "output": "37792280" }, { "input": "6 3", "output": "5" }, { "input": "43 4", "output": "33" }, { "input": "811 3", "output": "543" }, { "input": "3410 4", "output": "2560" }, { "input": "21341 4", "output": "16009" }, { "input": "696485 4", "output": "522368" }, { "input": "8856748 3", "output": "5904504" }, { "input": "2959379 4", "output": "2219538" }, { "input": "831410263 3", "output": "554273516" }, { "input": "2 5", "output": "2" }, { "input": "19 6", "output": "17" }, { "input": "715 7", "output": "615" }, { "input": "9122 5", "output": "7300" }, { "input": "89117 6", "output": "74268" }, { "input": "689973 7", "output": "591408" }, { "input": "3024524 5", "output": "2419624" }, { "input": "67127156 6", "output": "55939302" }, { "input": "412262167 7", "output": "353367574" }, { "input": "6 8", "output": "6" }, { "input": "59 9", "output": "54" }, { "input": "246 10", "output": "222" }, { "input": "5314 8", "output": "4651" }, { "input": "15309 9", "output": "13609" }, { "input": "35648 10", "output": "32085" }, { "input": "3018012 8", "output": "2640764" }, { "input": "92153348 9", "output": "81914089" }, { "input": "177583558 10", "output": "159825206" }, { "input": "1000000000 2", "output": "500000008" }, { "input": "1000000000 3", "output": "666666672" }, { "input": "1000000000 4", "output": "750000005" }, { "input": "1000000000 5", "output": "800000003" }, { "input": "1000000000 6", "output": "833333338" }, { "input": "1000000000 7", "output": "857142861" }, { "input": "1000000000 8", "output": "875000004" }, { "input": "1000000000 9", "output": "888888894" }, { "input": "1000000000 10", "output": "900000001" }, { "input": "1 4", "output": "1" }, { "input": "2 10", "output": "2" }, { "input": "1 2", "output": "1" }, { "input": "6 8", "output": "6" }, { "input": "987862820 9", "output": "878100288" }, { "input": "979591791 9", "output": "870748262" }, { "input": "948889213 9", "output": "843457081" }, { "input": "8 9", "output": "8" }, { "input": "999999999 10", "output": "900000000" } ]
1,635,573,357
2,147,483,647
PyPy 3-64
OK
TESTS
56
218
34,611,200
from collections import defaultdict, Counter from queue import PriorityQueue, Queue import math def getLines(n, k) : ans = 0 p = 1 while p <= n : ans += n // p p *= k return ans n, k= map(int, input().split()) l, h = 1, n while l <= h : mid = (l + h) // 2 x = getLines(mid, k) #print(l, h, mid, x) if x == n : break elif x > n : h = mid - 1 else : l = mid + 1 if l <= h : print((l + h) // 2) else : print(l)
Title: Burning Midnight Oil Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ... The expression is regarded as the integral part from dividing number *a* by number *b*. The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished. Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep. Input Specification: The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10. Output Specification: Print the only integer — the minimum value of *v* that lets Vasya write the program in one night. Demo Input: ['7 2\n', '59 9\n'] Demo Output: ['4\n', '54\n'] Note: In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task. In the second sample the answer is *v* = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than *n* = 59.
```python from collections import defaultdict, Counter from queue import PriorityQueue, Queue import math def getLines(n, k) : ans = 0 p = 1 while p <= n : ans += n // p p *= k return ans n, k= map(int, input().split()) l, h = 1, n while l <= h : mid = (l + h) // 2 x = getLines(mid, k) #print(l, h, mid, x) if x == n : break elif x > n : h = mid - 1 else : l = mid + 1 if l <= h : print((l + h) // 2) else : print(l) ```
3
203
C
Photographer
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's memory is *d* megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes *a* megabytes of memory, one high quality photo take *b* megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the *i*-th client asks to make *x**i* low quality photos and *y**i* high quality photos. Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the *i*-th client, Valera needs to give him everything he wants, that is, to make *x**i* low quality photos and *y**i* high quality photos. To make one low quality photo, the camera must have at least *a* megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least *b* megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up. Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*d*<=≤<=109) — the number of clients and the camera memory size, correspondingly. The second line contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=104) — the size of one low quality photo and of one high quality photo, correspondingly. Next *n* lines describe the clients. The *i*-th line contains two integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=105) — the number of low quality photos and high quality photos the *i*-th client wants, correspondingly. All numbers on all lines are separated by single spaces.
On the first line print the answer to the problem — the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
[ "3 10\n2 3\n1 4\n2 1\n1 0\n", "3 6\n6 6\n1 1\n1 0\n1 0\n" ]
[ "2\n3 2 ", "1\n2 " ]
none
1,500
[ { "input": "3 10\n2 3\n1 4\n2 1\n1 0", "output": "2\n3 2 " }, { "input": "3 6\n6 6\n1 1\n1 0\n1 0", "output": "1\n2 " }, { "input": "4 5\n6 8\n1 2\n3 0\n10 2\n0 4", "output": "0" }, { "input": "4 10\n6 6\n1 2\n2 2\n0 0\n0 0", "output": "2\n3 4 " }, { "input": "10 10\n1 1\n0 3\n6 4\n3 3\n6 3\n5 2\n6 4\n1 3\n5 5\n2 6\n6 4", "output": "2\n1 7 " }, { "input": "5 5\n1 1\n2 0\n3 2\n4 4\n10 0\n0 1", "output": "2\n5 1 " }, { "input": "4 10\n1 2\n1 0\n0 0\n2 0\n1 3", "output": "4\n2 1 3 4 " }, { "input": "1 22\n3 5\n1 3", "output": "1\n1 " }, { "input": "10 20\n3 5\n3 0\n0 3\n1 2\n1 3\n1 1\n3 0\n0 3\n0 3\n3 1\n3 1", "output": "2\n5 1 " }, { "input": "10 50\n1 1\n7 10\n6 6\n1 0\n2 5\n2 6\n9 7\n3 5\n7 6\n7 10\n7 7", "output": "6\n3 4 5 7 2 8 " }, { "input": "15 30\n13 19\n10 20\n9 0\n11 15\n10 8\n18 3\n13 15\n2 14\n9 16\n8 4\n13 10\n19 2\n13 19\n6 17\n16 4\n15 6", "output": "0" }, { "input": "30 50\n1 3\n2 2\n3 2\n3 3\n0 1\n0 2\n1 3\n1 3\n1 1\n0 1\n0 2\n1 3\n1 0\n1 0\n2 1\n0 1\n0 0\n0 3\n2 3\n2 2\n0 1\n2 3\n2 3\n0 3\n0 3\n3 3\n1 2\n2 1\n1 3\n3 1\n0 3", "output": "13\n16 12 13 4 9 15 20 8 14 27 5 10 29 " }, { "input": "50 50\n6 10\n10 0\n1 9\n8 2\n4 9\n0 7\n2 0\n7 5\n4 8\n10 7\n2 4\n5 6\n6 8\n3 2\n4 6\n7 8\n6 9\n7 7\n7 3\n9 5\n3 10\n7 2\n4 3\n2 0\n6 5\n5 3\n1 7\n1 7\n9 1\n10 4\n10 5\n4 2\n10 10\n0 7\n1 2\n10 1\n1 7\n3 7\n8 7\n5 2\n6 1\n3 1\n4 7\n7 10\n1 5\n10 8\n5 5\n5 1\n3 3\n1 6\n2 1", "output": "3\n6 23 50 " }, { "input": "1 100\n6 10\n14 19", "output": "0" }, { "input": "2 160\n6 9\n11 9\n6 6", "output": "1\n2 " }, { "input": "2 1000000000\n10000 10000\n50000 50000\n100000 100000", "output": "1\n1 " }, { "input": "2 1000000000\n10000 10000\n100000 0\n100000 100000", "output": "1\n1 " }, { "input": "1 1000000000\n1 1\n1 1", "output": "1\n1 " }, { "input": "6 1000000000\n9999 10000\n10000 9998\n10000 10000\n10000 10000\n70000 70000\n10000 10000\n10000 10000", "output": "5\n1 2 3 5 6 " }, { "input": "3 10\n1 10\n0 1\n3 0\n3 0", "output": "2\n2 3 " }, { "input": "2 1000000000\n10000 10000\n0 100000\n100000 100000", "output": "1\n1 " }, { "input": "3 3\n1 1\n3 0\n1 0\n1 0", "output": "2\n2 3 " }, { "input": "2 1000000000\n10000 10000\n100000 100000\n50000 50000", "output": "1\n2 " }, { "input": "2 1000000000\n10000 10000\n0 90000\n100000 100000", "output": "1\n1 " }, { "input": "3 1000000000\n10000 10000\n100000 0\n100000 100000\n0 0", "output": "2\n3 1 " }, { "input": "2 1000000000\n10000 10000\n10000 10000\n100000 100000", "output": "1\n1 " }, { "input": "2 1000000000\n10000 10000\n100000 100000\n100000 0", "output": "1\n2 " }, { "input": "3 1000000000\n10000 10000\n99999 0\n100000 100000\n100000 100000", "output": "1\n1 " } ]
1,650,456,015
2,147,483,647
PyPy 3-64
OK
TESTS
54
654
28,160,000
import sys input = sys.stdin.readline class Order: def __init__(self, n, cost): self.number = n self.cost = cost n, storage = map(int, input().split()) a, b = map(int, input().split()) orders = [] for i in range(n): x, y = map(int, input().split()) orders.append(Order(i + 1, x * a + y * b)) orders.sort(key=lambda a: a.cost) s = [] number = 0 for order in orders: if storage - order.cost >= 0: number += 1 storage = storage - order.cost s.append(order.number) else: break print(number) print(*s)
Title: Photographer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's memory is *d* megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes *a* megabytes of memory, one high quality photo take *b* megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the *i*-th client asks to make *x**i* low quality photos and *y**i* high quality photos. Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the *i*-th client, Valera needs to give him everything he wants, that is, to make *x**i* low quality photos and *y**i* high quality photos. To make one low quality photo, the camera must have at least *a* megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least *b* megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up. Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients. Input Specification: The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*d*<=≤<=109) — the number of clients and the camera memory size, correspondingly. The second line contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=104) — the size of one low quality photo and of one high quality photo, correspondingly. Next *n* lines describe the clients. The *i*-th line contains two integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=105) — the number of low quality photos and high quality photos the *i*-th client wants, correspondingly. All numbers on all lines are separated by single spaces. Output Specification: On the first line print the answer to the problem — the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data. Demo Input: ['3 10\n2 3\n1 4\n2 1\n1 0\n', '3 6\n6 6\n1 1\n1 0\n1 0\n'] Demo Output: ['2\n3 2 ', '1\n2 '] Note: none
```python import sys input = sys.stdin.readline class Order: def __init__(self, n, cost): self.number = n self.cost = cost n, storage = map(int, input().split()) a, b = map(int, input().split()) orders = [] for i in range(n): x, y = map(int, input().split()) orders.append(Order(i + 1, x * a + y * b)) orders.sort(key=lambda a: a.cost) s = [] number = 0 for order in orders: if storage - order.cost >= 0: number += 1 storage = storage - order.cost s.append(order.number) else: break print(number) print(*s) ```
3
137
B
Permutation
PROGRAMMING
1,000
[ "greedy" ]
null
null
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*).
Print the only number — the minimum number of changes needed to get the permutation.
[ "3\n3 1 2\n", "2\n2 2\n", "5\n5 3 3 3 1\n" ]
[ "0\n", "1\n", "2\n" ]
The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with number 2.
1,000
[ { "input": "3\n3 1 2", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "5\n5 3 3 3 1", "output": "2" }, { "input": "5\n6 6 6 6 6", "output": "5" }, { "input": "10\n1 1 2 2 8 8 7 7 9 9", "output": "5" }, { "input": "8\n9 8 7 6 5 4 3 2", "output": "1" }, { "input": "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5", "output": "10" }, { "input": "1\n1", "output": "0" }, { "input": "1\n5000", "output": "1" }, { "input": "4\n5000 5000 5000 5000", "output": "4" }, { "input": "5\n3366 3461 4 5 4370", "output": "3" }, { "input": "10\n8 2 10 3 4 6 1 7 9 5", "output": "0" }, { "input": "10\n551 3192 3213 2846 3068 1224 3447 1 10 9", "output": "7" }, { "input": "15\n4 1459 12 4281 3241 2748 10 3590 14 845 3518 1721 2 2880 1974", "output": "10" }, { "input": "15\n15 1 8 2 13 11 12 7 3 14 6 10 9 4 5", "output": "0" }, { "input": "15\n2436 2354 4259 1210 2037 2665 700 3578 2880 973 1317 1024 24 3621 4142", "output": "15" }, { "input": "30\n28 1 3449 9 3242 4735 26 3472 15 21 2698 7 4073 3190 10 3 29 1301 4526 22 345 3876 19 12 4562 2535 2 630 18 27", "output": "14" }, { "input": "100\n50 39 95 30 66 78 2169 4326 81 31 74 34 80 40 19 48 97 63 82 6 88 16 21 57 92 77 10 1213 17 93 32 91 38 4375 29 75 44 22 4 45 14 2395 3254 59 3379 2 85 96 8 83 27 94 1512 2960 100 9 73 79 7 25 55 69 90 99 51 87 98 62 18 35 43 4376 4668 28 72 56 4070 61 65 36 54 4106 11 24 15 86 70 71 4087 23 13 76 20 4694 26 4962 4726 37 14 64", "output": "18" }, { "input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 3638 4652 418 68 4962 387 764 4647 159 1846 225 2760 4904 3150 403 3 2439 91 4428 92 4705 75 348 1566 1465 69 6 49 4 62 4643 564 1090 3447 1871 2255 139 24 99 2669 969 86 61 4550 158 4537 3993 1589 872 2907 1888 401 80 1825 1483 63 1 2264 4068 4113 2548 41 885 4806 36 67 167 4447 34 1248 2593 82 202 81 1783 1284 4973 16 43 95 7 865 2091 3008 1793 20 947 4912 3604", "output": "70" }, { "input": "1\n2", "output": "1" }, { "input": "2\n5000 5000", "output": "2" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n2 3", "output": "1" }, { "input": "2\n3 4", "output": "2" }, { "input": "10\n1 2 3 4 5 6 7 1000 10 10", "output": "2" } ]
1,649,232,883
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
280
4,608,000
import sys #import bisect import math import itertools #import array as ab import random def get_line(): return list(map(int, sys.stdin.readline().strip().split())) def in1(): return int(input()) n=in1() a=get_line() b=list(set(a)) print(n-len(b))
Title: Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). Input Specification: The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). Output Specification: Print the only number — the minimum number of changes needed to get the permutation. Demo Input: ['3\n3 1 2\n', '2\n2 2\n', '5\n5 3 3 3 1\n'] Demo Output: ['0\n', '1\n', '2\n'] Note: The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with number 2.
```python import sys #import bisect import math import itertools #import array as ab import random def get_line(): return list(map(int, sys.stdin.readline().strip().split())) def in1(): return int(input()) n=in1() a=get_line() b=list(set(a)) print(n-len(b)) ```
0
940
C
Phone Numbers
PROGRAMMING
1,500
[ "constructive algorithms", "implementation", "strings" ]
null
null
And where the are the phone numbers? You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {*a*,<=*b*,<=*d*}. String *p* is lexicographically smaller than string *q*, if *p* is a prefix of *q*, is not equal to *q* or there exists *i*, such that *p**i*<=&lt;<=*q**i* and for all *j*<=&lt;<=*i* it is satisfied that *p**j*<==<=*q**j*. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a.
The first line of input contains two space separated integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the length of *s* and the required length of *t*. The second line of input contains the string *s* consisting of *n* lowercase English letters.
Output the string *t* conforming to the requirements above. It's guaranteed that the answer exists.
[ "3 3\nabc\n", "3 2\nabc\n", "3 3\nayy\n", "2 3\nba\n" ]
[ "aca\n", "ac\n", "yaa\n", "baa\n" ]
In the first example the list of strings *t* of length 3, such that the set of letters of *t* is a subset of letters of *s* is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
1,250
[ { "input": "3 3\nabc", "output": "aca" }, { "input": "3 2\nabc", "output": "ac" }, { "input": "3 3\nayy", "output": "yaa" }, { "input": "2 3\nba", "output": "baa" }, { "input": "1 3\nf", "output": "fff" }, { "input": "3 1\nazz", "output": "z" }, { "input": "3 3\nzbf", "output": "zbz" }, { "input": "2 3\ngi", "output": "gig" }, { "input": "3 2\nyzy", "output": "zy" }, { "input": "5 10\nkekff", "output": "kekffeeeee" }, { "input": "10 5\nhqqqqcdddb", "output": "qbbbb" }, { "input": "10 10\nmrfkcsxcuj", "output": "mrfkcsxcuk" }, { "input": "10 3\nggjnohlepu", "output": "ggl" }, { "input": "8 9\npppppppp", "output": "ppppppppp" }, { "input": "10 7\nffffffffyf", "output": "ffffffy" }, { "input": "10 2\nkmiejhcimj", "output": "mc" }, { "input": "10 1\ngiwekrmngf", "output": "i" }, { "input": "8 8\nlolololo", "output": "lololool" }, { "input": "10 9\nbcegikmyyy", "output": "bcegikybb" }, { "input": "7 5000\nqqqqqqq", "output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq..." }, { "input": "3 99948\nttt", "output": "ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt..." } ]
1,535,713,613
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
a = 'abcdefghijklmnopqrstuvwxyz' n, k = map(int, input().split()) s = input() for i in a[::-1]: if i in s: print(i * k) exit(0)
Title: Phone Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: And where the are the phone numbers? You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {*a*,<=*b*,<=*d*}. String *p* is lexicographically smaller than string *q*, if *p* is a prefix of *q*, is not equal to *q* or there exists *i*, such that *p**i*<=&lt;<=*q**i* and for all *j*<=&lt;<=*i* it is satisfied that *p**j*<==<=*q**j*. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input Specification: The first line of input contains two space separated integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the length of *s* and the required length of *t*. The second line of input contains the string *s* consisting of *n* lowercase English letters. Output Specification: Output the string *t* conforming to the requirements above. It's guaranteed that the answer exists. Demo Input: ['3 3\nabc\n', '3 2\nabc\n', '3 3\nayy\n', '2 3\nba\n'] Demo Output: ['aca\n', 'ac\n', 'yaa\n', 'baa\n'] Note: In the first example the list of strings *t* of length 3, such that the set of letters of *t* is a subset of letters of *s* is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
```python a = 'abcdefghijklmnopqrstuvwxyz' n, k = map(int, input().split()) s = input() for i in a[::-1]: if i in s: print(i * k) exit(0) ```
0