contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
sequencelengths
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
sequencelengths
0
7
demo-output
sequencelengths
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
304
B
Calendar
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February. Look at the sample to understand what borders are included in the aswer.
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900<=≤<=*yyyy*<=≤<=2038 and yyyy:mm:dd is a legal date).
Print a single integer — the answer to the problem.
[ "1900:01:01\n2038:12:31\n", "1996:03:09\n1991:11:12\n" ]
[ "50768\n", "1579\n" ]
none
1,000
[ { "input": "1900:01:01\n2038:12:31", "output": "50768" }, { "input": "1996:03:09\n1991:11:12", "output": "1579" }, { "input": "1999:12:31\n2000:02:29", "output": "60" }, { "input": "1903:09:27\n1988:06:15", "output": "30943" }, { "input": "1913:11:14\n1901:05:11", "output": "4570" }, { "input": "1915:01:01\n2007:07:01", "output": "33784" }, { "input": "1925:07:15\n2010:06:22", "output": "31023" }, { "input": "1935:10:08\n1923:01:07", "output": "4657" }, { "input": "1986:08:24\n1926:04:13", "output": "22048" }, { "input": "1932:11:18\n2028:09:25", "output": "35010" }, { "input": "1942:06:04\n1982:12:29", "output": "14818" }, { "input": "1993:08:25\n1985:02:16", "output": "3112" }, { "input": "1954:06:30\n1911:05:04", "output": "15763" }, { "input": "2005:08:01\n1963:08:23", "output": "15319" }, { "input": "2015:10:17\n1966:07:12", "output": "17994" }, { "input": "2025:08:10\n2018:09:03", "output": "2533" }, { "input": "2027:07:31\n1945:04:06", "output": "30066" }, { "input": "2037:05:16\n1996:03:11", "output": "15041" }, { "input": "1949:07:09\n1901:10:24", "output": "17425" }, { "input": "2028:04:11\n1931:09:01", "output": "35287" }, { "input": "1900:02:06\n1997:12:07", "output": "35733" }, { "input": "1902:09:06\n1951:03:31", "output": "17738" }, { "input": "1912:03:09\n1954:06:17", "output": "15440" }, { "input": "1963:05:02\n2005:08:02", "output": "15433" }, { "input": "1973:03:18\n1932:11:07", "output": "14741" }, { "input": "1934:01:09\n1935:02:22", "output": "409" }, { "input": "1985:08:24\n1987:05:01", "output": "615" }, { "input": "1995:06:03\n1990:07:22", "output": "1777" }, { "input": "1907:04:04\n1902:10:01", "output": "1646" }, { "input": "1910:01:11\n1987:02:08", "output": "28152" }, { "input": "1996:03:09\n1996:03:09", "output": "0" }, { "input": "1900:03:02\n2038:03:01", "output": "50403" }, { "input": "2000:01:02\n2000:02:02", "output": "31" }, { "input": "1999:04:08\n1999:02:04", "output": "63" }, { "input": "1999:01:01\n1999:01:10", "output": "9" }, { "input": "2012:05:29\n2012:02:29", "output": "90" }, { "input": "1900:01:01\n1900:01:01", "output": "0" }, { "input": "1996:02:01\n1996:01:27", "output": "5" }, { "input": "1901:12:31\n1901:12:31", "output": "0" }, { "input": "2000:02:28\n2000:02:28", "output": "0" } ]
1,693,685,709
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
30
92
0
from sys import stdin def input(): return stdin.readline()[:-1] def ili(): return list(map(int, input().split())) y1,m1,d1=map(int, input().split(':')) y2,m2,d2=map(int, input().split(':')) days = 0 if y1*100000+m1*100+d1 > y2*100000+m2*100+d2: # print("hererheoroe") y1, y2 = y2, y1 m1, m2 = m2, m1 d1, d2 = d2, d1 for i in range(y1+1,y2): if (i%4 == 0 and i%100 != 0) or i%400 == 0: days += 366 continue days += 365 for l in range(1, m2+1): if l == m2: # print("hello") days += d2 break if l == 1 or l == 3 or l == 5 or l == 7 or l == 8 or l == 10 or l == 12: days += 31 elif l == 4 or l == 6 or l == 9 or l == 11: days += 30 elif l == 2: days += 28 if (y2%4 == 0 and y2%100 != 0) or y2%400 == 0: days += 1 days += 365 if (y1%4 == 0 and y1%100 != 0) or y1%400 == 0: days += 1 # print(f"y2 is {y2}") for l in range(1, m1+1): if l == m1: days -= d1 break if l == 1 or l == 3 or l == 5 or l == 7 or l == 8 or l == 10 or l == 12: days -= 31 elif l == 4 or l == 6 or l == 9 or l == 11: days -= 30 elif l == 2: days -= 28 if (y1%4 == 0 and y1%100 != 0) or y1%400 == 0: # print("hellomoto") days -= 1 print(days)
Title: Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February. Look at the sample to understand what borders are included in the aswer. Input Specification: The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900<=≤<=*yyyy*<=≤<=2038 and yyyy:mm:dd is a legal date). Output Specification: Print a single integer — the answer to the problem. Demo Input: ['1900:01:01\n2038:12:31\n', '1996:03:09\n1991:11:12\n'] Demo Output: ['50768\n', '1579\n'] Note: none
```python from sys import stdin def input(): return stdin.readline()[:-1] def ili(): return list(map(int, input().split())) y1,m1,d1=map(int, input().split(':')) y2,m2,d2=map(int, input().split(':')) days = 0 if y1*100000+m1*100+d1 > y2*100000+m2*100+d2: # print("hererheoroe") y1, y2 = y2, y1 m1, m2 = m2, m1 d1, d2 = d2, d1 for i in range(y1+1,y2): if (i%4 == 0 and i%100 != 0) or i%400 == 0: days += 366 continue days += 365 for l in range(1, m2+1): if l == m2: # print("hello") days += d2 break if l == 1 or l == 3 or l == 5 or l == 7 or l == 8 or l == 10 or l == 12: days += 31 elif l == 4 or l == 6 or l == 9 or l == 11: days += 30 elif l == 2: days += 28 if (y2%4 == 0 and y2%100 != 0) or y2%400 == 0: days += 1 days += 365 if (y1%4 == 0 and y1%100 != 0) or y1%400 == 0: days += 1 # print(f"y2 is {y2}") for l in range(1, m1+1): if l == m1: days -= d1 break if l == 1 or l == 3 or l == 5 or l == 7 or l == 8 or l == 10 or l == 12: days -= 31 elif l == 4 or l == 6 or l == 9 or l == 11: days -= 30 elif l == 2: days -= 28 if (y1%4 == 0 and y1%100 != 0) or y1%400 == 0: # print("hellomoto") days -= 1 print(days) ```
0
729
B
Spotlights
PROGRAMMING
1,200
[ "dp", "implementation" ]
null
null
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines. A position is good if two conditions hold: - there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects. Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.
Print one integer — the number of good positions for placing the spotlight.
[ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ]
[ "9\n", "20\n" ]
In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction. Therefore, there are 9 good positions in this example.
1,000
[ { "input": "2 4\n0 1 0 0\n1 0 1 0", "output": "9" }, { "input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "output": "20" }, { "input": "1 5\n1 1 0 0 0", "output": "3" }, { "input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "3 1\n1\n0\n0", "output": "2" }, { "input": "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0", "output": "25" }, { "input": "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "4" }, { "input": "5 7\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1\n0 1 1 1 1 1 1\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1", "output": "26" }, { "input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "121" }, { "input": "1 2\n0 1", "output": "1" }, { "input": "1 2\n1 0", "output": "1" }, { "input": "1 2\n1 1", "output": "0" }, { "input": "2 1\n1\n0", "output": "1" }, { "input": "2 1\n0\n1", "output": "1" }, { "input": "2 1\n1\n1", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1", "output": "16" } ]
1,479,636,225
3,525
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
6
1,000
5,734,400
n, m = map(int, input().split()) A = [] ans = 0 B = [0 for i in range(m)] for i in range(n): line = list(map(int, input().split())) res = 0 for j in range(m): if line[j] == 1: res = 1 B[j] = 1 if line[j] == 0 and res == 1: ans += 1 if line[j] == 0 and B[j] == 1: ans += 1 res = 0 for j in range(m - 1, -1, -1): if line[j] == 1: res = 1 if line[j] == 0 and res == 1: ans += 1 A.append(line) B = [0 for i in range(m)] for i in range(n - 1, -1, -1): line = A[i] for j in range(m): if line[j] == 1: B[j] = 1 if line[j] == 0 and B[j] == 1: ans += 1 print(ans)
Title: Spotlights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines. A position is good if two conditions hold: - there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects. Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ. Input Specification: The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan. Output Specification: Print one integer — the number of good positions for placing the spotlight. Demo Input: ['2 4\n0 1 0 0\n1 0 1 0\n', '4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n'] Demo Output: ['9\n', '20\n'] Note: In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction. Therefore, there are 9 good positions in this example.
```python n, m = map(int, input().split()) A = [] ans = 0 B = [0 for i in range(m)] for i in range(n): line = list(map(int, input().split())) res = 0 for j in range(m): if line[j] == 1: res = 1 B[j] = 1 if line[j] == 0 and res == 1: ans += 1 if line[j] == 0 and B[j] == 1: ans += 1 res = 0 for j in range(m - 1, -1, -1): if line[j] == 1: res = 1 if line[j] == 0 and res == 1: ans += 1 A.append(line) B = [0 for i in range(m)] for i in range(n - 1, -1, -1): line = A[i] for j in range(m): if line[j] == 1: B[j] = 1 if line[j] == 0 and B[j] == 1: ans += 1 print(ans) ```
0
765
B
Code obfuscation
PROGRAMMING
1,100
[ "greedy", "implementation", "strings" ]
null
null
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs. You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters.
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
[ "abacaba\n", "jinotega\n" ]
[ "YES\n", "NO\n" ]
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program: - replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result would be "a b a character a b a",- replace all occurences of character with c, the result would be "a b a c a b a",- all identifiers have been replaced, thus the obfuscation is finished.
1,000
[ { "input": "abacaba", "output": "YES" }, { "input": "jinotega", "output": "NO" }, { "input": "aaaaaaaaaaa", "output": "YES" }, { "input": "aba", "output": "YES" }, { "input": "bab", "output": "NO" }, { "input": "a", "output": "YES" }, { "input": "abcdefghijklmnopqrstuvwxyz", "output": "YES" }, { "input": "fihyxmbnzq", "output": "NO" }, { "input": "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "YES" }, { "input": "darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr", "output": "NO" }, { "input": "bbbbbb", "output": "NO" }, { "input": "aabbbd", "output": "NO" }, { "input": "abdefghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "abcdeghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "abcdefghijklmnopqrsuvwxyz", "output": "NO" }, { "input": "abcdefghijklmnopqrstuvwxy", "output": "YES" }, { "input": "abcdefghijklmnopqrsutvwxyz", "output": "NO" }, { "input": "acdef", "output": "NO" }, { "input": "z", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "YES" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabbbabbaaabbaaaaabaabbaa", "output": "YES" }, { "input": "aababbabbaabbbbbaabababaabbbaaaaabbabbabbaabbbbabaabbaaababbaaacbbabbbbbbcbcababbccaaacbaccaccaababbccaacccaabaaccaaabacacbaabacbaacbaaabcbbbcbbaacaabcbcbccbacabbcbabcaccaaaaaabcbacabcbabbbbbabccbbcacbaaabbccbbaaaaaaaaaaaadbbbabdacabdaddddbaabbddbdabbdacbacbacaaaabbacadbcddddadaddabbdccaddbaaacbceebbceadbeaadecddbbbcaaecbdeaebaddbbdebbcbaabcacbdcdc", "output": "YES" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbaabaabaababbbabbacacbbbacbbaaaabbccacbaabaaccbbbbbcbbbacabbccaaabbaaacabcbacbcabbbbecbecadcbacbaadeeadabeacdebccdbbcaecdbeeebbebcaaaeacdcbdeccdbbdcdebdcbdacebcecbacddeeaebcedffedfggbeedceacaecagdfedfabcfchffceachgcbicbcffeeebgcgiefcafhibhceiedgbfebbccegbehhibhhfedbaeedbghggffehggaeaidifhdhaggdjcfjhiaieaichjacedchejg", "output": "NO" }, { "input": "b", "output": "NO" }, { "input": "ac", "output": "NO" }, { "input": "cde", "output": "NO" }, { "input": "abd", "output": "NO" }, { "input": "zx", "output": "NO" }, { "input": "bcd", "output": "NO" }, { "input": "aaac", "output": "NO" }, { "input": "aacb", "output": "NO" }, { "input": "acd", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "NO" }, { "input": "abcdefghijklmnopqrstuvwxyzz", "output": "YES" }, { "input": "bc", "output": "NO" }, { "input": "aaaaaaaaad", "output": "NO" }, { "input": "abb", "output": "YES" }, { "input": "abcb", "output": "YES" }, { "input": "aac", "output": "NO" }, { "input": "abcbcb", "output": "YES" }, { "input": "bb", "output": "NO" }, { "input": "abbb", "output": "YES" }, { "input": "bbb", "output": "NO" }, { "input": "x", "output": "NO" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazz", "output": "NO" }, { "input": "acbccccccccccc", "output": "NO" }, { "input": "za", "output": "NO" }, { "input": "ade", "output": "NO" }, { "input": "bbbbbbbbbb", "output": "NO" }, { "input": "bac", "output": "NO" }, { "input": "bcddcb", "output": "NO" }, { "input": "aaacb", "output": "NO" }, { "input": "aaaaac", "output": "NO" }, { "input": "aaaaaaaaaaad", "output": "NO" }, { "input": "c", "output": "NO" }, { "input": "abcccccccc", "output": "YES" }, { "input": "aaaaaaac", "output": "NO" } ]
1,611,752,338
2,147,483,647
PyPy 3
OK
TESTS
59
156
2,355,200
import string obf = [x for x in input()] obf = [x for i, x in enumerate(obf) if x not in obf[:i]] n = len(obf) letters = list(string.ascii_lowercase) letters = letters[:n] if obf == letters: print('Yes') else: print('No')
Title: Code obfuscation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs. You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation. Input Specification: In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters. Output Specification: If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO". Demo Input: ['abacaba\n', 'jinotega\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program: - replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result would be "a b a character a b a",- replace all occurences of character with c, the result would be "a b a c a b a",- all identifiers have been replaced, thus the obfuscation is finished.
```python import string obf = [x for x in input()] obf = [x for i, x in enumerate(obf) if x not in obf[:i]] n = len(obf) letters = list(string.ascii_lowercase) letters = letters[:n] if obf == letters: print('Yes') else: print('No') ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made 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,690,500,517
2,147,483,647
Python 3
OK
TESTS
20
46
0
n=int(input()) x=1 l=[] while x!=n+1: w=input("") l.append(w) x+=1 y=0 m=[] for y in range (n): v=l[y] p=len(v)-2 if len(v)>10: a=v[0]+str(p)+v[len(v)-1] m.append(a) else: m.append(v) p=0 while p!=len(m): print(m[p]) p+=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 n=int(input()) x=1 l=[] while x!=n+1: w=input("") l.append(w) x+=1 y=0 m=[] for y in range (n): v=l[y] p=len(v)-2 if len(v)>10: a=v[0]+str(p)+v[len(v)-1] m.append(a) else: m.append(v) p=0 while p!=len(m): print(m[p]) p+=1 ```
3.977
300
B
Coach
PROGRAMMING
1,500
[ "brute force", "dfs and similar", "graphs" ]
null
null
A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the *i*-th student wants to be on the same team with the *j*-th one, then the *j*-th student wants to be on the same team with the *i*-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the *i*-th student wants to be on the same team with the *j*-th, then the *i*-th and the *j*-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants.
The first line of the input contains integers *n* and *m* (3<=≤<=*n*<=≤<=48, . Then follow *m* lines, each contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) — the pair *a**i*,<=*b**i* means that students with numbers *a**i* and *b**i* want to be on the same team. It is guaranteed that *n* is divisible by 3. It is guaranteed that each pair *a**i*,<=*b**i* occurs in the input at most once.
If the required division into teams doesn't exist, print number -1. Otherwise, print lines. In each line print three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=*n*) — the *i*-th team. If there are multiple answers, you are allowed to print any of them.
[ "3 0\n", "6 4\n1 2\n2 3\n3 4\n5 6\n", "3 3\n1 2\n2 3\n1 3\n" ]
[ "3 2 1 \n", "-1\n", "3 2 1 \n" ]
none
1,000
[ { "input": "3 0", "output": "3 2 1 " }, { "input": "6 4\n1 2\n2 3\n3 4\n5 6", "output": "-1" }, { "input": "3 3\n1 2\n2 3\n1 3", "output": "3 2 1 " }, { "input": "6 3\n1 2\n3 4\n5 6", "output": "-1" }, { "input": "15 9\n1 4\n1 6\n2 7\n2 11\n4 6\n5 12\n7 11\n9 14\n13 15", "output": "6 4 1 \n11 7 2 \n12 5 3 \n14 9 8 \n15 13 10 " }, { "input": "3 1\n1 3", "output": "3 2 1 " }, { "input": "15 13\n1 9\n1 11\n2 7\n2 12\n3 8\n3 15\n4 10\n5 6\n5 14\n6 14\n7 12\n8 15\n9 11", "output": "11 9 1 \n12 7 2 \n14 6 5 \n15 8 3 \n13 10 4 " }, { "input": "36 27\n1 34\n2 18\n2 20\n3 9\n3 21\n4 5\n4 25\n5 25\n6 13\n6 22\n8 23\n8 31\n9 21\n10 14\n11 17\n11 19\n13 22\n15 24\n15 26\n17 19\n18 20\n23 31\n24 26\n28 29\n28 33\n29 33\n32 36", "output": "19 17 11 \n20 18 2 \n21 9 3 \n22 13 6 \n25 5 4 \n26 24 15 \n31 23 8 \n33 29 28 \n14 10 7 \n34 12 1 \n36 32 16 \n35 30 27 " }, { "input": "18 12\n1 10\n2 4\n2 8\n3 15\n3 18\n4 8\n5 6\n9 13\n12 14\n12 16\n14 16\n15 18", "output": "8 4 2 \n16 14 12 \n18 15 3 \n7 6 5 \n11 10 1 \n17 13 9 " }, { "input": "39 27\n1 2\n1 25\n2 25\n4 16\n5 22\n5 28\n6 7\n6 26\n7 26\n8 24\n10 31\n10 38\n11 17\n11 21\n12 35\n12 37\n13 34\n17 21\n18 23\n19 39\n22 28\n27 29\n27 36\n29 36\n31 38\n32 33\n35 37", "output": "21 17 11 \n25 2 1 \n26 7 6 \n28 22 5 \n36 29 27 \n37 35 12 \n38 31 10 \n16 4 3 \n23 18 9 \n24 14 8 \n33 32 15 \n34 20 13 \n39 30 19 " }, { "input": "12 7\n1 2\n4 5\n6 12\n7 8\n9 10\n9 11\n10 11", "output": "-1" }, { "input": "33 22\n3 9\n3 28\n4 12\n5 11\n5 31\n6 18\n8 15\n8 29\n9 28\n10 22\n11 31\n13 14\n15 29\n16 23\n16 27\n17 25\n17 32\n19 21\n20 30\n23 27\n24 33\n25 32", "output": "-1" }, { "input": "18 8\n1 14\n2 16\n4 7\n5 11\n8 9\n8 12\n9 12\n10 18", "output": "12 9 8 \n7 4 3 \n11 6 5 \n14 13 1 \n16 15 2 \n18 17 10 " }, { "input": "27 21\n1 3\n2 9\n2 11\n5 16\n5 25\n7 26\n8 14\n8 22\n9 11\n10 17\n10 27\n12 21\n13 20\n13 23\n14 22\n15 18\n15 19\n16 25\n17 27\n18 19\n20 23", "output": "11 9 2 \n19 18 15 \n22 14 8 \n23 20 13 \n25 16 5 \n27 17 10 \n4 3 1 \n21 12 6 \n26 24 7 " }, { "input": "24 21\n1 14\n2 6\n3 4\n3 19\n4 19\n5 7\n5 21\n7 21\n8 18\n8 23\n9 15\n9 16\n10 12\n10 17\n11 22\n12 17\n13 20\n13 24\n15 16\n18 23\n20 24", "output": "-1" }, { "input": "45 31\n1 5\n2 45\n3 29\n3 30\n4 16\n4 32\n6 40\n7 13\n7 25\n8 42\n10 31\n11 20\n11 26\n12 27\n12 34\n13 25\n14 24\n14 43\n15 36\n15 37\n16 32\n18 19\n18 33\n19 33\n20 26\n23 41\n24 43\n27 34\n28 39\n29 30\n36 37", "output": "25 13 7 \n26 20 11 \n30 29 3 \n32 16 4 \n33 19 18 \n34 27 12 \n37 36 15 \n43 24 14 \n9 5 1 \n31 17 10 \n39 28 21 \n40 22 6 \n41 35 23 \n42 38 8 \n45 44 2 " }, { "input": "18 9\n1 16\n2 17\n4 6\n5 18\n7 8\n7 15\n8 15\n9 11\n10 13", "output": "-1" }, { "input": "6 6\n1 6\n1 3\n3 6\n2 4\n4 5\n2 5", "output": "5 4 2 \n6 3 1 " }, { "input": "48 48\n7 39\n39 45\n7 45\n25 26\n26 31\n25 31\n4 11\n11 19\n4 19\n8 16\n16 37\n8 37\n14 22\n22 33\n14 33\n6 12\n12 46\n6 46\n29 44\n44 48\n29 48\n15 27\n27 41\n15 41\n3 24\n24 34\n3 34\n13 20\n20 47\n13 47\n5 9\n9 36\n5 36\n21 40\n40 43\n21 43\n2 35\n35 38\n2 38\n23 28\n28 42\n23 42\n1 10\n10 32\n1 32\n17 18\n18 30\n17 30", "output": "19 11 4 \n30 18 17 \n31 26 25 \n32 10 1 \n33 22 14 \n34 24 3 \n36 9 5 \n37 16 8 \n38 35 2 \n41 27 15 \n42 28 23 \n43 40 21 \n45 39 7 \n46 12 6 \n47 20 13 \n48 44 29 " }, { "input": "12 9\n1 2\n2 4\n1 3\n5 6\n6 8\n5 7\n9 10\n10 12\n9 11", "output": "-1" }, { "input": "9 7\n1 2\n3 4\n5 6\n7 8\n2 3\n2 5\n2 7", "output": "-1" }, { "input": "9 3\n4 5\n6 7\n8 9", "output": "5 4 1 \n7 6 2 \n9 8 3 " }, { "input": "6 2\n3 4\n5 6", "output": "4 3 1 \n6 5 2 " }, { "input": "9 7\n1 2\n2 3\n1 3\n4 5\n4 6\n4 7\n4 8", "output": "-1" }, { "input": "6 1\n1 2", "output": "3 2 1 \n6 5 4 " }, { "input": "48 1\n1 2", "output": "3 2 1 \n6 5 4 \n9 8 7 \n12 11 10 \n15 14 13 \n18 17 16 \n21 20 19 \n24 23 22 \n27 26 25 \n30 29 28 \n33 32 31 \n36 35 34 \n39 38 37 \n42 41 40 \n45 44 43 \n48 47 46 " } ]
1,598,850,955
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
278
20,172,800
n, m = map(int, input().split()) ans = [] temp = set() if m == 0: for x in range(n // 3): print(n, n - 1, n - 2) n -= 3 else: for x in range(m): z, y = map(int, input().split()) if len(temp) < 3: temp.add(z) temp.add(y) else: if z not in temp or y not in temp: print(-1) exit() else: ans.append(temp) temp = set() for x in ans: print(*x)
Title: Coach Time Limit: None seconds Memory Limit: None megabytes Problem Description: A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the *i*-th student wants to be on the same team with the *j*-th one, then the *j*-th student wants to be on the same team with the *i*-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the *i*-th student wants to be on the same team with the *j*-th, then the *i*-th and the *j*-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input Specification: The first line of the input contains integers *n* and *m* (3<=≤<=*n*<=≤<=48, . Then follow *m* lines, each contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) — the pair *a**i*,<=*b**i* means that students with numbers *a**i* and *b**i* want to be on the same team. It is guaranteed that *n* is divisible by 3. It is guaranteed that each pair *a**i*,<=*b**i* occurs in the input at most once. Output Specification: If the required division into teams doesn't exist, print number -1. Otherwise, print lines. In each line print three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=*n*) — the *i*-th team. If there are multiple answers, you are allowed to print any of them. Demo Input: ['3 0\n', '6 4\n1 2\n2 3\n3 4\n5 6\n', '3 3\n1 2\n2 3\n1 3\n'] Demo Output: ['3 2 1 \n', '-1\n', '3 2 1 \n'] Note: none
```python n, m = map(int, input().split()) ans = [] temp = set() if m == 0: for x in range(n // 3): print(n, n - 1, n - 2) n -= 3 else: for x in range(m): z, y = map(int, input().split()) if len(temp) < 3: temp.add(z) temp.add(y) else: if z not in temp or y not in temp: print(-1) exit() else: ans.append(temp) temp = set() for x in ans: print(*x) ```
0
1,009
B
Minimum Ternary String
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: - "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j &lt; i$ holds $a_j = b_j$, and $a_i &lt; b_i$.
The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive).
Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
[ "100210\n", "11222121\n", "20\n" ]
[ "001120\n", "11112222\n", "20\n" ]
none
0
[ { "input": "100210", "output": "001120" }, { "input": "11222121", "output": "11112222" }, { "input": "20", "output": "20" }, { "input": "1002", "output": "0012" }, { "input": "10", "output": "01" }, { "input": "000021", "output": "000012" }, { "input": "021", "output": "012" }, { "input": "2", "output": "2" }, { "input": "201", "output": "120" }, { "input": "2112120", "output": "1112220" }, { "input": "102", "output": "012" }, { "input": "202", "output": "202" }, { "input": "220201", "output": "122020" }, { "input": "12", "output": "12" }, { "input": "100022202", "output": "000122202" }, { "input": "01", "output": "01" }, { "input": "1", "output": "1" } ]
1,531,780,820
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
word = input() count_ones = 0 cur_word = '' for c in word: if int(c)==1: count_ones += 1 if int(c)!=1: cur_word = cur_word + c res = '' found = 0 for c in cur_word: if c==2 and found==0: found = 1 for i in range(count_ones): res += '1' else: res += c if found==0: for i in range(count_ones): res += '1' print(res)
Title: Minimum Ternary String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: - "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j &lt; i$ holds $a_j = b_j$, and $a_i &lt; b_i$. Input Specification: The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). Output Specification: Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). Demo Input: ['100210\n', '11222121\n', '20\n'] Demo Output: ['001120\n', '11112222\n', '20\n'] Note: none
```python word = input() count_ones = 0 cur_word = '' for c in word: if int(c)==1: count_ones += 1 if int(c)!=1: cur_word = cur_word + c res = '' found = 0 for c in cur_word: if c==2 and found==0: found = 1 for i in range(count_ones): res += '1' else: res += c if found==0: for i in range(count_ones): res += '1' print(res) ```
0
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,664,063,741
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
6,656,000
n=int(input()) s=list(map(int,input().split())) m=int(input()) mm=list(map(int,input().split())) s2=s.copy() s2.reverse() v=0 p=0 for i in mm: v+=s.index(i)+1 p+=s2.index(i)+1 print(v,p)
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python n=int(input()) s=list(map(int,input().split())) m=int(input()) mm=list(map(int,input().split())) s2=s.copy() s2.reverse() v=0 p=0 for i in mm: v+=s.index(i)+1 p+=s2.index(i)+1 print(v,p) ```
0
0
none
none
none
0
[ "none" ]
null
null
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z. For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well. Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
[ "4 3\n1 3\n3 4\n1 4\n", "4 4\n3 1\n2 3\n3 4\n1 2\n", "10 4\n4 3\n5 10\n8 9\n1 2\n", "3 2\n1 2\n2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
0
[ { "input": "4 3\n1 3\n3 4\n1 4", "output": "YES" }, { "input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO" }, { "input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 0", "output": "YES" }, { "input": "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\n13 12\n2 6\n9 14\n6 9\n12 9\n11 1\n2 9\n11 8", "output": "YES" }, { "input": "20 80\n17 4\n10 1\n11 10\n17 7\n15 10\n14 15\n13 1\n18 13\n3 13\n12 7\n9 13\n10 12\n14 12\n18 11\n4 7\n10 13\n11 3\n19 8\n14 7\n10 17\n14 3\n7 11\n11 14\n19 5\n10 14\n15 17\n3 1\n9 10\n11 1\n4 1\n11 4\n9 1\n12 3\n13 7\n1 14\n11 12\n7 1\n9 12\n18 15\n17 3\n7 15\n4 10\n7 18\n7 9\n12 17\n14 18\n3 18\n18 17\n9 15\n14 4\n14 9\n9 18\n12 4\n7 10\n15 4\n4 18\n15 13\n1 12\n7 3\n13 11\n4 13\n5 8\n12 18\n12 15\n17 9\n11 15\n3 10\n18 10\n4 3\n15 3\n13 12\n9 4\n9 11\n14 17\n13 17\n3 9\n13 14\n1 17\n15 1\n17 11", "output": "NO" }, { "input": "99 26\n64 17\n48 70\n71 50\n3 50\n9 60\n61 64\n53 50\n25 12\n3 71\n71 53\n3 53\n65 70\n9 25\n9 12\n59 56\n39 60\n64 69\n65 94\n70 94\n25 60\n60 12\n94 48\n17 69\n61 17\n65 48\n61 69", "output": "NO" }, { "input": "3 1\n1 2", "output": "YES" }, { "input": "3 2\n3 2\n1 3", "output": "NO" }, { "input": "3 3\n2 3\n1 2\n1 3", "output": "YES" }, { "input": "4 2\n4 1\n2 1", "output": "NO" }, { "input": "4 3\n3 1\n2 1\n3 2", "output": "YES" }, { "input": "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2", "output": "NO" }, { "input": "10 5\n9 5\n1 2\n6 8\n6 3\n10 6", "output": "NO" }, { "input": "10 8\n10 7\n9 7\n5 7\n6 8\n3 5\n8 10\n3 4\n7 8", "output": "NO" }, { "input": "10 20\n8 2\n8 3\n1 8\n9 5\n2 4\n10 1\n10 5\n7 5\n7 8\n10 7\n6 5\n3 7\n1 9\n9 8\n7 2\n2 10\n2 1\n6 4\n9 7\n4 3", "output": "NO" }, { "input": "150000 10\n62562 50190\n48849 60549\n139470 18456\n21436 25159\n66845 120884\n99972 114453\n11631 99153\n62951 134848\n78114 146050\n136760 131762", "output": "YES" }, { "input": "150000 0", "output": "YES" }, { "input": "4 4\n1 2\n2 3\n3 4\n1 4", "output": "NO" }, { "input": "30 73\n25 2\n2 16\n20 12\n16 20\n7 18\n11 15\n13 11\n30 29\n16 12\n12 25\n2 1\n18 14\n9 8\n28 16\n2 9\n22 21\n1 25\n12 28\n14 7\n4 9\n26 7\n14 27\n12 2\n29 22\n1 9\n13 15\n3 10\n1 12\n8 20\n30 24\n25 20\n4 1\n4 12\n20 1\n8 4\n2 28\n25 16\n16 8\n20 4\n9 12\n21 30\n23 11\n19 6\n28 4\n29 21\n9 28\n30 10\n22 24\n25 8\n27 26\n25 4\n28 20\n9 25\n24 29\n20 9\n18 26\n1 28\n30 22\n23 15\n28 27\n8 2\n23 13\n12 8\n14 26\n16 4\n28 25\n8 1\n4 2\n9 16\n20 2\n18 27\n28 8\n27 7", "output": "NO" }, { "input": "5 4\n1 2\n2 5\n3 4\n4 5", "output": "NO" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "NO" }, { "input": "6 6\n1 2\n2 4\n4 3\n1 5\n5 6\n6 3", "output": "NO" }, { "input": "3 2\n1 2\n1 3", "output": "NO" }, { "input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6", "output": "NO" }, { "input": "4 4\n1 2\n1 3\n2 4\n3 4", "output": "NO" }, { "input": "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n3 4", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n2 4", "output": "NO" }, { "input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "NO" }, { "input": "150000 3\n150000 149999\n149998 149999\n149998 150000", "output": "YES" }, { "input": "10 15\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10", "output": "NO" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "NO" }, { "input": "5 4\n1 2\n1 3\n1 4\n1 5", "output": "NO" }, { "input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n1 4\n2 3\n3 4", "output": "NO" }, { "input": "4 4\n1 2\n1 3\n4 2\n4 3", "output": "NO" }, { "input": "5 5\n1 4\n5 3\n5 1\n2 3\n4 5", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n2 3\n1 4\n2 4", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4", "output": "NO" }, { "input": "6 12\n1 2\n1 4\n1 5\n1 6\n2 3\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6", "output": "NO" }, { "input": "1000 4\n100 132\n100 164\n196 132\n196 164", "output": "NO" } ]
1,694,384,729
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
def dfs(ver, par, amigos, visitados): visitados[ver] = True for vecino in amigos[ver]: if not visitados[vecino]: dfs(vecino, par, amigos, visitados) else: if par != vecino: return False return True def es_red_racional(n, m, relaciones): amigos = [[] for _ in range(n)] for a, b in relaciones: amigos[a - 1].append(b - 1) amigos[b - 1].append(a - 1) visitados = [False] * n for i in range(n): if not visitados[i]: if not dfs(i, -1, amigos, visitados): return "NO" return "YES" # Lectura de entrada n, m = map(int, input().split()) relaciones = [] for _ in range(m): a, b = map(int, input().split()) relaciones.append((a, b)) # Verificación y salida resultado = es_red_racional(n, m, relaciones) print(resultado)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z. For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well. Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes. Input Specification: The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input. Output Specification: If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). Demo Input: ['4 3\n1 3\n3 4\n1 4\n', '4 4\n3 1\n2 3\n3 4\n1 2\n', '10 4\n4 3\n5 10\n8 9\n1 2\n', '3 2\n1 2\n2 3\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n'] Note: The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
```python def dfs(ver, par, amigos, visitados): visitados[ver] = True for vecino in amigos[ver]: if not visitados[vecino]: dfs(vecino, par, amigos, visitados) else: if par != vecino: return False return True def es_red_racional(n, m, relaciones): amigos = [[] for _ in range(n)] for a, b in relaciones: amigos[a - 1].append(b - 1) amigos[b - 1].append(a - 1) visitados = [False] * n for i in range(n): if not visitados[i]: if not dfs(i, -1, amigos, visitados): return "NO" return "YES" # Lectura de entrada n, m = map(int, input().split()) relaciones = [] for _ in range(m): a, b = map(int, input().split()) relaciones.append((a, b)) # Verificación y salida resultado = es_red_racional(n, m, relaciones) print(resultado) ```
0
522
D
Closest Equals
PROGRAMMING
2,000
[ "*special", "data structures" ]
null
null
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* and *m* queries *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query you need to print the minimum distance between such pair of elements *a**x* and *a**y* (*x*<=≠<=*y*), that: - both indexes of the elements lie within range [*l**j*,<=*r**j*], that is, *l**j*<=≤<=*x*,<=*y*<=≤<=*r**j*; - the values of the elements are equal, that is *a**x*<==<=*a**y*. The text above understands distance as |*x*<=-<=*y*|.
The first line of the input contains a pair of integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=5·105) — the length of the sequence and the number of queries, correspondingly. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). Next *m* lines contain the queries, one per line. Each query is given by a pair of numbers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the indexes of the query range limits.
Print *m* integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query.
[ "5 3\n1 1 2 3 2\n1 5\n2 4\n3 5\n", "6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6\n" ]
[ "1\n-1\n2\n", "2\n2\n3\n-1\n2\n" ]
none
2,000
[ { "input": "5 3\n1 1 2 3 2\n1 5\n2 4\n3 5", "output": "1\n-1\n2" }, { "input": "6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6", "output": "2\n2\n3\n-1\n2" }, { "input": "10 6\n2 2 1 5 6 4 9 8 5 4\n1 2\n1 10\n2 10\n2 9\n5 5\n2 8", "output": "1\n1\n4\n5\n-1\n-1" }, { "input": "1 1\n1\n1 1", "output": "-1" }, { "input": "1 3\n1\n1 1\n1 1\n1 1", "output": "-1\n-1\n-1" }, { "input": "2 1\n1 1\n1 2", "output": "1" }, { "input": "2 1\n1 1\n1 1", "output": "-1" }, { "input": "2 5\n1 1\n1 1\n1 2\n2 2\n1 2\n1 1", "output": "-1\n1\n-1\n1\n-1" }, { "input": "2 4\n1 2\n1 1\n1 2\n2 2\n1 2", "output": "-1\n-1\n-1\n-1" } ]
1,630,624,811
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
108
20,172,800
def find1(X, l, r): m = len(X) if r < X[0]: return float('inf') if X[-1] < l: return float('inf') if l <= X[0]: left_point = 0 else: s = 0 e = m-1 while s+1 < e: mid = (s+e)//2 if X[mid] > l: s, e = mid, e else: s, e = s, mid left_point = e if X[-1] <= r: right_point = m-1 else: s = 0 e = m-1 while s+1 < e: mid = (s+e)//2 if X[mid] <= r: s, e = mid, e else: s, e = s, mid right_point = s if left_point==right_point: return float('inf') return X[right_point]-X[left_point] def process(A, Q): d = {} n = len(A) answer = [] for i in range(n): x = A[i] if x not in d: d[x] = [] d[x].append(i) for l, r in Q: my_min = float('inf') for x in d: my_min = min(my_min, find1(d[x], l-1, r-1)) if my_min==float('inf'): answer.append(-1) else: answer.append(my_min) return answer n, m = [int(x) for x in input().split()] A = [int(x) for x in input().split()] Q = [] for i in range(m): l, r = [int(x) for x in input().split()] Q.append([l, r]) answer = process(A, Q) for x in answer: print(x)
Title: Closest Equals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given sequence *a*1,<=*a*2,<=...,<=*a**n* and *m* queries *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query you need to print the minimum distance between such pair of elements *a**x* and *a**y* (*x*<=≠<=*y*), that: - both indexes of the elements lie within range [*l**j*,<=*r**j*], that is, *l**j*<=≤<=*x*,<=*y*<=≤<=*r**j*; - the values of the elements are equal, that is *a**x*<==<=*a**y*. The text above understands distance as |*x*<=-<=*y*|. Input Specification: The first line of the input contains a pair of integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=5·105) — the length of the sequence and the number of queries, correspondingly. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). Next *m* lines contain the queries, one per line. Each query is given by a pair of numbers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the indexes of the query range limits. Output Specification: Print *m* integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query. Demo Input: ['5 3\n1 1 2 3 2\n1 5\n2 4\n3 5\n', '6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6\n'] Demo Output: ['1\n-1\n2\n', '2\n2\n3\n-1\n2\n'] Note: none
```python def find1(X, l, r): m = len(X) if r < X[0]: return float('inf') if X[-1] < l: return float('inf') if l <= X[0]: left_point = 0 else: s = 0 e = m-1 while s+1 < e: mid = (s+e)//2 if X[mid] > l: s, e = mid, e else: s, e = s, mid left_point = e if X[-1] <= r: right_point = m-1 else: s = 0 e = m-1 while s+1 < e: mid = (s+e)//2 if X[mid] <= r: s, e = mid, e else: s, e = s, mid right_point = s if left_point==right_point: return float('inf') return X[right_point]-X[left_point] def process(A, Q): d = {} n = len(A) answer = [] for i in range(n): x = A[i] if x not in d: d[x] = [] d[x].append(i) for l, r in Q: my_min = float('inf') for x in d: my_min = min(my_min, find1(d[x], l-1, r-1)) if my_min==float('inf'): answer.append(-1) else: answer.append(my_min) return answer n, m = [int(x) for x in input().split()] A = [int(x) for x in input().split()] Q = [] for i in range(m): l, r = [int(x) for x in input().split()] Q.append([l, r]) answer = process(A, Q) for x in answer: print(x) ```
0
920
E
Connected Components?
PROGRAMMING
2,100
[ "data structures", "dfs and similar", "dsu", "graphs" ]
null
null
You are given an undirected graph consisting of *n* vertices and edges. Instead of giving you the edges that exist in the graph, we give you *m* unordered pairs (*x*,<=*y*) such that there is no edge between *x* and *y*, and if some pair of vertices is not listed in the input, then there is an edge between these vertices. You have to find the number of connected components in the graph and the size of each component. A connected component is a set of vertices *X* such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to *X* violates this rule.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=200000, ). Then *m* lines follow, each containing a pair of integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*, *x*<=≠<=*y*) denoting that there is no edge between *x* and *y*. Each pair is listed at most once; (*x*,<=*y*) and (*y*,<=*x*) are considered the same (so they are never listed in the same test). If some pair of vertices is not listed in the input, then there exists an edge between those vertices.
Firstly print *k* — the number of connected components in this graph. Then print *k* integers — the sizes of components. You should output these integers in non-descending order.
[ "5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n" ]
[ "2\n1 4 " ]
none
0
[ { "input": "5 5\n1 2\n3 4\n3 2\n4 2\n2 5", "output": "2\n1 4 " }, { "input": "8 15\n2 1\n4 5\n2 4\n3 4\n2 5\n3 5\n2 6\n3 6\n5 6\n4 6\n2 7\n3 8\n2 8\n3 7\n6 7", "output": "1\n8 " }, { "input": "12 58\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 10\n1 11\n1 12\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n4 5\n4 6\n4 8\n4 11\n4 12\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n7 8\n7 9\n7 10\n7 11\n7 12\n8 9\n8 10\n8 11\n9 10\n9 11\n9 12\n10 12", "output": "4\n1 1 1 9 " }, { "input": "5 7\n1 2\n2 3\n3 4\n1 5\n2 5\n3 5\n4 5", "output": "2\n1 4 " }, { "input": "6 10\n1 2\n1 3\n1 4\n1 6\n2 3\n2 4\n2 5\n3 5\n3 6\n4 6", "output": "1\n6 " }, { "input": "8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8", "output": "3\n1 2 5 " }, { "input": "4 3\n2 1\n3 1\n4 2", "output": "1\n4 " }, { "input": "6 9\n1 2\n1 4\n1 5\n2 3\n2 5\n2 6\n3 5\n4 6\n5 6", "output": "1\n6 " }, { "input": "2 0", "output": "1\n2 " }, { "input": "8 18\n1 4\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 8\n4 7\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8", "output": "1\n8 " }, { "input": "4 3\n1 2\n3 1\n4 3", "output": "1\n4 " }, { "input": "8 23\n2 7\n7 5\n8 6\n8 2\n6 3\n3 5\n8 1\n8 4\n8 3\n3 4\n1 2\n2 6\n5 2\n6 4\n7 6\n6 5\n7 8\n7 1\n5 4\n3 7\n1 4\n3 1\n3 2", "output": "3\n1 3 4 " }, { "input": "4 4\n2 1\n3 1\n1 4\n3 2", "output": "2\n1 3 " }, { "input": "2 1\n1 2", "output": "2\n1 1 " }, { "input": "4 3\n1 3\n1 4\n2 3", "output": "1\n4 " }, { "input": "3 1\n2 3", "output": "1\n3 " }, { "input": "5 4\n1 4\n2 3\n4 3\n4 2", "output": "1\n5 " }, { "input": "10 36\n7 8\n7 9\n2 3\n2 4\n2 5\n9 10\n2 7\n2 8\n2 9\n2 10\n4 5\n4 6\n4 7\n4 8\n4 10\n6 7\n6 9\n6 10\n1 2\n1 3\n1 4\n8 9\n1 5\n8 10\n1 7\n1 8\n1 9\n1 10\n3 4\n3 6\n3 7\n3 9\n5 6\n5 7\n5 9\n5 10", "output": "2\n2 8 " }, { "input": "10 34\n7 10\n2 3\n2 4\n2 5\n9 10\n2 7\n2 8\n2 10\n4 5\n4 6\n4 7\n4 8\n4 9\n6 7\n6 8\n6 9\n6 10\n1 2\n1 3\n1 5\n8 9\n1 6\n1 7\n1 8\n1 9\n1 10\n3 4\n3 5\n3 6\n3 8\n3 10\n5 6\n5 9\n5 10", "output": "1\n10 " }, { "input": "12 56\n9 5\n2 6\n9 8\n5 4\n1 11\n1 6\n4 1\n1 10\n10 3\n8 4\n5 1\n9 1\n5 10\n2 7\n11 5\n6 11\n5 8\n7 6\n3 2\n12 7\n8 6\n12 3\n1 2\n8 1\n2 11\n10 12\n4 6\n5 12\n2 4\n10 2\n7 3\n12 11\n7 10\n7 1\n9 2\n11 9\n9 10\n8 7\n11 3\n7 9\n5 7\n4 12\n3 5\n12 2\n4 10\n9 12\n5 2\n9 4\n11 8\n8 2\n3 6\n4 11\n8 10\n6 10\n3 9\n3 4", "output": "3\n1 4 7 " }, { "input": "11 49\n10 3\n6 4\n11 3\n7 6\n10 6\n6 1\n4 3\n10 2\n4 5\n9 2\n10 1\n5 7\n1 5\n9 7\n2 11\n8 6\n3 9\n2 5\n9 5\n6 5\n1 4\n11 9\n1 7\n8 10\n3 6\n3 7\n11 5\n6 9\n4 10\n8 7\n4 9\n8 2\n4 2\n8 11\n7 4\n9 10\n8 1\n10 7\n3 2\n5 8\n8 9\n1 3\n2 7\n10 11\n5 3\n10 5\n4 11\n1 11\n8 3", "output": "5\n1 1 1 2 6 " } ]
1,618,877,066
2,147,483,647
PyPy 3
MEMORY_LIMIT_EXCEEDED
TESTS
8
2,292
268,390,400
import sys input = sys.stdin.buffer.readline n,m = map(int,input().split()) adj = [set() for i in range(n+1)] for i in range(m): x,y = map(int,input().split()) adj[x].add(y) adj[y].add(x) unpaired = set([i for i in range(1,n+1)]) comps = [] vis = [0]*(n+1) for i in range(1,n+1): if not vis[i]: comps.append(0) s = [i] while s: c = s[-1] if not vis[c]: comps[-1] += 1 vis[c] = 1 unpaired.remove(c) for ne in unpaired: if ne not in adj[c]: s.append(ne) else: s.pop() print(len(comps)) print(*sorted(comps))
Title: Connected Components? Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an undirected graph consisting of *n* vertices and edges. Instead of giving you the edges that exist in the graph, we give you *m* unordered pairs (*x*,<=*y*) such that there is no edge between *x* and *y*, and if some pair of vertices is not listed in the input, then there is an edge between these vertices. You have to find the number of connected components in the graph and the size of each component. A connected component is a set of vertices *X* such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to *X* violates this rule. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=200000, ). Then *m* lines follow, each containing a pair of integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*, *x*<=≠<=*y*) denoting that there is no edge between *x* and *y*. Each pair is listed at most once; (*x*,<=*y*) and (*y*,<=*x*) are considered the same (so they are never listed in the same test). If some pair of vertices is not listed in the input, then there exists an edge between those vertices. Output Specification: Firstly print *k* — the number of connected components in this graph. Then print *k* integers — the sizes of components. You should output these integers in non-descending order. Demo Input: ['5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n'] Demo Output: ['2\n1 4 '] Note: none
```python import sys input = sys.stdin.buffer.readline n,m = map(int,input().split()) adj = [set() for i in range(n+1)] for i in range(m): x,y = map(int,input().split()) adj[x].add(y) adj[y].add(x) unpaired = set([i for i in range(1,n+1)]) comps = [] vis = [0]*(n+1) for i in range(1,n+1): if not vis[i]: comps.append(0) s = [i] while s: c = s[-1] if not vis[c]: comps[-1] += 1 vis[c] = 1 unpaired.remove(c) for ne in unpaired: if ne not in adj[c]: s.append(ne) else: s.pop() print(len(comps)) print(*sorted(comps)) ```
0
678
C
Joty and Chocolate
PROGRAMMING
1,600
[ "implementation", "math", "number theory" ]
null
null
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue. After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximum number of chocolates Joty can get.
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
Print the only integer *s* — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "5 2 3 12 15\n", "20 2 3 3 5\n" ]
[ "39\n", "51\n" ]
none
0
[ { "input": "5 2 3 12 15", "output": "39" }, { "input": "20 2 3 3 5", "output": "51" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1 2 2 2 2", "output": "0" }, { "input": "2 1 3 3 3", "output": "6" }, { "input": "3 1 1 3 3", "output": "9" }, { "input": "4 1 5 4 3", "output": "16" }, { "input": "8 8 1 1 1", "output": "8" }, { "input": "15 14 32 65 28", "output": "65" }, { "input": "894 197 325 232 902", "output": "2732" }, { "input": "8581 6058 3019 2151 4140", "output": "10431" }, { "input": "41764 97259 54586 18013 75415", "output": "0" }, { "input": "333625 453145 800800 907251 446081", "output": "0" }, { "input": "4394826 2233224 609367 3364334 898489", "output": "9653757" }, { "input": "13350712 76770926 61331309 8735000 9057368", "output": "0" }, { "input": "142098087 687355301 987788392 75187408 868856364", "output": "0" }, { "input": "1000000000 1 3 1000000000 999999999", "output": "1000000000000000000" }, { "input": "6 6 2 8 2", "output": "12" }, { "input": "500 8 4 4 5", "output": "625" }, { "input": "20 4 6 2 3", "output": "17" }, { "input": "10 3 9 1 2", "output": "4" }, { "input": "120 18 6 3 5", "output": "100" }, { "input": "30 4 6 2 2", "output": "20" }, { "input": "1000000000 7171 2727 191 272", "output": "125391842" }, { "input": "5 2 2 4 1", "output": "8" }, { "input": "1000000000 2 2 3 3", "output": "1500000000" }, { "input": "24 4 6 5 7", "output": "48" }, { "input": "216 6 36 10 100", "output": "900" }, { "input": "100 12 6 1 10", "output": "160" }, { "input": "1000 4 8 3 5", "output": "1000" }, { "input": "10 2 4 3 6", "output": "21" }, { "input": "1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "10 5 10 2 3", "output": "5" }, { "input": "100000 3 9 1 2", "output": "44444" }, { "input": "10 2 4 1 100", "output": "203" }, { "input": "20 6 4 2 3", "output": "19" }, { "input": "1200 4 16 2 3", "output": "675" }, { "input": "7 2 4 7 9", "output": "23" }, { "input": "24 6 4 15 10", "output": "100" }, { "input": "50 2 8 15 13", "output": "375" }, { "input": "100 4 6 12 15", "output": "444" }, { "input": "56756 9 18 56 78", "output": "422502" }, { "input": "10000 4 6 10 12", "output": "36662" }, { "input": "20 2 4 3 5", "output": "40" }, { "input": "24 4 6 10 100", "output": "440" }, { "input": "12 2 4 5 6", "output": "33" }, { "input": "100 2 4 1 100", "output": "2525" }, { "input": "1000 4 6 50 50", "output": "16650" }, { "input": "60 12 6 12 15", "output": "150" }, { "input": "1000 2 4 5 6", "output": "2750" }, { "input": "1000000000 1 1 9999 5555", "output": "9999000000000" }, { "input": "50 2 2 4 5", "output": "125" }, { "input": "14 4 2 2 3", "output": "21" }, { "input": "100 3 9 1 2", "output": "44" }, { "input": "1000000000 4 6 1 1000000000", "output": "166666666166666667" }, { "input": "12 3 3 45 4", "output": "180" }, { "input": "12 2 4 5 9", "output": "42" }, { "input": "1000000000 2 2 1000000000 1000000000", "output": "500000000000000000" }, { "input": "50 4 8 5 6", "output": "66" }, { "input": "32 4 16 6 3", "output": "48" }, { "input": "10000 2 4 1 1", "output": "5000" }, { "input": "8 2 4 100 1", "output": "400" }, { "input": "20 4 2 10 1", "output": "55" }, { "input": "5 2 2 12 15", "output": "30" }, { "input": "20 2 12 5 6", "output": "51" }, { "input": "10 2 4 1 2", "output": "7" }, { "input": "32 4 16 3 6", "output": "30" }, { "input": "50 2 8 13 15", "output": "337" }, { "input": "12 6 4 10 9", "output": "38" }, { "input": "1000000000 999999998 999999999 999999998 999999999", "output": "1999999997" }, { "input": "20 2 4 10 20", "output": "150" }, { "input": "13 4 6 12 15", "output": "54" }, { "input": "30 3 6 5 7", "output": "60" }, { "input": "7 2 4 2 1", "output": "6" }, { "input": "100000 32 16 2 3", "output": "18750" }, { "input": "6 2 6 1 1", "output": "3" }, { "input": "999999999 180 192 46642017 28801397", "output": "399129078526502" }, { "input": "12 4 6 1 1", "output": "4" }, { "input": "10 2 4 10 5", "output": "50" }, { "input": "1000000 4 6 12 14", "output": "4333328" }, { "input": "2000 20 30 3 5", "output": "531" }, { "input": "1000000000 1 2 1 1", "output": "1000000000" }, { "input": "30 3 15 10 3", "output": "100" }, { "input": "1000 2 4 1 100", "output": "25250" }, { "input": "6 3 3 12 15", "output": "30" }, { "input": "24 4 6 1 1", "output": "8" }, { "input": "20 2 12 4 5", "output": "41" }, { "input": "1000000000 9 15 10 10", "output": "1555555550" }, { "input": "16 2 4 1 2", "output": "12" }, { "input": "100000 4 6 12 14", "output": "433328" }, { "input": "24 6 4 1 1", "output": "8" }, { "input": "1000000 4 6 12 15", "output": "4499994" }, { "input": "100 2 4 5 6", "output": "275" }, { "input": "10 3 9 12 15", "output": "39" }, { "input": "1000000000 1 1 999999999 999999999", "output": "999999999000000000" }, { "input": "6 2 4 2 3", "output": "7" }, { "input": "2 2 2 2 2", "output": "2" }, { "input": "6 6 2 1 1", "output": "3" }, { "input": "100 2 4 3 7", "output": "250" }, { "input": "1000000 32 16 2 5", "output": "312500" }, { "input": "100 20 15 50 25", "output": "375" }, { "input": "1000000000 100000007 100000013 10 3", "output": "117" }, { "input": "1000000000 9999999 99999998 3 3", "output": "330" }, { "input": "10077696 24 36 10 100", "output": "30792960" }, { "input": "392852503 148746166 420198270 517065752 906699795", "output": "1034131504" }, { "input": "536870912 60000 72000 271828 314159", "output": "4369119072" }, { "input": "730114139 21550542 204644733 680083361 11353255", "output": "22476810678" }, { "input": "538228881 766493289 791886544 468896052 600136703", "output": "0" }, { "input": "190 20 50 84 172", "output": "1188" }, { "input": "1000 5 10 80 90", "output": "17000" }, { "input": "99999999 999999998 1 271828 314159", "output": "31415899685841" }, { "input": "22 3 6 1243 1", "output": "8701" }, { "input": "15 10 5 2 2", "output": "6" }, { "input": "1000000000 1000000000 1 1000000000 1000000000", "output": "1000000000000000000" }, { "input": "62 62 42 78 124", "output": "202" }, { "input": "2 2 2 2 1", "output": "2" }, { "input": "864351351 351 313 531 11", "output": "1337898227" }, { "input": "26 3 6 1244 1", "output": "9952" }, { "input": "1000 4 6 7 3", "output": "1999" }, { "input": "134312 3 6 33333 1", "output": "1492318410" }, { "input": "100 4 6 17 18", "output": "577" }, { "input": "6 2 4 5 6", "output": "16" }, { "input": "8 2 4 10 1", "output": "40" }, { "input": "10 2 4 3 3", "output": "15" }, { "input": "1000 1000 1000 1000 1000", "output": "1000" }, { "input": "123123 3 6 34312 2", "output": "1408198792" }, { "input": "1000000000 25 5 999 999", "output": "199800000000" }, { "input": "100 4 2 5 12", "output": "600" }, { "input": "50 2 4 4 5", "output": "112" }, { "input": "24 4 6 100 333", "output": "1732" }, { "input": "216 24 36 10 100", "output": "660" }, { "input": "50 6 4 3 8", "output": "108" }, { "input": "146 76 2 178 192", "output": "14016" }, { "input": "55 8 6 11 20", "output": "224" }, { "input": "5 2 4 6 16", "output": "22" }, { "input": "54 2 52 50 188", "output": "1488" }, { "input": "536870912 60000000 72000000 271828 314159", "output": "4101909" }, { "input": "1000000000 1000000000 1 1 100", "output": "100000000000" }, { "input": "50 4 2 4 5", "output": "125" }, { "input": "198 56 56 122 118", "output": "366" }, { "input": "5 1000000000 1 12 15", "output": "75" }, { "input": "1000 6 12 5 6", "output": "913" }, { "input": "50 3 6 12 15", "output": "216" }, { "input": "333 300 300 300 300", "output": "300" }, { "input": "1 1000000000 1 1 2", "output": "2" }, { "input": "188 110 110 200 78", "output": "200" }, { "input": "100000 20 10 3 2", "output": "25000" }, { "input": "100 2 4 1 10", "output": "275" }, { "input": "1000000000 2 1000000000 1 1000000", "output": "500999999" }, { "input": "20 3 6 5 7", "output": "36" }, { "input": "50 4 6 4 5", "output": "72" }, { "input": "96 46 4 174 156", "output": "3936" }, { "input": "5 2 4 12 15", "output": "27" }, { "input": "12 3 6 100 1", "output": "400" }, { "input": "100 4 2 10 32", "output": "1600" }, { "input": "1232 3 6 30000 3", "output": "12300000" }, { "input": "20 3 6 5 4", "output": "30" }, { "input": "100 6 15 11 29", "output": "317" }, { "input": "10000000 4 8 100 200", "output": "375000000" }, { "input": "1000000000 12 24 2 4", "output": "249999998" }, { "input": "123 3 6 3000 1", "output": "123000" }, { "input": "401523968 1536 2664 271828 314159", "output": "117768531682" }, { "input": "9 2 4 3 5", "output": "16" }, { "input": "999999999 724362018 772432019 46201854 20017479", "output": "66219333" }, { "input": "100 2 4 1 1000", "output": "25025" }, { "input": "50 2 4 1 1000", "output": "12013" }, { "input": "1000000000 2 1 2 1", "output": "1500000000" }, { "input": "1000000000 2005034 2005046 15 12", "output": "13446" }, { "input": "1000000000 999999999 1000000000 1 1", "output": "2" }, { "input": "999999999 500000000 1 100 1000", "output": "999999999000" }, { "input": "50 8 6 3 4", "output": "44" }, { "input": "1000000000 1 1 1000000000 1000000000", "output": "1000000000000000000" }, { "input": "1000000000 999999862 999999818 15 12", "output": "27" }, { "input": "1000000000 10000019 10000019 21 17", "output": "2079" }, { "input": "20 6 4 8 2", "output": "32" }, { "input": "1000000000 1000000000 1 1 1", "output": "1000000000" }, { "input": "1000000000 12345678 123456789 1000000000 999999999", "output": "88999999992" }, { "input": "1000000000 2 999999937 100000000 100000000", "output": "50000000100000000" }, { "input": "1000000000 1 1 1000000000 999999999", "output": "1000000000000000000" }, { "input": "1000000000 50001 100003 10 10", "output": "299980" }, { "input": "1000000000 1000000000 3 1 1", "output": "333333334" }, { "input": "10000 44 49 114 514", "output": "130278" }, { "input": "30 5 15 2 1", "output": "12" }, { "input": "20 2 4 1 1", "output": "10" }, { "input": "100 8 12 5 6", "output": "88" } ]
1,630,367,829
2,147,483,647
PyPy 3
OK
TESTS
185
109
20,172,800
from sys import stdin, stdout def read(): return stdin.readline().rstrip() def read_int(): return int(read()) def read_ints(): return list(map(int, read().split())) def gcd(x,y): while y>0: x,y=y,x%y return x def solve(): n,a,b,p,q=read_ints() print((n//a)*p + (n//b)*q - (n//(a*b//gcd(a,b)))*min(p,q)) solve()
Title: Joty and Chocolate Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue. After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximum number of chocolates Joty can get. Input Specification: The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). Output Specification: Print the only integer *s* — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Demo Input: ['5 2 3 12 15\n', '20 2 3 3 5\n'] Demo Output: ['39\n', '51\n'] Note: none
```python from sys import stdin, stdout def read(): return stdin.readline().rstrip() def read_int(): return int(read()) def read_ints(): return list(map(int, read().split())) def gcd(x,y): while y>0: x,y=y,x%y return x def solve(): n,a,b,p,q=read_ints() print((n//a)*p + (n//b)*q - (n//(a*b//gcd(a,b)))*min(p,q)) solve() ```
3
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", "output": "21223442" }, { "input": "91730629", "output": "91230320" }, { "input": "420062703497", "output": "420032203402" }, { "input": "332711047202", "output": "332211042202" }, { "input": "3395184971407775", "output": "3304114021402224" }, { "input": "8464062628894325", "output": "1434032321104324" }, { "input": "164324828731963982", "output": "134324121231033012" }, { "input": "384979173822804784", "output": "314020123122104214" }, { "input": "41312150450968417", "output": "41312140440031412" }, { "input": "2156", "output": "2143" }, { "input": "1932", "output": "1032" }, { "input": "5902", "output": "4002" }, { "input": "5728", "output": "4221" }, { "input": "8537", "output": "1432" }, { "input": "55403857", "output": "44403142" }, { "input": "270739", "output": "220230" }, { "input": "28746918", "output": "21243011" }, { "input": "10279211", "output": "10220211" }, { "input": "40289679", "output": "40210320" }, { "input": "545203238506", "output": "444203231403" }, { "input": "461117063340", "output": "431112033340" }, { "input": "658492686568", "output": "341402313431" }, { "input": "857373361868", "output": "142323331131" }, { "input": "429325660016", "output": "420324330013" }, { "input": "9894448650287940", "output": "9104441340212040" }, { "input": "6354510839296263", "output": "3344410130203233" }, { "input": "6873575462224593", "output": "3123424432224403" }, { "input": "4237951492601449", "output": "4232041402301440" }, { "input": "2680352384836991", "output": "2310342314133001" }, { "input": "606187734191890310", "output": "303112234101100310" }, { "input": "351499943576823355", "output": "341400043423123344" }, { "input": "180593481782177068", "output": "110403411212122031" }, { "input": "999999999999999999", "output": "900000000000000000" }, { "input": "1000000000000000000", "output": "1000000000000000000" }, { "input": "9999", "output": "9000" }, { "input": "99", "output": "90" }, { "input": "9991", "output": "9001" } ]
1,683,287,065
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
77
0
import math n=int(input()) t=n num=0 i=0 while t: temp=t%10 temp=min(temp, 9-temp) num+=((temp)*pow(10, i)) i+=1 t=int(t/10) if num==0: print(n) else: print(num)
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. Input Specification: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. Output Specification: Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. Demo Input: ['27\n', '4545\n'] Demo Output: ['22\n', '4444\n'] Note: none
```python import math n=int(input()) t=n num=0 i=0 while t: temp=t%10 temp=min(temp, 9-temp) num+=((temp)*pow(10, i)) i+=1 t=int(t/10) if num==0: print(n) else: print(num) ```
0
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6", "output": "3" }, { "input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32", "output": "6" }, { "input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30", "output": "10" }, { "input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20", "output": "8" }, { "input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49", "output": "1" }, { "input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16", "output": "5" }, { "input": "2\n0 24\n1 0", "output": "1" }, { "input": "1\n0 0", "output": "1" }, { "input": "1\n1 5", "output": "1" }, { "input": "1\n1 1", "output": "1" }, { "input": "3\n0 0\n0 0\n0 0", "output": "3" }, { "input": "1\n5 0", "output": "1" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "5" }, { "input": "1\n10 10", "output": "1" }, { "input": "1\n8 0", "output": "1" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "10" }, { "input": "2\n0 0\n0 1", "output": "1" }, { "input": "2\n8 5\n8 5", "output": "2" } ]
1,674,650,753
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
0
s=[[],[]] for _ in range(int(input())): a,b=map(int,input().split()) if b in s[0]: s[1][0]+=1 else: s[1].append(1) s[0].append(b) print(max(s[1]))
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period. Output Specification: Print a single integer — the minimum number of cashes, needed to serve all clients next day. Demo Input: ['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
```python s=[[],[]] for _ in range(int(input())): a,b=map(int,input().split()) if b in s[0]: s[1][0]+=1 else: s[1].append(1) s[0].append(b) print(max(s[1])) ```
0
545
C
Woodcutters
PROGRAMMING
1,500
[ "dp", "greedy" ]
null
null
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Print a single number — the maximum number of trees that you can cut down by the given rules.
[ "5\n1 2\n2 1\n5 10\n10 9\n19 1\n", "5\n1 2\n2 1\n5 10\n10 9\n20 1\n" ]
[ "3\n", "4\n" ]
In the first sample you can fell the trees like that: - fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
1,750
[ { "input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3" }, { "input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4" }, { "input": "4\n10 4\n15 1\n19 3\n20 1", "output": "4" }, { "input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4", "output": "10" }, { "input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1", "output": "2" }, { "input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8", "output": "5" }, { "input": "1\n1000000000 1000000000", "output": "1" }, { "input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1", "output": "9" }, { "input": "3\n1 1\n1000 1000\n1000000000 1000000000", "output": "3" }, { "input": "2\n1 999999999\n1000000000 1000000000", "output": "2" }, { "input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000", "output": "2" }, { "input": "2\n100000000 1000000000\n1000000000 1000000000", "output": "2" } ]
1,697,646,809
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
31
102,400
e = int(input()) x = [0] * (e+1) h = [0] * (e+1) gp = [[0] * 5 for _ in range(e +1)] for i in range(1, e+1): x[i], h[i] = map(int, input().split()) if e== 1: print(1) exit(0) if x[1] + h[1] < x[2]: dp[1][2] = 1 gp[1][1] = 1 for i in range(2,e+1): p1 =gp[i-1][0] p2 = gp[i-1][1] p3 =gp[i-1][2] gp[i][0] = max(p1, p2, p3) if x[i] - x[i-1] > h[i] + h[i-1]: gp[i][1] =gp[i][0] + 1 elif x[i] - x[i-1] > h[i]: gp[i][1] = 1 + max(p1, p2) if i+1 <= e and x[i+1] - x[i] > h[i]: gp[i][2] = 1 + gp[i][0] if i ==e: gp[i][2] = 1 + gp[i][0] print(max(gp[e][2], gp[e][0], gp[e][1]))
Title: Woodcutters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. Output Specification: Print a single number — the maximum number of trees that you can cut down by the given rules. Demo Input: ['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n'] Demo Output: ['3\n', '4\n'] Note: In the first sample you can fell the trees like that: - fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
```python e = int(input()) x = [0] * (e+1) h = [0] * (e+1) gp = [[0] * 5 for _ in range(e +1)] for i in range(1, e+1): x[i], h[i] = map(int, input().split()) if e== 1: print(1) exit(0) if x[1] + h[1] < x[2]: dp[1][2] = 1 gp[1][1] = 1 for i in range(2,e+1): p1 =gp[i-1][0] p2 = gp[i-1][1] p3 =gp[i-1][2] gp[i][0] = max(p1, p2, p3) if x[i] - x[i-1] > h[i] + h[i-1]: gp[i][1] =gp[i][0] + 1 elif x[i] - x[i-1] > h[i]: gp[i][1] = 1 + max(p1, p2) if i+1 <= e and x[i+1] - x[i] > h[i]: gp[i][2] = 1 + gp[i][0] if i ==e: gp[i][2] = 1 + gp[i][0] print(max(gp[e][2], gp[e][0], gp[e][1])) ```
-1
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment. For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place. Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single space.
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "6\n2 3 2 2 1 3", "output": "4" }, { "input": "8\n2 2 5 3 4 3 3 2", "output": "4" }, { "input": "7\n4 1 3 2 2 4 5", "output": "4" }, { "input": "3\n3 5 1", "output": "4" }, { "input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2", "output": "5" }, { "input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1", "output": "4" }, { "input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4", "output": "5" }, { "input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3", "output": "5" }, { "input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3", "output": "4" }, { "input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2", "output": "4" }, { "input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3", "output": "5" }, { "input": "6\n4 2 3 1 3 5", "output": "4" }, { "input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4", "output": "5" }, { "input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2", "output": "5" }, { "input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3", "output": "5" }, { "input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1", "output": "5" }, { "input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5", "output": "5" }, { "input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3", "output": "5" }, { "input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2", "output": "5" }, { "input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1", "output": "5" }, { "input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5", "output": "5" }, { "input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3", "output": "5" }, { "input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "4" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "5" } ]
1,499,926,848
2,147,483,647
Python 3
OK
TESTS
30
124
5,529,600
n = int(input()) string = input() a = sum(list(map(int, string.split()))) b = 0 for x in range(1, 6): if (a + x) % (n + 1) != 1: b += 1 print(b)
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment. For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place. Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single space. Output Specification: In a single line print the answer to the problem. Demo Input: ['1\n1\n', '1\n2\n', '2\n3 5\n'] Demo Output: ['3\n', '2\n', '3\n'] Note: In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
```python n = int(input()) string = input() a = sum(list(map(int, string.split()))) b = 0 for x in range(1, 6): if (a + x) % (n + 1) != 1: b += 1 print(b) ```
3
0
none
none
none
0
[ "none" ]
null
null
A factory produces thimbles in bulk. Typically, it can produce up to *a* thimbles a day. However, some of the machinery is defective, so it can currently only produce *b* thimbles each day. The factory intends to choose a *k*-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of *a* thimbles per day after the *k* days are complete. Initially, no orders are pending. The factory receives updates of the form *d**i*, *a**i*, indicating that *a**i* new orders have been placed for the *d**i*-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes. As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day *p**i*. Help the owner answer his questions.
The first line contains five integers *n*, *k*, *a*, *b*, and *q* (1<=≤<=*k*<=≤<=*n*<=≤<=200<=000, 1<=≤<=*b*<=&lt;<=*a*<=≤<=10 000, 1<=≤<=*q*<=≤<=200<=000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next *q* lines contain the descriptions of the queries. Each query is of one of the following two forms: - 1 *d**i* *a**i* (1<=≤<=*d**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=10 000), representing an update of *a**i* orders on day *d**i*, or - 2 *p**i* (1<=≤<=*p**i*<=≤<=*n*<=-<=*k*<=+<=1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day *p**i*? It's guaranteed that the input will contain at least one query of the second type.
For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all *n* days.
[ "5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n", "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n" ]
[ "3\n6\n4\n", "7\n1\n" ]
Consider the first sample. We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days. For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled. For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.
0
[ { "input": "5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3", "output": "3\n6\n4" }, { "input": "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2", "output": "7\n1" }, { "input": "1 1 2 1 1\n2 1", "output": "0" } ]
1,456,685,835
2,835
PyPy 3
WRONG_ANSWER
PRETESTS
0
93
0
n, k, a, b, q = map(int, input().split()) g1 = [0] * (n + 1) g2 = [0] * (n + 1) p = [] for i in range(q): s = input().split() if len(s) == 3: h, d = int(s[1]), int(s[2]) g1[h] += d g2[h] += d else: p.append(int(s[1])) sum = 0 for i in range(n + 1): sum += min(g1[i], b) g1[i] = sum sum = 0 for i in range(n + 1): sum += min(g2[i], a) g2[i] = sum for i in range(len(p)): sum1 = g1[p[i] - 1] - g1[0] sum2 = g2[-1] - g2[p[i] + k - 1] print(sum1 + sum2)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A factory produces thimbles in bulk. Typically, it can produce up to *a* thimbles a day. However, some of the machinery is defective, so it can currently only produce *b* thimbles each day. The factory intends to choose a *k*-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of *a* thimbles per day after the *k* days are complete. Initially, no orders are pending. The factory receives updates of the form *d**i*, *a**i*, indicating that *a**i* new orders have been placed for the *d**i*-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes. As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day *p**i*. Help the owner answer his questions. Input Specification: The first line contains five integers *n*, *k*, *a*, *b*, and *q* (1<=≤<=*k*<=≤<=*n*<=≤<=200<=000, 1<=≤<=*b*<=&lt;<=*a*<=≤<=10 000, 1<=≤<=*q*<=≤<=200<=000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next *q* lines contain the descriptions of the queries. Each query is of one of the following two forms: - 1 *d**i* *a**i* (1<=≤<=*d**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=10 000), representing an update of *a**i* orders on day *d**i*, or - 2 *p**i* (1<=≤<=*p**i*<=≤<=*n*<=-<=*k*<=+<=1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day *p**i*? It's guaranteed that the input will contain at least one query of the second type. Output Specification: For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all *n* days. Demo Input: ['5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n', '5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n'] Demo Output: ['3\n6\n4\n', '7\n1\n'] Note: Consider the first sample. We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days. For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled. For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.
```python n, k, a, b, q = map(int, input().split()) g1 = [0] * (n + 1) g2 = [0] * (n + 1) p = [] for i in range(q): s = input().split() if len(s) == 3: h, d = int(s[1]), int(s[2]) g1[h] += d g2[h] += d else: p.append(int(s[1])) sum = 0 for i in range(n + 1): sum += min(g1[i], b) g1[i] = sum sum = 0 for i in range(n + 1): sum += min(g2[i], a) g2[i] = sum for i in range(len(p)): sum1 = g1[p[i] - 1] - g1[0] sum2 = g2[-1] - g2[p[i] + k - 1] print(sum1 + sum2) ```
0
909
B
Segments
PROGRAMMING
1,300
[ "constructive algorithms", "math" ]
null
null
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given *N*.
The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100).
Output a single integer - the minimal number of layers required to draw the segments for the given *N*.
[ "2\n", "3\n", "4\n" ]
[ "2\n", "4\n", "6\n" ]
As an example, here are the segments and their optimal arrangement into layers for *N* = 4.
1,000
[ { "input": "2", "output": "2" }, { "input": "3", "output": "4" }, { "input": "4", "output": "6" }, { "input": "21", "output": "121" }, { "input": "100", "output": "2550" }, { "input": "1", "output": "1" }, { "input": "5", "output": "9" }, { "input": "6", "output": "12" }, { "input": "7", "output": "16" }, { "input": "8", "output": "20" }, { "input": "9", "output": "25" }, { "input": "10", "output": "30" }, { "input": "11", "output": "36" }, { "input": "12", "output": "42" }, { "input": "13", "output": "49" }, { "input": "14", "output": "56" }, { "input": "15", "output": "64" }, { "input": "16", "output": "72" }, { "input": "17", "output": "81" }, { "input": "18", "output": "90" }, { "input": "19", "output": "100" }, { "input": "20", "output": "110" }, { "input": "22", "output": "132" }, { "input": "23", "output": "144" }, { "input": "24", "output": "156" }, { "input": "25", "output": "169" }, { "input": "26", "output": "182" }, { "input": "27", "output": "196" }, { "input": "28", "output": "210" }, { "input": "29", "output": "225" }, { "input": "30", "output": "240" }, { "input": "31", "output": "256" }, { "input": "32", "output": "272" }, { "input": "33", "output": "289" }, { "input": "34", "output": "306" }, { "input": "35", "output": "324" }, { "input": "36", "output": "342" }, { "input": "37", "output": "361" }, { "input": "38", "output": "380" }, { "input": "39", "output": "400" }, { "input": "40", "output": "420" }, { "input": "41", "output": "441" }, { "input": "42", "output": "462" }, { "input": "43", "output": "484" }, { "input": "44", "output": "506" }, { "input": "45", "output": "529" }, { "input": "46", "output": "552" }, { "input": "47", "output": "576" }, { "input": "48", "output": "600" }, { "input": "49", "output": "625" }, { "input": "50", "output": "650" }, { "input": "51", "output": "676" }, { "input": "52", "output": "702" }, { "input": "53", "output": "729" }, { "input": "54", "output": "756" }, { "input": "55", "output": "784" }, { "input": "56", "output": "812" }, { "input": "57", "output": "841" }, { "input": "58", "output": "870" }, { "input": "59", "output": "900" }, { "input": "60", "output": "930" }, { "input": "61", "output": "961" }, { "input": "62", "output": "992" }, { "input": "63", "output": "1024" }, { "input": "64", "output": "1056" }, { "input": "65", "output": "1089" }, { "input": "66", "output": "1122" }, { "input": "67", "output": "1156" }, { "input": "68", "output": "1190" }, { "input": "69", "output": "1225" }, { "input": "70", "output": "1260" }, { "input": "71", "output": "1296" }, { "input": "72", "output": "1332" }, { "input": "73", "output": "1369" }, { "input": "74", "output": "1406" }, { "input": "75", "output": "1444" }, { "input": "76", "output": "1482" }, { "input": "77", "output": "1521" }, { "input": "78", "output": "1560" }, { "input": "79", "output": "1600" }, { "input": "80", "output": "1640" }, { "input": "81", "output": "1681" }, { "input": "82", "output": "1722" }, { "input": "83", "output": "1764" }, { "input": "84", "output": "1806" }, { "input": "85", "output": "1849" }, { "input": "86", "output": "1892" }, { "input": "87", "output": "1936" }, { "input": "88", "output": "1980" }, { "input": "89", "output": "2025" }, { "input": "90", "output": "2070" }, { "input": "91", "output": "2116" }, { "input": "92", "output": "2162" }, { "input": "93", "output": "2209" }, { "input": "94", "output": "2256" }, { "input": "95", "output": "2304" }, { "input": "96", "output": "2352" }, { "input": "97", "output": "2401" }, { "input": "98", "output": "2450" }, { "input": "99", "output": "2500" }, { "input": "1", "output": "1" }, { "input": "5", "output": "9" } ]
1,592,654,649
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
for i in range(1): n=int(input()) s=0 for i in range(1,n+1): s=i+s print(s) x=s/2 if x>int(x): print(int(x)+1) else: print(int(x))
Title: Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given *N*. Input Specification: The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). Output Specification: Output a single integer - the minimal number of layers required to draw the segments for the given *N*. Demo Input: ['2\n', '3\n', '4\n'] Demo Output: ['2\n', '4\n', '6\n'] Note: As an example, here are the segments and their optimal arrangement into layers for *N* = 4.
```python for i in range(1): n=int(input()) s=0 for i in range(1,n+1): s=i+s print(s) x=s/2 if x>int(x): print(int(x)+1) else: print(int(x)) ```
0
769
D
k-Interesting Pairs Of Integers
PROGRAMMING
1,700
[ "*special", "bitmasks", "brute force", "meet-in-the-middle" ]
null
null
Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=101 and *y*=011 differs exactly in two bits. Vasya wants to know how many pairs of indexes (*i*, *j*) are in his sequence so that *i*<=&lt;<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. Your task is to help Vasya and determine this number.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=104), which Vasya has.
Print the number of pairs (*i*, *j*) so that *i*<=&lt;<=*j* and the pair of integers *a**i* and *a**j* is k-interesting.
[ "4 1\n0 3 2 1\n", "6 0\n200 100 100 100 200 200\n" ]
[ "4\n", "6\n" ]
In the first test there are 4 k-interesting pairs: - (1, 3), - (1, 4), - (2, 3), - (2, 4). In the second test *k* = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs: - (1, 5), - (1, 6), - (2, 3), - (2, 4), - (3, 4), - (5, 6).
2,000
[ { "input": "4 1\n0 3 2 1", "output": "4" }, { "input": "6 0\n200 100 100 100 200 200", "output": "6" }, { "input": "2 0\n1 1", "output": "1" }, { "input": "2 0\n0 0", "output": "1" }, { "input": "2 0\n10000 10000", "output": "1" }, { "input": "2 0\n0 10000", "output": "0" }, { "input": "2 1\n0 1", "output": "1" }, { "input": "2 1\n0 2", "output": "1" }, { "input": "3 1\n0 1 2", "output": "2" }, { "input": "3 2\n0 3 3", "output": "2" }, { "input": "3 2\n3 3 3", "output": "0" }, { "input": "10 0\n1 1 1 1 1 1 1 1 1 1", "output": "45" }, { "input": "100 14\n8192 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8191 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8192 8192 8192 8192 8192 8192 8191 8191 8192 8192 8191 8191 8192 8192 8192 8191 8191 8192 8191 8191 8191 8191 8191 8191 8192 8191 8191 8192 8191 8191 8192 8192 8191 8192 8192 8192 8192 8192 8192 8192 8191 8192 8192 8192 8191 8191 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8192 8192 8191 8192 8192 8192 8192 8191 8192 8191 8191 8192 8191 8192 8192 8191 8191", "output": "2400" } ]
1,488,640,245
11,445
Python 3
WRONG_ANSWER
PRETESTS
6
62
4,915,200
def pr(a,b): a = str(a) b = str(b) if len(a)>len(b): k = len(a) - len(b) for i in range(len(b),0): for j in range(len(a),0): if a-b == j-i and b[i] != a[j]: k+=1 else: k = len(b) - len(a) for i in range(len(a),0): for j in range(len(b),0): if b-a == j-i and a[i] != b[j]: k+=1 return k def main(): n,m = map(int,input().split()) arr = list(map(int,input().split())) for i in range(n): k = 1 b = 0 while (arr[i]!=0): b += arr[i] % 2 * k arr[i] //= 2 k *= 10 arr[i] = b q = 0 for i in range(n): for j in range(i+1,n): p = pr(arr[i],arr[j]) if p == m: q+=1; print(q) main()
Title: k-Interesting Pairs Of Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=101 and *y*=011 differs exactly in two bits. Vasya wants to know how many pairs of indexes (*i*, *j*) are in his sequence so that *i*<=&lt;<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. Your task is to help Vasya and determine this number. Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=104), which Vasya has. Output Specification: Print the number of pairs (*i*, *j*) so that *i*<=&lt;<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. Demo Input: ['4 1\n0 3 2 1\n', '6 0\n200 100 100 100 200 200\n'] Demo Output: ['4\n', '6\n'] Note: In the first test there are 4 k-interesting pairs: - (1, 3), - (1, 4), - (2, 3), - (2, 4). In the second test *k* = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs: - (1, 5), - (1, 6), - (2, 3), - (2, 4), - (3, 4), - (5, 6).
```python def pr(a,b): a = str(a) b = str(b) if len(a)>len(b): k = len(a) - len(b) for i in range(len(b),0): for j in range(len(a),0): if a-b == j-i and b[i] != a[j]: k+=1 else: k = len(b) - len(a) for i in range(len(a),0): for j in range(len(b),0): if b-a == j-i and a[i] != b[j]: k+=1 return k def main(): n,m = map(int,input().split()) arr = list(map(int,input().split())) for i in range(n): k = 1 b = 0 while (arr[i]!=0): b += arr[i] % 2 * k arr[i] //= 2 k *= 10 arr[i] = b q = 0 for i in range(n): for j in range(i+1,n): p = pr(arr[i],arr[j]) if p == m: q+=1; print(q) main() ```
0
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "input": "2 2\n20 10", "output": "1" }, { "input": "2 1\n20 1", "output": "2" }, { "input": "3 1\n1 2 3", "output": "1" }, { "input": "3 1\n2 1 3", "output": "2" }, { "input": "3 1\n3 2 1", "output": "3" }, { "input": "3 2\n1 2 3", "output": "1" }, { "input": "3 2\n3 2 1", "output": "2" }, { "input": "3 3\n1 2 3", "output": "1" }, { "input": "4 2\n9 8 11 7", "output": "1" }, { "input": "4 2\n10 1 2 3", "output": "2" }, { "input": "6 3\n56 56 56 2 1 2", "output": "4" }, { "input": "8 3\n1 1 1 1 2 60 90 1", "output": "1" }, { "input": "4 1\n1 5 2 2", "output": "1" }, { "input": "4 2\n4 6 7 4", "output": "1" }, { "input": "10 4\n1 1 1 4 4 4 4 4 4 3", "output": "1" }, { "input": "6 3\n1 2 1 3 1 1", "output": "1" }, { "input": "5 2\n100 100 100 1 1", "output": "4" } ]
1,688,494,412
2,147,483,647
PyPy 3-64
OK
TESTS
51
93
17,612,800
from sys import stdin, stdout def input(): return stdin.readline().strip() def print(string): return stdout.write(str(string) + "\n") def main(): n, k = map(int, input().split()) h = [int(x) for x in input().split()] dp = [None] * n dp[0] = sum(h[:k]) smallest_i = 0 for i in range(n-k): dp[i+1] = dp[i] - h[i] + h[i+k] if dp[i+1] < dp[smallest_i]: smallest_i = i+1 print(smallest_i+1) if __name__ == "__main__": main()
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). Input Specification: The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. Output Specification: Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. Demo Input: ['7 3\n1 2 6 1 1 7 1\n'] Demo Output: ['3\n'] Note: In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
```python from sys import stdin, stdout def input(): return stdin.readline().strip() def print(string): return stdout.write(str(string) + "\n") def main(): n, k = map(int, input().split()) h = [int(x) for x in input().split()] dp = [None] * n dp[0] = sum(h[:k]) smallest_i = 0 for i in range(n-k): dp[i+1] = dp[i] - h[i] + h[i+k] if dp[i+1] < dp[smallest_i]: smallest_i = i+1 print(smallest_i+1) if __name__ == "__main__": main() ```
3
716
A
Crazy Computer
PROGRAMMING
800
[ "implementation" ]
null
null
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=&gt;<=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen. For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen. You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=...<=&lt;<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word.
Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*.
[ "6 5\n1 3 8 14 19 20\n", "6 1\n1 3 5 7 9 10\n" ]
[ "3", "2" ]
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.
500
[ { "input": "6 5\n1 3 8 14 19 20", "output": "3" }, { "input": "6 1\n1 3 5 7 9 10", "output": "2" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "5 5\n1 7 12 13 14", "output": "4" }, { "input": "2 1000000000\n1 1000000000", "output": "2" }, { "input": "3 5\n1 10 20", "output": "1" }, { "input": "3 10\n1 2 3", "output": "3" }, { "input": "2 1\n1 100", "output": "1" }, { "input": "3 1\n1 2 10", "output": "1" }, { "input": "2 1\n1 2", "output": "2" } ]
1,568,221,442
2,147,483,647
PyPy 3
OK
TESTS
81
249
11,366,400
n,c=map(int,input().split()) s=1 l=list(map(int,input().split())) a=l[0] b=0 for i in range(1,len(l)): b=l[i] if(b-a<=c): s+=1 else: s=1 a=l[i] print(str(s),end="")
Title: Crazy Computer Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=&gt;<=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen. For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen. You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything. Input Specification: The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=...<=&lt;<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word. Output Specification: Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. Demo Input: ['6 5\n1 3 8 14 19 20\n', '6 1\n1 3 5 7 9 10\n'] Demo Output: ['3', '2'] Note: The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.
```python n,c=map(int,input().split()) s=1 l=list(map(int,input().split())) a=l[0] b=0 for i in range(1,len(l)): b=l[i] if(b-a<=c): s+=1 else: s=1 a=l[i] print(str(s),end="") ```
3
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcdefghijklm" }, { "input": "100 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "100 10", "output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij" }, { "input": "3 3", "output": "abc" }, { "input": "6 3", "output": "abcabc" }, { "input": "10 3", "output": "abcabcabca" }, { "input": "50 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab" }, { "input": "90 2", "output": "ababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "6 2", "output": "ababab" }, { "input": "99 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc" }, { "input": "4 2", "output": "abab" }, { "input": "100 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "40 22", "output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr" }, { "input": "13 8", "output": "abcdefghabcde" }, { "input": "16 15", "output": "abcdefghijklmnoa" }, { "input": "17 17", "output": "abcdefghijklmnopq" }, { "input": "19 4", "output": "abcdabcdabcdabcdabc" }, { "input": "100 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv" }, { "input": "100 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy" }, { "input": "26 26", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "27 26", "output": "abcdefghijklmnopqrstuvwxyza" }, { "input": "2 2", "output": "ab" }, { "input": "26 25", "output": "abcdefghijklmnopqrstuvwxya" }, { "input": "99 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababa" }, { "input": "99 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu" }, { "input": "4 4", "output": "abcd" }, { "input": "5 3", "output": "abcab" }, { "input": "5 4", "output": "abcda" }, { "input": "5 5", "output": "abcde" }, { "input": "24 22", "output": "abcdefghijklmnopqrstuvab" }, { "input": "26 14", "output": "abcdefghijklmnabcdefghijkl" }, { "input": "26 15", "output": "abcdefghijklmnoabcdefghijk" }, { "input": "30 12", "output": "abcdefghijklabcdefghijklabcdef" }, { "input": "35 4", "output": "abcdabcdabcdabcdabcdabcdabcdabcdabc" }, { "input": "79 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "79 14", "output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi" }, { "input": "85 13", "output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg" }, { "input": "90 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno" }, { "input": "90 19", "output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn" }, { "input": "26 24", "output": "abcdefghijklmnopqrstuvwxab" }, { "input": "100 17", "output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno" }, { "input": "26 2", "output": "ababababababababababababab" } ]
1,650,487,800
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
409,600
import random import string alpha ='abcdefghijklmnopqrstuvwxyz' x = int(input()) c = int(input()) password = '' for i in range(0,c): password +=alpha[i] for i in range(c,x): password+= password[i-c] print(password)
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. Input Specification: The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists. Output Specification: Print any password which satisfies all conditions given by Innokentiy. Demo Input: ['4 3\n', '6 6\n', '5 2\n'] Demo Output: ['java\n', 'python\n', 'phphp\n'] Note: In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
```python import random import string alpha ='abcdefghijklmnopqrstuvwxyz' x = int(input()) c = int(input()) password = '' for i in range(0,c): password +=alpha[i] for i in range(c,x): password+= password[i-c] print(password) ```
-1
515
C
Drazil and Factorial
PROGRAMMING
1,400
[ "greedy", "math", "sortings" ]
null
null
Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions: 1. *x* doesn't contain neither digit 0 nor digit 1. 2. = . Help friends find such number.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
[ "4\n1234\n", "3\n555\n" ]
[ "33222\n", "555\n" ]
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "4\n1234", "output": "33222" }, { "input": "3\n555", "output": "555" }, { "input": "15\n012345781234578", "output": "7777553333222222222222" }, { "input": "1\n8", "output": "7222" }, { "input": "10\n1413472614", "output": "75333332222222" }, { "input": "8\n68931246", "output": "77553333332222222" }, { "input": "7\n4424368", "output": "75333332222222222" }, { "input": "6\n576825", "output": "7755532222" }, { "input": "5\n97715", "output": "7775332" }, { "input": "3\n915", "output": "75332" }, { "input": "2\n26", "output": "532" }, { "input": "1\n4", "output": "322" }, { "input": "15\n028745260720699", "output": "7777755533333332222222222" }, { "input": "13\n5761790121605", "output": "7775555333322" }, { "input": "10\n3312667105", "output": "755533332" }, { "input": "1\n7", "output": "7" }, { "input": "15\n989898989898989", "output": "777777777777777333333333333333322222222222222222222222222222" }, { "input": "15\n000000000000007", "output": "7" }, { "input": "15\n999999999999990", "output": "77777777777777333333333333333333333333333322222222222222" }, { "input": "1\n2", "output": "2" }, { "input": "1\n3", "output": "3" }, { "input": "1\n4", "output": "322" }, { "input": "1\n5", "output": "5" }, { "input": "1\n6", "output": "53" }, { "input": "1\n7", "output": "7" }, { "input": "1\n9", "output": "7332" }, { "input": "2\n09", "output": "7332" }, { "input": "13\n1337251172966", "output": "777555333333222" }, { "input": "15\n987654329876543", "output": "777777555533333333332222222222222" }, { "input": "9\n234567899", "output": "777755333333322222222" }, { "input": "2\n99", "output": "77333322" }, { "input": "2\n66", "output": "5533" }, { "input": "3\n999", "output": "777333333222" }, { "input": "5\n99999", "output": "77777333333333322222" }, { "input": "9\n123456789", "output": "77755333332222222" }, { "input": "9\n987654321", "output": "77755333332222222" }, { "input": "3\n666", "output": "555333" }, { "input": "2\n26", "output": "532" }, { "input": "6\n555777", "output": "777555" }, { "input": "10\n1234567899", "output": "777755333333322222222" }, { "input": "4\n6666", "output": "55553333" }, { "input": "4\n9754", "output": "775333222" }, { "input": "2\n95", "output": "75332" }, { "input": "14\n11122233344455", "output": "55333333222222222" }, { "input": "12\n836544897832", "output": "77777553333333222222222222222" } ]
1,602,596,428
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
108
0
n=int(input()) digits=list(map(int,input())) print(digits) countfact={2:0,3:0,5:0,7:0} def fact(n): mydict={2:0,3:0,5:0,7:0} factor=[i for i in range(1,n+1)] for val in factor: if val==2: mydict[2]+=1 elif val==3: mydict[3]+=1 elif val==4: mydict[2]+=2 elif val==5: mydict[5]+=1 elif val==6: mydict[3]+=1 mydict[2]+=1 elif val==7: mydict[7]+=1 elif val==8: mydict[2]+=3 elif val==9: mydict[3]+=2 return mydict for digit in digits: tmp=fact(digit) for key in tmp.keys(): countfact[key]+=tmp[key] while countfact[2]!=0: if countfact[7]!=0: tmp=fact(7) print("7",end="") for key in tmp.keys(): countfact[key]-=tmp[key] elif countfact[5]!=0: tmp=fact(5) print("5",end="") for key in tmp.keys(): countfact[key]-=tmp[key] elif countfact[3]!=0: tmp=fact(3) print("3",end="") for key in tmp.keys(): countfact[key]-=tmp[key] elif countfact[2]!=0: tmp=fact(2) print("2",end="") for key in tmp.keys(): countfact[key]-=tmp[key]
Title: Drazil and Factorial Time Limit: None seconds Memory Limit: None megabytes Problem Description: Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions: 1. *x* doesn't contain neither digit 0 nor digit 1. 2. = . Help friends find such number. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. Output Specification: Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. Demo Input: ['4\n1234\n', '3\n555\n'] Demo Output: ['33222\n', '555\n'] Note: In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n=int(input()) digits=list(map(int,input())) print(digits) countfact={2:0,3:0,5:0,7:0} def fact(n): mydict={2:0,3:0,5:0,7:0} factor=[i for i in range(1,n+1)] for val in factor: if val==2: mydict[2]+=1 elif val==3: mydict[3]+=1 elif val==4: mydict[2]+=2 elif val==5: mydict[5]+=1 elif val==6: mydict[3]+=1 mydict[2]+=1 elif val==7: mydict[7]+=1 elif val==8: mydict[2]+=3 elif val==9: mydict[3]+=2 return mydict for digit in digits: tmp=fact(digit) for key in tmp.keys(): countfact[key]+=tmp[key] while countfact[2]!=0: if countfact[7]!=0: tmp=fact(7) print("7",end="") for key in tmp.keys(): countfact[key]-=tmp[key] elif countfact[5]!=0: tmp=fact(5) print("5",end="") for key in tmp.keys(): countfact[key]-=tmp[key] elif countfact[3]!=0: tmp=fact(3) print("3",end="") for key in tmp.keys(): countfact[key]-=tmp[key] elif countfact[2]!=0: tmp=fact(2) print("2",end="") for key in tmp.keys(): countfact[key]-=tmp[key] ```
0
19
D
Points
PROGRAMMING
2,800
[ "data structures" ]
D. Points
2
256
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0,<=0) is located in the bottom-left corner, *Ox* axis is directed right, *Oy* axis is directed up. Pete gives Bob requests of three types: - add x y — on the sheet of paper Bob marks a point with coordinates (*x*,<=*y*). For each request of this type it's guaranteed that point (*x*,<=*y*) is not yet marked on Bob's sheet at the time of the request. - remove x y — on the sheet of paper Bob erases the previously marked point with coordinates (*x*,<=*y*). For each request of this type it's guaranteed that point (*x*,<=*y*) is already marked on Bob's sheet at the time of the request. - find x y — on the sheet of paper Bob finds all the marked points, lying strictly above and strictly to the right of point (*x*,<=*y*). Among these points Bob chooses the leftmost one, if it is not unique, he chooses the bottommost one, and gives its coordinates to Pete. Bob managed to answer the requests, when they were 10, 100 or 1000, but when their amount grew up to 2·105, Bob failed to cope. Now he needs a program that will answer all Pete's requests. Help Bob, please!
The first input line contains number *n* (1<=≤<=*n*<=≤<=2·105) — amount of requests. Then there follow *n* lines — descriptions of the requests. add x y describes the request to add a point, remove x y — the request to erase a point, find x y — the request to find the bottom-left point. All the coordinates in the input file are non-negative and don't exceed 109.
For each request of type find x y output in a separate line the answer to it — coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (*x*,<=*y*). If there are no points strictly above and to the right of point (*x*,<=*y*), output -1.
[ "7\nadd 1 1\nadd 3 4\nfind 0 0\nremove 1 1\nfind 0 0\nadd 1 1\nfind 0 0\n", "13\nadd 5 5\nadd 5 6\nadd 5 7\nadd 6 5\nadd 6 6\nadd 6 7\nadd 7 5\nadd 7 6\nadd 7 7\nfind 6 6\nremove 7 7\nfind 6 6\nfind 4 4\n" ]
[ "1 1\n3 4\n1 1\n", "7 7\n-1\n5 5\n" ]
none
0
[]
1,601,246,388
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
819,200
def DPoints2_find(s,sk,l): find_x=-1 find_y=-1 for i in sk: if i>l[0]: for j in s[i]: if j>l[1]: find_y=j find_x=i break if find_y!=-1: break if find_y==-1: return -1 else: return [find_x,find_y] sheet={} sheet_k=[] result=[] n=int(input()) for _ in range(0,n): oper=input() oper=oper.split() if oper[0]=="add": if int(oper[1]) in sheet.keys(): sheet[int(oper[1])].append(int(oper[2])) sheet[int(oper[1])]=sorted(sheet[int(oper[1])]) else: sheet[int(oper[1])]=[] sheet[int(oper[1])].append(int(oper[2])) sheet[int(oper[1])]=sorted(sheet[int(oper[1])]) sheet_k=sorted(sheet.keys()) elif oper[0]=="remove": sheet[int(oper[1])].remove(int(oper[2])) if len(sheet[int(oper[1])])==0: del sheet[int(oper[1])] sheet_k.remove(int(oper[1])) else: result.append(DPoints2_find(sheet,sheet_k,[int(oper[1]),int(oper[2])])) for i in result: if i==-1: print(i) else: print(*i)
Title: Points Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0,<=0) is located in the bottom-left corner, *Ox* axis is directed right, *Oy* axis is directed up. Pete gives Bob requests of three types: - add x y — on the sheet of paper Bob marks a point with coordinates (*x*,<=*y*). For each request of this type it's guaranteed that point (*x*,<=*y*) is not yet marked on Bob's sheet at the time of the request. - remove x y — on the sheet of paper Bob erases the previously marked point with coordinates (*x*,<=*y*). For each request of this type it's guaranteed that point (*x*,<=*y*) is already marked on Bob's sheet at the time of the request. - find x y — on the sheet of paper Bob finds all the marked points, lying strictly above and strictly to the right of point (*x*,<=*y*). Among these points Bob chooses the leftmost one, if it is not unique, he chooses the bottommost one, and gives its coordinates to Pete. Bob managed to answer the requests, when they were 10, 100 or 1000, but when their amount grew up to 2·105, Bob failed to cope. Now he needs a program that will answer all Pete's requests. Help Bob, please! Input Specification: The first input line contains number *n* (1<=≤<=*n*<=≤<=2·105) — amount of requests. Then there follow *n* lines — descriptions of the requests. add x y describes the request to add a point, remove x y — the request to erase a point, find x y — the request to find the bottom-left point. All the coordinates in the input file are non-negative and don't exceed 109. Output Specification: For each request of type find x y output in a separate line the answer to it — coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (*x*,<=*y*). If there are no points strictly above and to the right of point (*x*,<=*y*), output -1. Demo Input: ['7\nadd 1 1\nadd 3 4\nfind 0 0\nremove 1 1\nfind 0 0\nadd 1 1\nfind 0 0\n', '13\nadd 5 5\nadd 5 6\nadd 5 7\nadd 6 5\nadd 6 6\nadd 6 7\nadd 7 5\nadd 7 6\nadd 7 7\nfind 6 6\nremove 7 7\nfind 6 6\nfind 4 4\n'] Demo Output: ['1 1\n3 4\n1 1\n', '7 7\n-1\n5 5\n'] Note: none
```python def DPoints2_find(s,sk,l): find_x=-1 find_y=-1 for i in sk: if i>l[0]: for j in s[i]: if j>l[1]: find_y=j find_x=i break if find_y!=-1: break if find_y==-1: return -1 else: return [find_x,find_y] sheet={} sheet_k=[] result=[] n=int(input()) for _ in range(0,n): oper=input() oper=oper.split() if oper[0]=="add": if int(oper[1]) in sheet.keys(): sheet[int(oper[1])].append(int(oper[2])) sheet[int(oper[1])]=sorted(sheet[int(oper[1])]) else: sheet[int(oper[1])]=[] sheet[int(oper[1])].append(int(oper[2])) sheet[int(oper[1])]=sorted(sheet[int(oper[1])]) sheet_k=sorted(sheet.keys()) elif oper[0]=="remove": sheet[int(oper[1])].remove(int(oper[2])) if len(sheet[int(oper[1])])==0: del sheet[int(oper[1])] sheet_k.remove(int(oper[1])) else: result.append(DPoints2_find(sheet,sheet_k,[int(oper[1]),int(oper[2])])) for i in result: if i==-1: print(i) else: print(*i) ```
0
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "1 1 1 1 1 1", "output": "Elephant" }, { "input": "9 9 9 9 9 9", "output": "Elephant" }, { "input": "1 8 9 1 1 1", "output": "Bear" }, { "input": "9 9 9 1 9 9", "output": "Bear" }, { "input": "1 2 3 8 9 7", "output": "Alien" }, { "input": "5 5 5 6 6 6", "output": "Alien" }, { "input": "1 1 2 2 3 4", "output": "Alien" }, { "input": "4 4 4 4 4 2", "output": "Bear" }, { "input": "2 2 3 3 4 4", "output": "Alien" }, { "input": "4 4 4 4 4 5", "output": "Bear" }, { "input": "1 1 2 2 2 2", "output": "Elephant" }, { "input": "1 2 5 5 5 5", "output": "Bear" }, { "input": "4 4 2 2 2 2", "output": "Elephant" }, { "input": "1 1 1 1 1 2", "output": "Bear" }, { "input": "2 2 4 4 4 4", "output": "Elephant" }, { "input": "4 4 4 4 4 3", "output": "Bear" }, { "input": "4 4 5 6 7 8", "output": "Alien" }, { "input": "4 4 4 4 2 2", "output": "Elephant" }, { "input": "1 1 1 1 2 2", "output": "Elephant" }, { "input": "1 1 3 3 3 5", "output": "Alien" }, { "input": "1 2 2 3 3 3", "output": "Alien" }, { "input": "1 2 2 2 2 2", "output": "Bear" }, { "input": "1 3 3 3 4 5", "output": "Alien" }, { "input": "5 1 1 1 1 1", "output": "Bear" } ]
1,653,783,028
2,147,483,647
Python 3
OK
TESTS
29
46
0
sticks = list(map(int, input().split())) #print(sticks) sticks.sort() hb = [(0, 5), (4, 5), (0, 1)] for head, body in hb: cur = sticks[3] flag = True for i in range(6): if i != head and i != body: if sticks[i] != cur: flag = False break if not flag: continue if sticks[head] < sticks[body]: print("Bear") else: print("Elephant") exit() print("Alien")
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. Input Specification: The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. Output Specification: If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). Demo Input: ['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n'] Demo Output: ['Bear', 'Elephant', 'Alien'] Note: If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
```python sticks = list(map(int, input().split())) #print(sticks) sticks.sort() hb = [(0, 5), (4, 5), (0, 1)] for head, body in hb: cur = sticks[3] flag = True for i in range(6): if i != head and i != body: if sticks[i] != cur: flag = False break if not flag: continue if sticks[head] < sticks[body]: print("Bear") else: print("Elephant") exit() print("Alien") ```
3
766
B
Mahmoud and a Triangle
PROGRAMMING
1,000
[ "constructive algorithms", "geometry", "greedy", "math", "number theory", "sortings" ]
null
null
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle. Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
[ "5\n1 5 3 2 4\n", "3\n4 1 2\n" ]
[ "YES\n", "NO\n" ]
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
1,000
[ { "input": "5\n1 5 3 2 4", "output": "YES" }, { "input": "3\n4 1 2", "output": "NO" }, { "input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576", "output": "NO" }, { "input": "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 177115397 62179276 390270885 754889875 881720571 902691435 154083299 328505383 761264351 182674686 94104683 357622370 573909964 320060691 33548810 247029007 812823597 946798893 813659359 710111761", "output": "YES" }, { "input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 915774563 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 354134861 132333165 405839062 522698334 29698277 541005920 856214146 167344951 398332403 68622974", "output": "YES" }, { "input": "40\n155 1470176 7384 765965701 1075 4 561554 6227772 93 16304522 1744 662 3 292572860 19335 908613 42685804 347058 20 132560 3848974 69067081 58 2819 111752888 408 81925 30 11951 4564 251 26381275 473392832 50628 180819969 2378797 10076746 9 214492 31291", "output": "NO" }, { "input": "3\n1 1000000000 1000000000", "output": "YES" }, { "input": "4\n1 1000000000 1000000000 1000000000", "output": "YES" }, { "input": "3\n1 1000000000 1", "output": "NO" }, { "input": "5\n1 2 3 5 2", "output": "YES" }, { "input": "41\n19 161 4090221 118757367 2 45361275 1562319 596751 140871 97 1844 310910829 10708344 6618115 698 1 87059 33 2527892 12703 73396090 17326460 3 368811 20550 813975131 10 53804 28034805 7847 2992 33254 1139 227930 965568 261 4846 503064297 192153458 57 431", "output": "NO" }, { "input": "42\n4317083 530966905 202811311 104 389267 35 1203 18287479 125344279 21690 859122498 65 859122508 56790 1951 148683 457 1 22 2668100 8283 2 77467028 13405 11302280 47877251 328155592 35095 29589769 240574 4 10 1019123 6985189 629846 5118 169 1648973 91891 741 282 3159", "output": "YES" }, { "input": "43\n729551585 11379 5931704 330557 1653 15529406 729551578 278663905 1 729551584 2683 40656510 29802 147 1400284 2 126260 865419 51 17 172223763 86 1 534861 450887671 32 234 25127103 9597697 48226 7034 389 204294 2265706 65783617 4343 3665990 626 78034 106440137 5 18421 1023", "output": "YES" }, { "input": "44\n719528276 2 235 444692918 24781885 169857576 18164 47558 15316043 9465834 64879816 2234575 1631 853530 8 1001 621 719528259 84 6933 31 1 3615623 719528266 40097928 274835337 1381044 11225 2642 5850203 6 527506 18 104977753 76959 29393 49 4283 141 201482 380 1 124523 326015", "output": "YES" }, { "input": "45\n28237 82 62327732 506757 691225170 5 970 4118 264024506 313192 367 14713577 73933 691225154 6660 599 691225145 3473403 51 427200630 1326718 2146678 100848386 1569 27 163176119 193562 10784 45687 819951 38520653 225 119620 1 3 691225169 691225164 17445 23807072 1 9093493 5620082 2542 139 14", "output": "YES" }, { "input": "44\n165580141 21 34 55 1 89 144 17711 2 377 610 987 2584 13 5 4181 6765 10946 1597 8 28657 3 233 75025 121393 196418 317811 9227465 832040 1346269 2178309 3524578 5702887 1 14930352 102334155 24157817 39088169 63245986 701408733 267914296 433494437 514229 46368", "output": "NO" }, { "input": "3\n1 1000000000 999999999", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "YES" }, { "input": "10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000", "output": "NO" }, { "input": "5\n2 3 4 10 20", "output": "YES" }, { "input": "6\n18 23 40 80 160 161", "output": "YES" }, { "input": "4\n5 6 7 888", "output": "YES" }, { "input": "9\n1 1 2 2 4 5 10 10 20", "output": "YES" }, { "input": "7\n3 150 900 4 500 1500 5", "output": "YES" }, { "input": "3\n2 2 3", "output": "YES" }, { "input": "7\n1 2 100 200 250 1000000 2000000", "output": "YES" }, { "input": "8\n2 3 5 5 5 6 6 13", "output": "YES" }, { "input": "3\n2 3 4", "output": "YES" }, { "input": "6\n1 1 1 4 5 100", "output": "YES" }, { "input": "13\n1 2 3 5 8 13 22 34 55 89 144 233 377", "output": "YES" }, { "input": "4\n2 3 4 8", "output": "YES" }, { "input": "3\n5 6 7", "output": "YES" }, { "input": "5\n1 4 5 6 1000000", "output": "YES" }, { "input": "4\n5 6 7 20", "output": "YES" }, { "input": "6\n1 1 1 1 1 65", "output": "YES" }, { "input": "4\n3 4 5 100", "output": "YES" }, { "input": "3\n2 4 5", "output": "YES" }, { "input": "7\n1 1 1 1 1 10 1000", "output": "YES" }, { "input": "4\n1 1 2 3", "output": "NO" }, { "input": "11\n1 2 5 6 7 8 9 17 18 19 100", "output": "YES" }, { "input": "4\n5 16 20 200", "output": "YES" }, { "input": "5\n17 6 3 3 1", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" }, { "input": "6\n1 1 1 2 3 5", "output": "YES" }, { "input": "4\n2 4 6 6", "output": "YES" }, { "input": "9\n1 2 4 4 4 4 7 8 20", "output": "YES" }, { "input": "9\n1 1 2 5 5 5 10 10 20", "output": "YES" }, { "input": "7\n3 150 600 4 1700 6000 5", "output": "YES" }, { "input": "5\n5761 20966 27841 28800 29399", "output": "YES" }, { "input": "9\n1 2 3 6 7 10 11 12 24", "output": "YES" }, { "input": "4\n1 2 1 1", "output": "YES" }, { "input": "5\n1 1 2 3 4", "output": "YES" } ]
1,655,541,797
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n, f=int(input()), 0 a=list(map(int,input().split())) a.sort() for i in range(1, n-1): if a[i-1]+a[i]<=a[i+1]: f+=1 break if f==1: print("YES") else: print("NO")
Title: Mahmoud and a Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle. Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area. Input Specification: The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. Output Specification: In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. Demo Input: ['5\n1 5 3 2 4\n', '3\n4 1 2\n'] Demo Output: ['YES\n', 'NO\n'] Note: For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
```python n, f=int(input()), 0 a=list(map(int,input().split())) a.sort() for i in range(1, n-1): if a[i-1]+a[i]<=a[i+1]: f+=1 break if f==1: print("YES") else: print("NO") ```
0
302
A
Eugeny and Array
PROGRAMMING
800
[ "implementation" ]
null
null
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries.
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
[ "2 3\n1 -1\n1 1\n1 2\n2 2\n", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n" ]
[ "0\n1\n0\n", "0\n1\n0\n1\n0\n" ]
none
500
[ { "input": "2 3\n1 -1\n1 1\n1 2\n2 2", "output": "0\n1\n0" }, { "input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5", "output": "0\n1\n0\n1\n0" }, { "input": "3 3\n1 1 1\n2 2\n1 1\n1 1", "output": "0\n0\n0" }, { "input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1", "output": "0\n0\n0\n0" }, { "input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4", "output": "0\n0\n0\n0\n0" }, { "input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4", "output": "0\n1\n0\n0\n0\n1" }, { "input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7", "output": "0\n0\n0\n0\n0\n0\n1" }, { "input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3", "output": "0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5", "output": "0\n1\n0\n0\n0\n0\n0\n1\n0" }, { "input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1", "output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0" }, { "input": "1 1\n-1\n1 1", "output": "0" }, { "input": "1 1\n1\n1 1", "output": "0" } ]
1,632,581,855
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
6,758,400
n, m = map(int, input().split()) a = list(map(int, input().split())) ans = [] for i in range(m): l, r = map(int, input().split()) result = 0 if (r - l + 1) % 2 else 1 ans.append(result) for val in ans: print(val)
Title: Eugeny and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries. Input Specification: The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Output Specification: Print *m* integers — the responses to Eugene's queries in the order they occur in the input. Demo Input: ['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n'] Demo Output: ['0\n1\n0\n', '0\n1\n0\n1\n0\n'] Note: none
```python n, m = map(int, input().split()) a = list(map(int, input().split())) ans = [] for i in range(m): l, r = map(int, input().split()) result = 0 if (r - l + 1) % 2 else 1 ans.append(result) for val in ans: print(val) ```
0
740
A
Alyona and copybooks
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
[ "1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n" ]
[ "3\n", "1\n", "0\n", "1000000000\n" ]
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
500
[ { "input": "1 1 3 4", "output": "3" }, { "input": "6 2 1 1", "output": "1" }, { "input": "4 4 4 4", "output": "0" }, { "input": "999999999 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1016 3 2 1", "output": "0" }, { "input": "17 100 100 1", "output": "1" }, { "input": "17 2 3 100", "output": "5" }, { "input": "18 1 3 3", "output": "2" }, { "input": "19 1 1 1", "output": "1" }, { "input": "999999997 999999990 1000000000 1000000000", "output": "1000000000" }, { "input": "999999998 1000000000 999999990 1000000000", "output": "999999990" }, { "input": "634074578 336470888 481199252 167959139", "output": "335918278" }, { "input": "999999999 1000000000 1000000000 999999990", "output": "1000000000" }, { "input": "804928248 75475634 54748096 641009859", "output": "0" }, { "input": "535590429 374288891 923264237 524125987", "output": "524125987" }, { "input": "561219907 673102149 496813081 702209411", "output": "673102149" }, { "input": "291882089 412106895 365329221 585325539", "output": "585325539" }, { "input": "757703054 5887448 643910770 58376259", "output": "11774896" }, { "input": "783332532 449924898 72235422 941492387", "output": "0" }, { "input": "513994713 43705451 940751563 824608515", "output": "131116353" }, { "input": "539624191 782710197 514300407 2691939", "output": "8075817" }, { "input": "983359971 640274071 598196518 802030518", "output": "640274071" }, { "input": "8989449 379278816 26521171 685146646", "output": "405799987" }, { "input": "34618927 678092074 895037311 863230070", "output": "678092074" }, { "input": "205472596 417096820 468586155 41313494", "output": "0" }, { "input": "19 5 1 2", "output": "3" }, { "input": "17 1 2 2", "output": "2" }, { "input": "18 3 3 1", "output": "2" }, { "input": "19 4 3 1", "output": "3" }, { "input": "936134778 715910077 747167704 219396918", "output": "438793836" }, { "input": "961764255 454914823 615683844 102513046", "output": "307539138" }, { "input": "692426437 48695377 189232688 985629174", "output": "146086131" }, { "input": "863280107 347508634 912524637 458679894", "output": "347508634" }, { "input": "593942288 86513380 486073481 341796022", "output": "0" }, { "input": "914539062 680293934 764655030 519879446", "output": "764655030" }, { "input": "552472140 509061481 586588704 452405440", "output": "0" }, { "input": "723325809 807874739 160137548 335521569", "output": "335521569" }, { "input": "748955287 546879484 733686393 808572289", "output": "546879484" }, { "input": "774584765 845692742 162011045 691688417", "output": "691688417" }, { "input": "505246946 439473295 30527185 869771841", "output": "30527185" }, { "input": "676100616 178478041 604076030 752887969", "output": "0" }, { "input": "701730093 477291299 177624874 930971393", "output": "654916173" }, { "input": "432392275 216296044 751173719 109054817", "output": "216296044" }, { "input": "458021753 810076598 324722563 992170945", "output": "992170945" }, { "input": "188683934 254114048 48014511 170254369", "output": "48014511" }, { "input": "561775796 937657403 280013594 248004555", "output": "0" }, { "input": "1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 10000 10000 3", "output": "9" }, { "input": "3 12 3 4", "output": "7" }, { "input": "3 10000 10000 1", "output": "3" }, { "input": "3 1000 1000 1", "output": "3" }, { "input": "3 10 10 1", "output": "3" }, { "input": "3 100 100 1", "output": "3" }, { "input": "3 100000 10000 1", "output": "3" }, { "input": "7 10 2 3", "output": "5" }, { "input": "3 1000 1000 2", "output": "6" }, { "input": "1 100000 1 100000", "output": "100000" }, { "input": "7 4 3 1", "output": "3" }, { "input": "3 1000 1000 3", "output": "9" }, { "input": "3 1000 1 1", "output": "2" }, { "input": "3 10 1 1", "output": "2" }, { "input": "3 100000 1 1", "output": "2" }, { "input": "3 100 1 1", "output": "2" }, { "input": "3 100000 100000 1", "output": "3" }, { "input": "3 1000 1 100", "output": "101" }, { "input": "3 1000000000 1 1000000000", "output": "1000000000" }, { "input": "3 1000 1 10", "output": "11" }, { "input": "3 200 1 100", "output": "101" }, { "input": "7 4 1 1", "output": "2" }, { "input": "7 4 12 1", "output": "3" }, { "input": "3 9 1 1", "output": "2" }, { "input": "3 10000000 1000000 1", "output": "3" }, { "input": "7 1000 1000 1", "output": "3" }, { "input": "3 10000 1 30", "output": "31" }, { "input": "3 1000 1 2", "output": "3" }, { "input": "7 12 6 1", "output": "3" }, { "input": "3 100000 1 1000", "output": "1001" }, { "input": "7 1000 1000 3", "output": "9" }, { "input": "3 4 3 1", "output": "3" }, { "input": "3 3000000 1 100000", "output": "100001" }, { "input": "3 3 1 1", "output": "2" }, { "input": "3 10 1 5", "output": "6" }, { "input": "3 2000 2000 1", "output": "3" }, { "input": "3 10000000 10000000 1", "output": "3" }, { "input": "3 5 1 1", "output": "2" }, { "input": "3 100 1 33", "output": "34" }, { "input": "7 9 2 7", "output": "9" }, { "input": "4448 2 3 6", "output": "0" }, { "input": "2228 1 6 3", "output": "0" } ]
1,479,920,574
1,674
Python 3
RUNTIME_ERROR
PRETESTS
2
46
0
d = input() d = [int(x) for x in d.split()] n,a,b,c = d[0],d[1],d[2],d[3] counter = [] if n%4==0: print(0) else: m = n%4 if m==3: counter.append(a) counter.append(b+c) elif m==2: counter.append(2*a) counter.append(b) counter.append(2*c) else: counter.append(b+a) counter.append(3*a) counter.append(c) print(min(counter))
Title: Alyona and copybooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input Specification: The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). Output Specification: Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. Demo Input: ['1 1 3 4\n', '6 2 1 1\n', '4 4 4 4\n', '999999999 1000000000 1000000000 1000000000\n'] Demo Output: ['3\n', '1\n', '0\n', '1000000000\n'] Note: In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
```python d = input() d = [int(x) for x in d.split()] n,a,b,c = d[0],d[1],d[2],d[3] counter = [] if n%4==0: print(0) else: m = n%4 if m==3: counter.append(a) counter.append(b+c) elif m==2: counter.append(2*a) counter.append(b) counter.append(2*c) else: counter.append(b+a) counter.append(3*a) counter.append(c) print(min(counter)) ```
-1
331
C1
The Great Julya Calendar
PROGRAMMING
1,100
[ "dp" ]
null
null
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!" Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.
The single line contains the magic integer *n*, 0<=≤<=*n*. - to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3).
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
[ "24\n" ]
[ "5" ]
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
20
[ { "input": "24", "output": "5" }, { "input": "0", "output": "0" }, { "input": "3", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "10", "output": "2" }, { "input": "31", "output": "6" }, { "input": "701", "output": "116" }, { "input": "222", "output": "39" }, { "input": "156", "output": "28" }, { "input": "12343", "output": "1778" }, { "input": "7984", "output": "1178" }, { "input": "1000000", "output": "128207" }, { "input": "1", "output": "1" }, { "input": "3", "output": "1" }, { "input": "5", "output": "1" }, { "input": "11", "output": "3" }, { "input": "77", "output": "14" }, { "input": "216", "output": "37" }, { "input": "1468", "output": "233" }, { "input": "1995", "output": "305" }, { "input": "11010", "output": "1568" }, { "input": "47320", "output": "6746" }, { "input": "258634", "output": "35024" } ]
1,608,833,155
2,147,483,647
Python 3
OK
TESTS1
24
404
0
n,c=int(input()),0 while n:n-=int(max(str(n)));c+=1 print(c)
Title: The Great Julya Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!" Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero. Input Specification: The single line contains the magic integer *n*, 0<=≤<=*n*. - to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3). Output Specification: Print a single integer — the minimum number of subtractions that turns the magic number to a zero. Demo Input: ['24\n'] Demo Output: ['5'] Note: In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
```python n,c=int(input()),0 while n:n-=int(max(str(n)));c+=1 print(c) ```
3
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,635,928,116
2,147,483,647
Python 3
OK
TESTS
96
46
4,300,800
def gcd(a, b): if a == 0: return b return gcd(b % a, a) def nok(a, b): return a // gcd(a, b) * b n, k = map(int, input().split()) print(nok(n, 10 ** k))
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python def gcd(a, b): if a == 0: return b return gcd(b % a, a) def nok(a, b): return a // gcd(a, b) * b n, k = map(int, input().split()) print(nok(n, 10 ** k)) ```
3
899
B
Months and Years
PROGRAMMING
1,200
[ "implementation" ]
null
null
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December. A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap. In this problem you are given *n* (1<=≤<=*n*<=≤<=24) integers *a*1,<=*a*2,<=...,<=*a**n*, and you have to check if these integers could be durations in days of *n* consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is *a*1 days, duration of the next month is *a*2 days, and so on.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check.
If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes). You can print each letter in arbitrary case (small or large).
[ "4\n31 31 30 31\n", "2\n30 30\n", "5\n29 31 30 31 30\n", "3\n31 28 30\n", "3\n31 31 28\n" ]
[ "Yes\n\n", "No\n\n", "Yes\n\n", "No\n\n", "Yes\n\n" ]
In the first example the integers can denote months July, August, September and October. In the second example the answer is no, because there are no two consecutive months each having 30 days. In the third example the months are: February (leap year) — March — April – May — June. In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO. In the fifth example the months are: December — January — February (non-leap year).
1,000
[ { "input": "4\n31 31 30 31", "output": "Yes" }, { "input": "2\n30 30", "output": "No" }, { "input": "5\n29 31 30 31 30", "output": "Yes" }, { "input": "3\n31 28 30", "output": "No" }, { "input": "3\n31 31 28", "output": "Yes" }, { "input": "24\n29 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "output": "No" }, { "input": "4\n31 29 31 30", "output": "Yes" }, { "input": "24\n31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "output": "Yes" }, { "input": "8\n31 29 31 30 31 30 31 31", "output": "Yes" }, { "input": "1\n29", "output": "Yes" }, { "input": "8\n31 29 31 30 31 31 31 31", "output": "No" }, { "input": "1\n31", "output": "Yes" }, { "input": "11\n30 31 30 31 31 30 31 30 31 31 28", "output": "Yes" }, { "input": "21\n30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31", "output": "Yes" }, { "input": "4\n31 28 28 30", "output": "No" }, { "input": "2\n30 31", "output": "Yes" }, { "input": "7\n28 31 30 31 30 31 31", "output": "Yes" }, { "input": "4\n28 31 30 31", "output": "Yes" }, { "input": "17\n28 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31", "output": "No" }, { "input": "9\n31 31 29 31 30 31 30 31 31", "output": "Yes" }, { "input": "4\n31 28 31 30", "output": "Yes" }, { "input": "21\n30 31 30 31 31 28 31 30 31 30 31 29 30 31 30 31 31 28 31 30 31", "output": "No" }, { "input": "2\n31 31", "output": "Yes" }, { "input": "17\n31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31", "output": "Yes" }, { "input": "4\n30 31 30 31", "output": "Yes" }, { "input": "12\n31 28 31 30 31 30 31 31 30 31 30 31", "output": "Yes" }, { "input": "12\n31 29 31 30 31 30 31 31 30 31 30 31", "output": "Yes" }, { "input": "11\n30 31 30 31 31 30 31 30 31 29 28", "output": "No" }, { "input": "22\n31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31", "output": "Yes" }, { "input": "14\n31 30 31 31 28 31 30 31 30 31 31 30 31 30", "output": "Yes" }, { "input": "12\n31 30 31 31 28 31 30 31 30 31 31 30", "output": "Yes" }, { "input": "4\n31 29 29 30", "output": "No" }, { "input": "7\n28 28 30 31 30 31 31", "output": "No" }, { "input": "9\n29 31 29 31 30 31 30 31 31", "output": "No" }, { "input": "17\n31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "output": "Yes" }, { "input": "2\n31 29", "output": "Yes" }, { "input": "12\n31 28 31 30 31 30 31 31 30 31 28 31", "output": "No" }, { "input": "2\n29 31", "output": "Yes" }, { "input": "12\n31 29 31 30 31 30 31 30 30 31 30 31", "output": "No" }, { "input": "12\n31 28 31 30 31 29 31 31 30 31 30 31", "output": "No" }, { "input": "22\n31 30 31 30 31 31 30 31 30 31 31 28 31 30 28 30 31 31 30 31 30 31", "output": "No" }, { "input": "14\n31 30 31 31 28 31 30 31 30 31 31 30 29 30", "output": "No" }, { "input": "19\n31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31", "output": "Yes" }, { "input": "20\n31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31", "output": "Yes" }, { "input": "1\n28", "output": "Yes" }, { "input": "1\n29", "output": "Yes" }, { "input": "17\n31 30 31 30 31 31 29 31 30 31 31 31 31 30 31 30 31", "output": "No" }, { "input": "1\n30", "output": "Yes" }, { "input": "1\n31", "output": "Yes" }, { "input": "24\n31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31", "output": "Yes" }, { "input": "24\n28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31", "output": "Yes" }, { "input": "12\n31 30 31 31 28 28 30 31 30 31 31 30", "output": "No" }, { "input": "24\n29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31", "output": "Yes" }, { "input": "24\n28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31", "output": "Yes" }, { "input": "24\n31 29 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "output": "No" }, { "input": "13\n28 31 30 31 30 31 31 30 31 30 31 31 28", "output": "Yes" }, { "input": "15\n31 31 28 31 30 31 30 31 31 30 31 30 31 31 29", "output": "Yes" }, { "input": "23\n31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31", "output": "Yes" }, { "input": "24\n31 30 31 30 31 31 30 31 30 31 31 30 31 30 31 30 31 31 30 31 30 31 31 30", "output": "No" }, { "input": "23\n29 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "output": "No" }, { "input": "15\n31 31 29 31 30 31 30 31 31 30 31 30 31 31 28", "output": "Yes" }, { "input": "12\n31 30 31 30 31 30 31 31 30 31 30 31", "output": "No" } ]
1,639,596,797
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
n = int(input()) months = '312931303130313130313031' m = input() for i in m: if i == ' ': m = m.replace(i,'') for i in m: if i == '8': m = m.replace(i,'9') if months.find(m) == -1: print('NO') else: print('YES')
Title: Months and Years Time Limit: None seconds Memory Limit: None megabytes Problem Description: Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December. A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap. In this problem you are given *n* (1<=≤<=*n*<=≤<=24) integers *a*1,<=*a*2,<=...,<=*a**n*, and you have to check if these integers could be durations in days of *n* consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is *a*1 days, duration of the next month is *a*2 days, and so on. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. Output Specification: If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes). You can print each letter in arbitrary case (small or large). Demo Input: ['4\n31 31 30 31\n', '2\n30 30\n', '5\n29 31 30 31 30\n', '3\n31 28 30\n', '3\n31 31 28\n'] Demo Output: ['Yes\n\n', 'No\n\n', 'Yes\n\n', 'No\n\n', 'Yes\n\n'] Note: In the first example the integers can denote months July, August, September and October. In the second example the answer is no, because there are no two consecutive months each having 30 days. In the third example the months are: February (leap year) — March — April – May — June. In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO. In the fifth example the months are: December — January — February (non-leap year).
```python n = int(input()) months = '312931303130313130313031' m = input() for i in m: if i == ' ': m = m.replace(i,'') for i in m: if i == '8': m = m.replace(i,'9') if months.find(m) == -1: print('NO') else: print('YES') ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,590,096,910
2,147,483,647
PyPy 3
OK
TESTS
102
140
0
a = input() n = len(a) a = int(a, 2) a ^= int(input(),2) a = bin(a)[2:] print('0'*(n-len(a))+a)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python a = input() n = len(a) a = int(a, 2) a ^= int(input(),2) a = bin(a)[2:] print('0'*(n-len(a))+a) ```
3.965
127
A
Wasted Time
PROGRAMMING
900
[ "geometry" ]
null
null
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second. Scrooge signed exactly *k* papers throughout his life and all those signatures look the same. Find the total time Scrooge wasted signing the papers.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space. All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6.
[ "2 1\n0 0\n10 0\n", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n" ]
[ "0.200000000", "6.032163204", "3.000000000" ]
none
500
[ { "input": "2 1\n0 0\n10 0", "output": "0.200000000" }, { "input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "output": "6.032163204" }, { "input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "output": "3.000000000" }, { "input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8", "output": "429.309294877" }, { "input": "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 -17\n-4 3\n13 -12\n11 -10\n18 7\n-6 11\n10 13\n10 3\n6 -14\n-1 10\n14 -15\n2 11\n-8 10", "output": "13629.282573522" }, { "input": "2 1\n-20 -10\n-10 -6", "output": "0.215406592" }, { "input": "2 13\n13 -10\n-3 -2", "output": "4.651021393" }, { "input": "2 21\n13 8\n14 10", "output": "0.939148551" }, { "input": "2 75\n-3 12\n1 12", "output": "6.000000000" }, { "input": "2 466\n10 16\n-6 -3", "output": "231.503997374" }, { "input": "2 999\n6 16\n-17 -14", "output": "755.286284531" }, { "input": "2 1000\n-17 -14\n-14 -8", "output": "134.164078650" }, { "input": "3 384\n-4 -19\n-17 -2\n3 4", "output": "324.722285390" }, { "input": "5 566\n-11 8\n2 -7\n7 0\n-7 -9\n-7 5", "output": "668.956254495" }, { "input": "7 495\n-10 -13\n-9 -5\n4 9\n8 13\n-4 2\n2 10\n-18 15", "output": "789.212495576" }, { "input": "10 958\n7 13\n20 19\n12 -7\n10 -10\n-13 -15\n-10 -7\n20 -5\n-11 19\n-7 3\n-4 18", "output": "3415.618464093" }, { "input": "13 445\n-15 16\n-8 -14\n8 7\n4 15\n8 -13\n15 -11\n-12 -4\n2 -13\n-5 0\n-20 -14\n-8 -7\n-10 -18\n18 -5", "output": "2113.552527680" }, { "input": "18 388\n11 -8\n13 10\n18 -17\n-15 3\n-13 -15\n20 -7\n1 -10\n-13 -12\n-12 -15\n-17 -8\n1 -2\n3 -20\n-8 -9\n15 -13\n-19 -6\n17 3\n-17 2\n6 6", "output": "2999.497312668" }, { "input": "25 258\n-5 -3\n-18 -14\n12 3\n6 11\n4 2\n-19 -3\n19 -7\n-15 19\n-19 -12\n-11 -10\n-5 17\n10 15\n-4 1\n-3 -20\n6 16\n18 -19\n11 -19\n-17 10\n-17 17\n-2 -17\n-3 -9\n18 13\n14 8\n-2 -5\n-11 4", "output": "2797.756635934" }, { "input": "29 848\n11 -10\n-19 1\n18 18\n19 -19\n0 -5\n16 10\n-20 -14\n7 15\n6 8\n-15 -16\n9 3\n16 -20\n-12 12\n18 -1\n-11 14\n18 10\n11 -20\n-20 -16\n-1 11\n13 10\n-6 13\n-7 -10\n-11 -10\n-10 3\n15 -13\n-4 11\n-13 -11\n-11 -17\n11 -5", "output": "12766.080247922" }, { "input": "36 3\n-11 20\n-11 13\n-17 9\n15 9\n-6 9\n-1 11\n12 -11\n16 -10\n-20 7\n-18 6\n-15 -2\n20 -20\n16 4\n-20 -8\n-12 -15\n-13 -6\n-9 -4\n0 -10\n8 -1\n1 4\n5 8\n8 -15\n16 -12\n19 1\n0 -4\n13 -4\n17 -13\n-7 11\n14 9\n-14 -9\n5 -8\n11 -8\n-17 -5\n1 -3\n-16 -17\n2 -3", "output": "36.467924851" }, { "input": "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-15 8\n-1 -11\n19 8\n11 20\n-9 -3\n16 1\n-14 19\n8 -4", "output": "9495.010556306" }, { "input": "50 284\n-17 -13\n7 12\n-13 0\n13 1\n14 6\n14 -9\n-5 -1\n0 -10\n12 -3\n-14 6\n-8 10\n-16 17\n0 -1\n4 -9\n2 6\n1 8\n-8 -14\n3 9\n1 -15\n-4 -19\n-7 -20\n18 10\n3 -11\n10 16\n2 -6\n-9 19\n-3 -1\n20 9\n-12 -5\n-10 -2\n16 -7\n-16 -18\n-2 17\n2 8\n7 -15\n4 1\n6 -17\n19 9\n-10 -20\n5 2\n10 -2\n3 7\n20 0\n8 -14\n-16 -1\n-20 7\n20 -19\n17 18\n-11 -18\n-16 14", "output": "6087.366930474" }, { "input": "57 373\n18 3\n-4 -1\n18 5\n-7 -15\n-6 -10\n-19 1\n20 15\n15 4\n-1 -2\n13 -14\n0 12\n10 3\n-16 -17\n-14 -9\n-11 -10\n17 19\n-2 6\n-12 -15\n10 20\n16 7\n9 -1\n4 13\n8 -2\n-1 -16\n-3 8\n14 11\n-12 3\n-5 -6\n3 4\n5 7\n-9 9\n11 4\n-19 10\n-7 4\n-20 -12\n10 16\n13 11\n13 -11\n7 -1\n17 18\n-19 7\n14 13\n5 -1\n-7 6\n-1 -6\n6 20\n-16 2\n4 17\n16 -11\n-4 -20\n19 -18\n17 16\n-14 -8\n3 2\n-6 -16\n10 -10\n-13 -11", "output": "8929.162822862" }, { "input": "60 662\n15 17\n-2 -19\n-4 -17\n10 0\n15 10\n-8 -14\n14 9\n-15 20\n6 5\n-9 0\n-13 20\n13 -2\n10 9\n7 5\n4 18\n-10 1\n6 -15\n15 -16\n6 13\n4 -6\n2 5\n18 19\n8 3\n-7 14\n-12 -20\n14 19\n-15 0\n-2 -12\n9 18\n14 4\n2 -20\n3 0\n20 9\n-5 11\n-11 1\n2 -19\n-14 -4\n18 6\n16 16\n15 3\n-1 -5\n9 20\n12 -8\n-1 10\n-4 -9\n3 6\n3 -12\n14 -10\n-8 10\n-18 6\n14 -2\n-14 -12\n-10 -7\n10 -6\n14 1\n6 14\n15 19\n4 14\n3 -14\n-9 -13", "output": "16314.207721932" }, { "input": "61 764\n-9 15\n11 -8\n-6 -7\n-13 -19\n16 -16\n-5 -1\n20 -19\n-14 -1\n-11 4\n7 -2\n-3 2\n-14 -17\n15 18\n20 15\n-13 -2\n15 8\n3 13\n19 -10\n2 -6\n15 -3\n-12 11\n4 -16\n-14 20\n0 2\n11 -7\n-6 -11\n16 7\n8 -3\n16 -10\n-3 9\n9 5\n4 -1\n-17 9\n14 -4\n8 6\n-19 12\n10 -17\n-5 7\n7 -3\n5 3\n6 -14\n9 9\n-16 -19\n11 -16\n-17 15\n8 5\n16 -19\n-7 10\n14 -15\n15 19\n-20 -16\n6 -2\n-4 6\n7 -15\n1 -8\n20 -17\n3 7\n10 12\n10 -11\n-19 10\n0 -11", "output": "22153.369189802" } ]
1,550,839,223
2,147,483,647
PyPy 3
OK
TESTS
42
342
512,000
from collections import deque, Counter, OrderedDict from heapq import nsmallest, nlargest from math import ceil,floor,log,log2,sqrt,gcd,factorial,pow def binNumber(n,size=4): return bin(n)[2:].zfill(size) def iar(): return list(map(int,input().split())) def ini(): return int(input()) def isp(): return map(int,input().split()) def sti(): return str(input()) def par(a): print(' '.join(list(map(str,a)))) def tdl(outerListSize,innerListSize,defaultValue = 0): return [[defaultValue]*innerListSize for i in range(outerListSize)] class pair: def __init__(self,f,s): self.fi = f self.se = s def __lt__(self,other): return (self.fi,self.se) < (other.fi,other.se) # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def dist(x1,y1,x2,y2): return sqrt((x2-x1)**2 + (y2-y1)**2) if __name__ == "__main__": n,k = isp() s = 0 p = [] for _ in range(n): x,y = isp() p.append(pair(x,y)) for i in range(1,n): s += dist(p[i].fi,p[i].se,p[i-1].fi,p[i-1].se) s *= k print(s/50)
Title: Wasted Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second. Scrooge signed exactly *k* papers throughout his life and all those signatures look the same. Find the total time Scrooge wasted signing the papers. Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space. All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters. Output Specification: Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. Demo Input: ['2 1\n0 0\n10 0\n', '5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n', '6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n'] Demo Output: ['0.200000000', '6.032163204', '3.000000000'] Note: none
```python from collections import deque, Counter, OrderedDict from heapq import nsmallest, nlargest from math import ceil,floor,log,log2,sqrt,gcd,factorial,pow def binNumber(n,size=4): return bin(n)[2:].zfill(size) def iar(): return list(map(int,input().split())) def ini(): return int(input()) def isp(): return map(int,input().split()) def sti(): return str(input()) def par(a): print(' '.join(list(map(str,a)))) def tdl(outerListSize,innerListSize,defaultValue = 0): return [[defaultValue]*innerListSize for i in range(outerListSize)] class pair: def __init__(self,f,s): self.fi = f self.se = s def __lt__(self,other): return (self.fi,self.se) < (other.fi,other.se) # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def dist(x1,y1,x2,y2): return sqrt((x2-x1)**2 + (y2-y1)**2) if __name__ == "__main__": n,k = isp() s = 0 p = [] for _ in range(n): x,y = isp() p.append(pair(x,y)) for i in range(1,n): s += dist(p[i].fi,p[i].se,p[i-1].fi,p[i-1].se) s *= k print(s/50) ```
3
0
none
none
none
0
[ "none" ]
null
null
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
[ "fixprefixsuffix\n", "abcdabc\n" ]
[ "fix", "Just a legend" ]
none
0
[ { "input": "fixprefixsuffix", "output": "fix" }, { "input": "abcdabc", "output": "Just a legend" }, { "input": "qwertyqwertyqwerty", "output": "qwerty" }, { "input": "papapapap", "output": "papap" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaa" }, { "input": "ghbdtn", "output": "Just a legend" }, { "input": "a", "output": "Just a legend" }, { "input": "aa", "output": "Just a legend" }, { "input": "ab", "output": "Just a legend" }, { "input": "aaa", "output": "a" }, { "input": "aba", "output": "Just a legend" }, { "input": "aab", "output": "Just a legend" }, { "input": "abb", "output": "Just a legend" }, { "input": "abc", "output": "Just a legend" }, { "input": "aaabaabaaaaab", "output": "Just a legend" }, { "input": "aabaaabaaaaab", "output": "aab" }, { "input": "aaabaaaabab", "output": "Just a legend" }, { "input": "abcabcabcabcabc", "output": "abcabcabc" }, { "input": "aaaaabaaaa", "output": "aaaa" }, { "input": "aaaabaaaaaaa", "output": "aaaa" }, { "input": "ghghghgxghghghg", "output": "ghghg" }, { "input": "kincenvizh", "output": "Just a legend" }, { "input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw", "output": "Just a legend" }, { "input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx", "output": "Just a legend" }, { "input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb", "output": "nfbdzgdlbjhrlvfryyjb" }, { "input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp", "output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp" }, { "input": "abcazabca", "output": "a" } ]
1,465,354,301
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
25
2,000
8,192,000
import math from collections import * from heapq import * s=input() l=len(s) if l==1 or l==2: print("Just a legend") else: vv=False for i in range(l-2,0,-1): s1=s[0:i] s2=s[l-i:l] if s1==s2: v=False for j in range(1,l-i): s3=s[j:j+i] if s3==s2: v=True break if v: print(s1) vv=True break if not vv: print("Just a legend")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. Input Specification: You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. Output Specification: Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. Demo Input: ['fixprefixsuffix\n', 'abcdabc\n'] Demo Output: ['fix', 'Just a legend'] Note: none
```python import math from collections import * from heapq import * s=input() l=len(s) if l==1 or l==2: print("Just a legend") else: vv=False for i in range(l-2,0,-1): s1=s[0:i] s2=s[l-i:l] if s1==s2: v=False for j in range(1,l-i): s3=s[j:j+i] if s3==s2: v=True break if v: print(s1) vv=True break if not vv: print("Just a legend") ```
0
653
B
Bear and Compressing
PROGRAMMING
1,300
[ "brute force", "dfs and similar", "dp", "strings" ]
null
null
Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of *q* possible operations. Limak can perform them in any order, any operation may be applied any number of times. The *i*-th operation is described by a string *a**i* of length two and a string *b**i* of length one. No two of *q* possible operations have the same string *a**i*. When Limak has a string *s* he can perform the *i*-th operation on *s* if the first two letters of *s* match a two-letter string *a**i*. Performing the *i*-th operation removes first two letters of *s* and inserts there a string *b**i*. See the notes section for further clarification. You may note that performing an operation decreases the length of a string *s* exactly by 1. Also, for some sets of operations there may be a string that cannot be compressed any further, because the first two letters don't match any *a**i*. Limak wants to start with a string of length *n* and perform *n*<=-<=1 operations to finally get a one-letter string "a". In how many ways can he choose the starting string to be able to get "a"? Remember that Limak can use only letters he knows.
The first line contains two integers *n* and *q* (2<=≤<=*n*<=≤<=6, 1<=≤<=*q*<=≤<=36) — the length of the initial string and the number of available operations. The next *q* lines describe the possible operations. The *i*-th of them contains two strings *a**i* and *b**i* (|*a**i*|<==<=2,<=|*b**i*|<==<=1). It's guaranteed that *a**i*<=≠<=*a**j* for *i*<=≠<=*j* and that all *a**i* and *b**i* consist of only first six lowercase English letters.
Print the number of strings of length *n* that Limak will be able to transform to string "a" by applying only operations given in the input.
[ "3 5\nab a\ncc c\nca a\nee c\nff d\n", "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c\n", "6 2\nbb a\nba a\n" ]
[ "4\n", "1\n", "0\n" ]
In the first sample, we count initial strings of length 3 from which Limak can get a required string "a". There are 4 such strings: "abb", "cab", "cca", "eea". The first one Limak can compress using operation 1 two times (changing "ab" to a single "a"). The first operation would change "abb" to "ab" and the second operation would change "ab" to "a". Other three strings may be compressed as follows: - "cab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "cca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "eea" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" In the second sample, the only correct initial string is "eb" because it can be immediately compressed to "a".
1,000
[ { "input": "3 5\nab a\ncc c\nca a\nee c\nff d", "output": "4" }, { "input": "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c", "output": "1" }, { "input": "6 2\nbb a\nba a", "output": "0" }, { "input": "2 5\nfe b\nbb a\naf b\nfd b\nbf c", "output": "1" }, { "input": "3 4\neb b\nbd a\ncd d\nbb b", "output": "2" }, { "input": "3 36\nab b\nbb a\naf c\nbd b\ncd a\nff c\nce a\nae a\ncb a\nba a\nad d\ndb a\nbf a\nbe a\ncc b\ndc a\nbc a\nca e\naa e\nec b\nac e\ned b\ndf d\nfa b\nea a\nef b\nee a\nda c\ncf a\nfe d\ndd f\nde a\neb f\nfd a\nfc a\nfb a", "output": "86" }, { "input": "4 20\naf a\nad a\nac a\nbe a\nbc a\naa a\nab a\nbb a\neb a\nbd a\nbf a\ndc a\nea a\ncf a\ncd a\ncb a\nee a\nca a\nba a\nce a", "output": "500" }, { "input": "6 4\nca a\nbe f\nad a\ncf a", "output": "3" }, { "input": "2 15\nbc c\nbd a\nab b\nca a\ndf b\naa c\nae b\nac c\ncd a\nba e\nad d\nbb d\ned a\nfa a\nbf b", "output": "5" }, { "input": "2 36\nad a\nae f\nac a\naa a\ncb b\nde e\nbe a\nea d\ncd b\nab a\nbf a\nba d\ncc c\ndc a\naf a\nca e\nda c\nbb c\nee b\nbd a\ned b\ndf b\nfd c\ndb d\nbc a\ncf d\nff d\ndd a\neb c\nce a\nfa c\nfe b\nec c\nef b\nfb a\nfc a", "output": "14" }, { "input": "3 20\nca a\nbf d\nac a\nad b\neb a\naf a\nbe c\nbd a\ncb a\ncd c\nce b\nbc c\nbb a\ndd f\ndc e\ncf e\nfc e\naa d\nba c\nae d", "output": "29" }, { "input": "4 35\nae f\nad d\naa a\neb d\nfb a\nce b\naf c\nfe c\nca a\nab a\nbd d\nbc a\nbe a\nbb f\nba c\ncb a\ncd a\nac c\ncc b\nbf b\ndb a\nfa a\ned b\nea a\nee d\nec a\ncf d\ndd a\nfc a\ndf a\nff a\ndc b\nef d\nde e\nda b", "output": "529" }, { "input": "5 10\nba a\nbb c\nad a\nac c\nbc b\nfa b\nab b\nbe a\nbf a\naa b", "output": "184" }, { "input": "5 20\nbd a\nac a\nad a\ncc a\naf a\nbe a\nbb a\ncb a\nca a\nab a\nbc a\nae a\ndb a\naa a\nbf a\nde a\nba a\ncf a\nda a\ned a", "output": "4320" }, { "input": "5 20\naf f\nae f\naa f\nbd f\nfc f\ndd f\nba f\nac f\nbe f\neb f\nad f\ncb f\nce f\ncf f\nbc f\nca f\nde f\nab f\nbf f\ncc f", "output": "0" }, { "input": "5 36\nac a\ncc c\nae f\nca a\nba a\nbe c\ndc e\nbc a\naa a\nad d\naf b\ncd c\ndf c\nbf b\nfb e\nef a\nbb b\nbd a\nce b\nab b\ndb c\nda b\ncf d\nfd c\nfa a\ncb c\nfe a\nea a\nfc e\ndd d\nde a\neb a\nec a\ned d\nee c\nff a", "output": "2694" }, { "input": "6 1\nbf a", "output": "0" }, { "input": "6 5\naa b\nad d\nba b\ndc d\nac a", "output": "1" }, { "input": "6 15\nad b\ncb b\naf b\nae c\nbc e\nbd a\nac a\nda b\nab c\ncc d\nce f\ndc b\nca a\nba c\nbb a", "output": "744" }, { "input": "6 15\naf a\nae a\nbc a\ncc a\nbe a\nff a\nab a\nbd a\nce a\nad a\ndb a\nee a\nba a\nda a\naa a", "output": "9375" }, { "input": "6 15\nab b\nbd b\nae b\ncd b\nac b\nba b\ndc b\nbc b\nbb b\nbf b\nef b\naa b\ndd b\ncf b\nfc b", "output": "0" }, { "input": "6 24\nab b\ncb b\naf a\nde c\ndb c\nad b\nca c\nbe c\nda e\nbb a\nbf a\nae a\nbc c\nba a\naa a\ncc f\ndc a\nac b\ncf c\ndd b\ndf a\ncd d\nbd d\neb b", "output": "7993" }, { "input": "6 35\ndc c\nba b\nae e\nab a\naa b\nbb a\nbe b\ndb b\naf b\ncd b\nde b\ncf d\nac b\neb a\ndd a\nce b\nad c\ncc a\ncb c\nbc a\nbd b\ndf d\nea e\nfe c\nbf a\nfc a\nef d\nec b\nda c\ned b\nca a\nff a\nee b\nfb b\nfa e", "output": "15434" }, { "input": "6 36\nbf f\nbb d\nff f\nac a\nad c\nbd e\ndd a\naa c\nab a\nba b\naf a\nda c\nce f\nea c\nde a\nca f\ndc f\nec b\ncc a\nae b\nbe b\nbc c\nee e\ncb b\nfb a\ncd d\ndb a\nef a\ncf d\neb c\ndf b\nfd a\ned a\nfe c\nfa b\nfc a", "output": "15314" }, { "input": "6 1\naa a", "output": "1" }, { "input": "6 1\nbb a", "output": "0" }, { "input": "6 1\nba a", "output": "0" }, { "input": "6 1\nab a", "output": "1" }, { "input": "6 36\nac a\naf a\ndb a\nab a\ncb a\nef a\nad a\nbd a\nfe a\nde a\nbe a\nbb a\naa a\nae a\ndf a\nbc a\nbf a\nce a\nba a\nfd a\ndc a\neb a\ncd a\nca a\nee a\ncc a\ncf a\ndd a\nda a\nec a\nfc a\nfa a\nea a\ned a\nff a\nfb a", "output": "46656" }, { "input": "6 36\naf f\nbd f\nba f\nbf f\nac f\nbe f\nbc f\nef f\naa f\neb f\nab f\nae f\nda f\ndc f\ncd f\nea f\ncb f\nad f\nbb f\ncc f\nce f\ndf f\nfa f\ncf f\ned f\nfe f\nfd f\nee f\ndb f\nde f\ndd f\nca f\nfb f\nec f\nff f\nfc f", "output": "0" }, { "input": "6 36\naa a\nab f\nac a\nad b\nae c\naf d\nba f\nbb a\nbc b\nbd c\nbe d\nbf e\nca f\ncb a\ncc b\ncd c\nce d\ncf e\nda f\ndb a\ndc b\ndd c\nde d\ndf e\nea f\neb a\nec b\ned c\nee d\nef e\nfa f\nfb a\nfc b\nfd c\nfe d\nff e", "output": "9331" }, { "input": "5 5\nab a\ncc c\nca a\nee c\nff d", "output": "8" } ]
1,458,381,605
5,105
Python 3
OK
TESTS
32
108
5,324,800
import collections n, q = map(int, input().split()) d = collections.defaultdict(list) cnt, t = [0] * 6, [0] * 6 for i in range(q): s1, s2 = input().split() d[s2].append(s1) cnt[ord(s2) - ord('a')] += 1 for s in d['a']: t[ord(s[0]) - ord('a')] += 1 for i in range(n - 2): p = [0] * 6 for j in range(6): if t[j] == 0: continue for s in d[chr(j + 97)]: p[ord(s[0]) - ord('a')] += t[j] t = p print(sum(t))
Title: Bear and Compressing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of *q* possible operations. Limak can perform them in any order, any operation may be applied any number of times. The *i*-th operation is described by a string *a**i* of length two and a string *b**i* of length one. No two of *q* possible operations have the same string *a**i*. When Limak has a string *s* he can perform the *i*-th operation on *s* if the first two letters of *s* match a two-letter string *a**i*. Performing the *i*-th operation removes first two letters of *s* and inserts there a string *b**i*. See the notes section for further clarification. You may note that performing an operation decreases the length of a string *s* exactly by 1. Also, for some sets of operations there may be a string that cannot be compressed any further, because the first two letters don't match any *a**i*. Limak wants to start with a string of length *n* and perform *n*<=-<=1 operations to finally get a one-letter string "a". In how many ways can he choose the starting string to be able to get "a"? Remember that Limak can use only letters he knows. Input Specification: The first line contains two integers *n* and *q* (2<=≤<=*n*<=≤<=6, 1<=≤<=*q*<=≤<=36) — the length of the initial string and the number of available operations. The next *q* lines describe the possible operations. The *i*-th of them contains two strings *a**i* and *b**i* (|*a**i*|<==<=2,<=|*b**i*|<==<=1). It's guaranteed that *a**i*<=≠<=*a**j* for *i*<=≠<=*j* and that all *a**i* and *b**i* consist of only first six lowercase English letters. Output Specification: Print the number of strings of length *n* that Limak will be able to transform to string "a" by applying only operations given in the input. Demo Input: ['3 5\nab a\ncc c\nca a\nee c\nff d\n', '2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c\n', '6 2\nbb a\nba a\n'] Demo Output: ['4\n', '1\n', '0\n'] Note: In the first sample, we count initial strings of length 3 from which Limak can get a required string "a". There are 4 such strings: "abb", "cab", "cca", "eea". The first one Limak can compress using operation 1 two times (changing "ab" to a single "a"). The first operation would change "abb" to "ab" and the second operation would change "ab" to "a". Other three strings may be compressed as follows: - "cab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ab" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "cca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" - "eea" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ca" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "a" In the second sample, the only correct initial string is "eb" because it can be immediately compressed to "a".
```python import collections n, q = map(int, input().split()) d = collections.defaultdict(list) cnt, t = [0] * 6, [0] * 6 for i in range(q): s1, s2 = input().split() d[s2].append(s1) cnt[ord(s2) - ord('a')] += 1 for s in d['a']: t[ord(s[0]) - ord('a')] += 1 for i in range(n - 2): p = [0] * 6 for j in range(6): if t[j] == 0: continue for s in d[chr(j + 97)]: p[ord(s[0]) - ord('a')] += t[j] t = p print(sum(t)) ```
3
1,009
B
Minimum Ternary String
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: - "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j &lt; i$ holds $a_j = b_j$, and $a_i &lt; b_i$.
The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive).
Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
[ "100210\n", "11222121\n", "20\n" ]
[ "001120\n", "11112222\n", "20\n" ]
none
0
[ { "input": "100210", "output": "001120" }, { "input": "11222121", "output": "11112222" }, { "input": "20", "output": "20" }, { "input": "1002", "output": "0012" }, { "input": "10", "output": "01" }, { "input": "000021", "output": "000012" }, { "input": "021", "output": "012" }, { "input": "2", "output": "2" }, { "input": "201", "output": "120" }, { "input": "2112120", "output": "1112220" }, { "input": "102", "output": "012" }, { "input": "202", "output": "202" }, { "input": "220201", "output": "122020" }, { "input": "12", "output": "12" }, { "input": "100022202", "output": "000122202" }, { "input": "01", "output": "01" }, { "input": "1", "output": "1" } ]
1,532,266,676
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
1,433,600
s = input() s = list(s) l = len(s) while True: asis = s[:] for i in range(l): if s[i] == '1': start = i zero = 0 one = 1 for j in range(l-i-1): if s[i+j+1] == '2': break elif s[i+j+1] == '0': zero += 1 else: one += 1 if zero != 0: for i in range(zero): s[start+i] = '0' for i in range(one): s[start+zero+i] = '1' for i in range(l): if s[i] == '2': start = i zero = 0 one = 0 two = 1 for j in range(l-i-1): if s[i+j+1] == '2': break elif s[i+j+1] == '0': zero += 1 else: one += 1 if one != 0: for i in range(one): s[start+i] = '1' for i in range(two): s[start+one+i] = '2' if zero != 0: for i in range(zero): s[start+one+two+i] = '0' if asis == s: break output = '' for i in s: output += i print(output)
Title: Minimum Ternary String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: - "010210" $\rightarrow$ "100210"; - "010210" $\rightarrow$ "001210"; - "010210" $\rightarrow$ "010120"; - "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j &lt; i$ holds $a_j = b_j$, and $a_i &lt; b_i$. Input Specification: The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). Output Specification: Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). Demo Input: ['100210\n', '11222121\n', '20\n'] Demo Output: ['001120\n', '11112222\n', '20\n'] Note: none
```python s = input() s = list(s) l = len(s) while True: asis = s[:] for i in range(l): if s[i] == '1': start = i zero = 0 one = 1 for j in range(l-i-1): if s[i+j+1] == '2': break elif s[i+j+1] == '0': zero += 1 else: one += 1 if zero != 0: for i in range(zero): s[start+i] = '0' for i in range(one): s[start+zero+i] = '1' for i in range(l): if s[i] == '2': start = i zero = 0 one = 0 two = 1 for j in range(l-i-1): if s[i+j+1] == '2': break elif s[i+j+1] == '0': zero += 1 else: one += 1 if one != 0: for i in range(one): s[start+i] = '1' for i in range(two): s[start+one+i] = '2' if zero != 0: for i in range(zero): s[start+one+two+i] = '0' if asis == s: break output = '' for i in s: output += i print(output) ```
0
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total.
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7", "output": "37 37" }, { "input": "40 10\n1 2 3 4 5 6 7 10 10 10", "output": "223 158" }, { "input": "1 1\n6", "output": "6 6" }, { "input": "1 2\n10 9", "output": "10 9" }, { "input": "2 1\n7", "output": "13 13" }, { "input": "2 2\n7 2", "output": "13 3" }, { "input": "3 2\n4 7", "output": "18 9" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "3 3\n2 1 1", "output": "4 4" }, { "input": "10 10\n3 1 2 2 1 1 2 1 2 3", "output": "20 13" }, { "input": "10 2\n7 3", "output": "34 34" }, { "input": "10 1\n19", "output": "145 145" }, { "input": "100 3\n29 36 35", "output": "1731 1731" }, { "input": "100 5\n3 38 36 35 2", "output": "2019 1941" }, { "input": "510 132\n50 76 77 69 94 30 47 65 14 62 18 121 26 35 49 17 105 93 47 16 78 3 7 74 7 37 30 36 30 83 71 113 7 58 86 10 65 57 34 102 55 44 43 47 106 44 115 75 109 70 47 45 16 57 62 55 20 88 74 40 45 84 41 1 9 53 65 25 67 31 115 2 63 51 123 70 65 65 18 14 75 14 103 26 117 105 36 104 81 37 35 61 44 90 71 70 88 89 26 21 64 77 89 16 87 99 13 79 27 3 46 120 116 11 14 17 32 70 113 94 108 57 29 100 53 48 44 29 70 30 32 62", "output": "50279 5479" }, { "input": "510 123\n5 2 3 2 5 7 2 3 1 3 6 6 3 1 5 3 5 6 2 2 1 5 5 5 2 2 3 1 6 3 5 8 4 6 1 5 4 5 1 6 5 5 3 6 4 1 6 1 3 5 2 7 5 2 4 4 5 6 5 5 4 3 4 6 5 4 4 3 5 8 5 5 6 3 1 7 4 4 3 3 5 3 6 3 3 6 2 5 3 2 4 5 4 5 2 2 4 4 4 7 3 4 6 5 3 6 4 7 1 6 5 7 6 5 7 3 7 4 4 1 6 6 4", "output": "1501 1501" }, { "input": "610 33\n15 44 8 8 17 11 39 39 38 25 17 36 17 25 21 37 10 11 34 30 29 50 29 50 4 20 32 13 41 14 2 11 2", "output": "12204 8871" } ]
1,621,706,522
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
124
0
n,p=map(int,input().split()) A=list(map(int,input().split())) A.sort() D=A[::-1] mn=0 k=n for i in A: if k>=i: mn+=(i)*(i+1)//2 k-=i else: mn+=((k)*((2*i)+(k-1)*(-1)))//2 break mx=0 D.append(0) for a in range(len(D)-1): d=D[a]-D[a+1] if (a+1)*d<=n: mx+=(((d)*((2*D[a])+(d-1)*(-1)))//2)*(a+1) n-=d*(a+1) else: l=(n//(a+1)) mx+=(((l)*(2*D[a]+(l-1)*(-1))//2)*(a+1)) n-=l*(a+1) mx+=(D[a]-l)*(n%(a+1)) print(mx,mn)
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane costs *x* zlotys (units of Polish currency). The only ticket office of the airport already has a queue of *n* passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all *n* passengers buy tickets according to the conditions of this offer? The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to *n*-th person. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th plane before the ticket office starts selling tickets. The numbers in the lines are separated by a space. It is guaranteed that there are at least *n* empty seats in total. Output Specification: Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. Demo Input: ['4 3\n2 1 1\n', '4 3\n2 2 2\n'] Demo Output: ['5 5\n', '7 6\n'] Note: In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
```python n,p=map(int,input().split()) A=list(map(int,input().split())) A.sort() D=A[::-1] mn=0 k=n for i in A: if k>=i: mn+=(i)*(i+1)//2 k-=i else: mn+=((k)*((2*i)+(k-1)*(-1)))//2 break mx=0 D.append(0) for a in range(len(D)-1): d=D[a]-D[a+1] if (a+1)*d<=n: mx+=(((d)*((2*D[a])+(d-1)*(-1)))//2)*(a+1) n-=d*(a+1) else: l=(n//(a+1)) mx+=(((l)*(2*D[a]+(l-1)*(-1))//2)*(a+1)) n-=l*(a+1) mx+=(D[a]-l)*(n%(a+1)) print(mx,mn) ```
0
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task.
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": ".g.g.d.v.q" }, { "input": "pumesz", "output": ".p.m.s.z" }, { "input": "g", "output": ".g" }, { "input": "zjuotps", "output": ".z.j.t.p.s" }, { "input": "jzbwuehe", "output": ".j.z.b.w.h" }, { "input": "tnkgwuugu", "output": ".t.n.k.g.w.g" }, { "input": "kincenvizh", "output": ".k.n.c.n.v.z.h" }, { "input": "xattxjenual", "output": ".x.t.t.x.j.n.l" }, { "input": "ktajqhpqsvhw", "output": ".k.t.j.q.h.p.q.s.v.h.w" }, { "input": "xnhcigytnqcmy", "output": ".x.n.h.c.g.t.n.q.c.m" }, { "input": "jfmtbejyilxcec", "output": ".j.f.m.t.b.j.l.x.c.c" }, { "input": "D", "output": ".d" }, { "input": "ab", "output": ".b" }, { "input": "Ab", "output": ".b" }, { "input": "aB", "output": ".b" }, { "input": "AB", "output": ".b" }, { "input": "ba", "output": ".b" }, { "input": "bA", "output": ".b" }, { "input": "Ba", "output": ".b" }, { "input": "BA", "output": ".b" }, { "input": "aab", "output": ".b" }, { "input": "baa", "output": ".b" }, { "input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM", "output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m" }, { "input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN", "output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n" }, { "input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ", "output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j" }, { "input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea", "output": ".w.z.t.c.v.v.v.v.z.v" }, { "input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl", "output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l" }, { "input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg", "output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g" }, { "input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ", "output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q" }, { "input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg", "output": ".l.t.g.m.g" }, { "input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy", "output": ".k.z.d.x.f" }, { "input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ", "output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q" }, { "input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY", "output": ".m.r.c.g.p" }, { "input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx", "output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x" }, { "input": "YB", "output": ".b" }, { "input": "fly", "output": ".f.l" }, { "input": "YyyYYYyyYxdwdawdDAWDdaddYYYY", "output": ".x.d.w.d.w.d.d.w.d.d.d.d" } ]
1,695,183,151
2,147,483,647
Python 3
OK
TESTS
42
92
0
string = input() string = string.lower() str_ = "" for i in string: if i not in "aouiye": str_ += "." + i print(str_)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task. Input Specification: The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. Output Specification: Print the resulting string. It is guaranteed that this string is not empty. Demo Input: ['tour\n', 'Codeforces\n', 'aBAcAba\n'] Demo Output: ['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n'] Note: none
```python string = input() string = string.lower() str_ = "" for i in string: if i not in "aouiye": str_ += "." + i print(str_) ```
3
963
A
Alternating Sum
PROGRAMMING
1,800
[ "math", "number theory" ]
null
null
You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$. Find out the non-negative remainder of division of $\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}$ by $10^{9} + 9$. Note that the modulo is unusual!
The first line contains four integers $n, a, b$ and $k$ $(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$. The second line contains a sequence of length $k$ consisting of characters '+' and '-'. If the $i$-th character (0-indexed) is '+', then $s_{i} = 1$, otherwise $s_{i} = -1$. Note that only the first $k$ members of the sequence are given, the rest can be obtained using the periodicity property.
Output a single integer — value of given expression modulo $10^{9} + 9$.
[ "2 2 3 3\n+-+\n", "4 1 5 1\n-\n" ]
[ "7\n", "999999228\n" ]
In the first example: $(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$ = $2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$ = 7 In the second example: $(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$.
500
[ { "input": "2 2 3 3\n+-+", "output": "7" }, { "input": "4 1 5 1\n-", "output": "999999228" }, { "input": "1 1 4 2\n-+", "output": "3" }, { "input": "3 1 4 4\n+--+", "output": "45" }, { "input": "5 1 1 6\n++---+", "output": "0" }, { "input": "5 2 2 6\n+--++-", "output": "0" }, { "input": "686653196 115381398 884618610 3\n+-+", "output": "542231211" }, { "input": "608663287 430477711 172252358 8\n-+--+-+-", "output": "594681696" }, { "input": "904132655 827386249 118827660 334\n+++-+++++--+++----+-+-+-+-+--+-+---++--++--++--+-+-+++-+++--+-+-+----+-+-++++-----+--++++------+++-+-+-++-++++++++-+-++-+++--+--++------+--+-+++--++--+---++-++-+-+-++---++-++--+-+-++-+------+-+----+++-+++--+-+-+--+--+--+------+--+---+--+-++--+++---+-+-++--------+-++--++-+-+-+-+-+-+--+-++++-+++--+--++----+--+-++-++--+--+-+-++-+-++++-", "output": "188208979" }, { "input": "234179195 430477711 115381398 12\n++++-+-+-+++", "output": "549793323" }, { "input": "75952547 967294208 907708706 252\n++--++--+++-+-+--++--++++++---+++-++-+-----++++--++-+-++------+-+-+-++-+-+-++++------++---+-++++---+-+-++++--++++++--+-+++-++--+--+---++++---+-+++-+++--+-+--+++++---+--++-++++--++++-+-++-+++-++-----+-+++++----++--+++-+-+++++-+--++-++-+--+-++++--+-+-+-+", "output": "605712499" }, { "input": "74709071 801809249 753674746 18\n++++++-+-+---+-+--", "output": "13414893" }, { "input": "743329 973758 92942 82\n++----+-++++----+--+++---+--++++-+-+---+++++--+--+++++++--++-+++----+--+++++-+--+-", "output": "299311566" }, { "input": "18111 291387 518587 2\n++", "output": "724471355" }, { "input": "996144 218286 837447 1\n-", "output": "549104837" }, { "input": "179358 828426 548710 67\n++++---+--++----+-+-++++----+--+---+------++-+-++++--+----+---+-+--", "output": "759716474" }, { "input": "397521 174985 279760 1\n+", "output": "25679493" }, { "input": "613632 812232 482342 1\n-", "output": "891965141" }, { "input": "936810 183454 647048 1\n+", "output": "523548992" }, { "input": "231531 250371 921383 28\n++-+------+--+--++++--+-+++-", "output": "134450934" }, { "input": "947301 87242 360762 97\n--+++--+++-++--++-++--++--+++---+++--++++--+++++--+-++-++-----+-++-+--++-----+-++-+--++-++-+-----", "output": "405016159" }, { "input": "425583346 814209084 570987274 1\n+", "output": "63271171" }, { "input": "354062556 688076879 786825319 1\n+", "output": "545304776" }, { "input": "206671954 13571766 192250278 1\n+", "output": "717117421" }, { "input": "23047921 621656196 160244047 1\n-", "output": "101533009" }, { "input": "806038018 740585177 987616107 293\n-+++++--++++---++-+--+-+---+-++++--+--+++--++---++++++++--+++++-+-++-+--+----+--+++-+-++-+++-+-+-+----------++-+-+++++++-+-+-+-++---+++-+-+-------+-+-++--++-++-++-++-+---+--++-++--+++--+++-+-+----++--+-+-++-+---+---+-+-+++------+-+++-+---++-+--+++----+++++---++-++--+----+++-+--+++-+------+-++", "output": "441468166" }, { "input": "262060935 184120408 148332034 148\n+--+-------+-+-+--++-+++--++-+-++++++--++-+++-+++--+-------+-+--+++-+-+-+---++-++-+-++---+--+-+-+--+------+++--+--+-+-+---+---+-+-++++---+++--+++---", "output": "700325386" }, { "input": "919350941 654611542 217223605 186\n++-++-+++++-+++--+---+++++++-++-+----+-++--+-++--++--+++-+++---+--+--++-+-+++-+-+++-++---+--+++-+-+++--+-+-------+-++------++---+-+---++-++-++---+-+--+-+--+++++---+--+--++++-++-++--+--++", "output": "116291420" }, { "input": "289455627 906207104 512692624 154\n-------++--+++---++-++------++----------+--+++-+-+++---+---+++--++++++--+-+-+--+---+-+-++-++--+-++--++++---+-+---+-----+--+-+---------+++-++---++-+-+-----", "output": "48198216" }, { "input": "258833760 515657142 791267045 1\n-", "output": "935800888" }, { "input": "691617927 66917103 843055237 8\n--+++---", "output": "147768186" }, { "input": "379582849 362892355 986900829 50\n++-++---+-+++++--++++--+--++--++-----+------++--+-", "output": "927469713" }, { "input": "176799169 363368399 841293419 1\n+", "output": "746494802" }, { "input": "144808247 203038656 166324035 4\n-+-+", "output": "909066471" }, { "input": "477607531 177367565 20080950 2\n++", "output": "928662830" }, { "input": "682074525 289438443 917164266 1\n+", "output": "28048785" }, { "input": "938449224 59852396 219719125 1\n-", "output": "648647459" }, { "input": "395171426 872478622 193568600 147\n+---++---+-+--+++++--+---+-++++-+-++---++++--+--+-+-++-+-++--------++---+++-+---++---+---+-+--+-++++-+++-+-+-++-+--+++-++-+-+-+-++++++-+---+---++--", "output": "460881399" }, { "input": "403493428 317461491 556701240 1\n-", "output": "936516261" }, { "input": "917751169 330191895 532837377 70\n-+-+++++++--++---++-+++++-+++-----+-+++---+--+-+-++-++-+-+-++-++-+----", "output": "908035409" }, { "input": "252089413 552678586 938424519 1\n-", "output": "627032736" }, { "input": "649316142 320010793 200197645 1\n-", "output": "323650777" }, { "input": "116399299 784781190 299072480 5\n++++-", "output": "754650814" } ]
1,525,717,136
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #include<inttypes.h> #include<math.h> #define for(i,a,b) for(int i=a;i<b ; i++) using namespace std; long long int puiss(long long int x,long long int y){long long int res=1;for(i,0,y){res=res*x;}return res;} long long int reste(long long int x,long long int y){long long int q=abs(x/y);return x+(q+1)*y;} int main() { //cout << puiss(5,3) << endl; long long int n,a,b,k; cin >> n >> a >>b >> k; string ch; cin >> ch; long long int s=0; for(i,0,n+1){ if (ch[i%k]=='+'){s=s+puiss(a,n-i)*puiss(b,i);} else{s=s-puiss(a,n-i)*puiss(b,i);} } long long int v; v=puiss(10,9)+9; v=reste(s,v); cout << v << endl; //long long int j=423834578; //cout << j << endl; return 0; }
Title: Alternating Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$. Find out the non-negative remainder of division of $\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}$ by $10^{9} + 9$. Note that the modulo is unusual! Input Specification: The first line contains four integers $n, a, b$ and $k$ $(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$. The second line contains a sequence of length $k$ consisting of characters '+' and '-'. If the $i$-th character (0-indexed) is '+', then $s_{i} = 1$, otherwise $s_{i} = -1$. Note that only the first $k$ members of the sequence are given, the rest can be obtained using the periodicity property. Output Specification: Output a single integer — value of given expression modulo $10^{9} + 9$. Demo Input: ['2 2 3 3\n+-+\n', '4 1 5 1\n-\n'] Demo Output: ['7\n', '999999228\n'] Note: In the first example: $(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$ = $2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$ = 7 In the second example: $(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$.
```python #include <iostream> #include<inttypes.h> #include<math.h> #define for(i,a,b) for(int i=a;i<b ; i++) using namespace std; long long int puiss(long long int x,long long int y){long long int res=1;for(i,0,y){res=res*x;}return res;} long long int reste(long long int x,long long int y){long long int q=abs(x/y);return x+(q+1)*y;} int main() { //cout << puiss(5,3) << endl; long long int n,a,b,k; cin >> n >> a >>b >> k; string ch; cin >> ch; long long int s=0; for(i,0,n+1){ if (ch[i%k]=='+'){s=s+puiss(a,n-i)*puiss(b,i);} else{s=s-puiss(a,n-i)*puiss(b,i);} } long long int v; v=puiss(10,9)+9; v=reste(s,v); cout << v << endl; //long long int j=423834578; //cout << j << endl; return 0; } ```
-1
194
A
Exams
PROGRAMMING
900
[ "implementation", "math" ]
null
null
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*.
The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*.
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*.
[ "4 8\n", "4 10\n", "1 3\n" ]
[ "4\n", "2\n", "0\n" ]
In the first sample the author has to get a 2 for all his exams. In the second sample he should get a 3 for two exams and a 2 for two more. In the third sample he should get a 3 for one exam.
500
[ { "input": "4 8", "output": "4" }, { "input": "4 10", "output": "2" }, { "input": "1 3", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "4 9", "output": "3" }, { "input": "50 234", "output": "0" }, { "input": "50 100", "output": "50" }, { "input": "50 250", "output": "0" }, { "input": "29 116", "output": "0" }, { "input": "20 69", "output": "0" }, { "input": "46 127", "output": "11" }, { "input": "3 7", "output": "2" }, { "input": "36 99", "output": "9" }, { "input": "45 104", "output": "31" }, { "input": "13 57", "output": "0" }, { "input": "25 106", "output": "0" }, { "input": "8 19", "output": "5" }, { "input": "20 69", "output": "0" }, { "input": "13 32", "output": "7" }, { "input": "47 128", "output": "13" }, { "input": "17 73", "output": "0" }, { "input": "3 7", "output": "2" }, { "input": "16 70", "output": "0" }, { "input": "1 5", "output": "0" }, { "input": "38 137", "output": "0" }, { "input": "7 20", "output": "1" }, { "input": "1 5", "output": "0" }, { "input": "36 155", "output": "0" }, { "input": "5 15", "output": "0" }, { "input": "27 75", "output": "6" }, { "input": "21 73", "output": "0" }, { "input": "2 5", "output": "1" }, { "input": "49 177", "output": "0" }, { "input": "7 20", "output": "1" }, { "input": "44 173", "output": "0" }, { "input": "49 219", "output": "0" }, { "input": "16 70", "output": "0" }, { "input": "10 28", "output": "2" } ]
1,618,612,675
2,147,483,647
Python 3
OK
TESTS
38
124
0
n, k = map(int, input().split()) two = k//n rem = k % n if two > 2: print(0) else: print(n-rem)
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. Input Specification: The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. Output Specification: Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. Demo Input: ['4 8\n', '4 10\n', '1 3\n'] Demo Output: ['4\n', '2\n', '0\n'] Note: In the first sample the author has to get a 2 for all his exams. In the second sample he should get a 3 for two exams and a 2 for two more. In the third sample he should get a 3 for one exam.
```python n, k = map(int, input().split()) two = k//n rem = k % n if two > 2: print(0) else: print(n-rem) ```
3
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him.
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt", "output": "NO" }, { "input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos", "output": "YES" }, { "input": "3\naaa\naaa\naaa", "output": "NO" }, { "input": "3\naca\noec\nzba", "output": "NO" }, { "input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo", "output": "NO" }, { "input": "3\nxxx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxx\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxxx", "output": "NO" }, { "input": "3\nxax\nxxa\nxax", "output": "NO" }, { "input": "3\nxax\naaa\nxax", "output": "NO" }, { "input": "3\naax\naxa\nxax", "output": "NO" }, { "input": "3\nxaa\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\naax", "output": "NO" }, { "input": "3\nxax\naxa\nxaa", "output": "NO" }, { "input": "3\nxfx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\nafa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxaf", "output": "NO" }, { "input": "3\nxox\nxxx\nxxx", "output": "NO" }, { "input": "3\naxa\naax\nxxa", "output": "NO" }, { "input": "3\nxox\noxx\nxox", "output": "NO" }, { "input": "3\nxox\nooo\nxox", "output": "NO" }, { "input": "3\naaa\naab\nbbb", "output": "NO" }, { "input": "3\nxxx\nsxs\nxsx", "output": "NO" }, { "input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba", "output": "NO" }, { "input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba", "output": "NO" }, { "input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nxox\noxx\nxxx", "output": "NO" }, { "input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox", "output": "NO" }, { "input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox", "output": "NO" }, { "input": "3\naaa\nbab\naba", "output": "NO" } ]
1,650,916,866
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define yes cout<<"yes\n"; #define Yes cout<<"Yes\n"; #define YES cout<<"YES\n"; #define no cout<<"no\n"; #define No cout<<"No\n"; #define NO cout<<"NO\n"; #define loop(n) for(int i=0;i<n;i++) #define all(x) x.begin(),x.end() typedef long long ll; struct interval { int s,e; }; bool sortthis(interval i1, interval i2) { return i1.s<i2.s; } void solve() { ll n;cin>>n;char arr[n][n]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>arr[i][j]; } } char a=arr[0][0]; char b=arr[0][1]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j) { if(arr[i][j] != a) { NO return; } } else if (i == n-1-j) { if(arr[i][n-1-j] != a) { NO return; } } else if(arr[i][j] != b) { NO return; } } } YES } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif ll t=1; //cin>>t; while(t--) { solve(); } return 0; }
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. Output Specification: Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. Demo Input: ['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: none
```python #include <bits/stdc++.h> using namespace std; #define endl '\n' #define yes cout<<"yes\n"; #define Yes cout<<"Yes\n"; #define YES cout<<"YES\n"; #define no cout<<"no\n"; #define No cout<<"No\n"; #define NO cout<<"NO\n"; #define loop(n) for(int i=0;i<n;i++) #define all(x) x.begin(),x.end() typedef long long ll; struct interval { int s,e; }; bool sortthis(interval i1, interval i2) { return i1.s<i2.s; } void solve() { ll n;cin>>n;char arr[n][n]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>arr[i][j]; } } char a=arr[0][0]; char b=arr[0][1]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j) { if(arr[i][j] != a) { NO return; } } else if (i == n-1-j) { if(arr[i][n-1-j] != a) { NO return; } } else if(arr[i][j] != b) { NO return; } } } YES } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif ll t=1; //cin>>t; while(t--) { solve(); } return 0; } ```
-1
550
A
Two Substrings
PROGRAMMING
1,500
[ "brute force", "dp", "greedy", "implementation", "strings" ]
null
null
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
[ "ABA\n", "BACFAB\n", "AXBYBXA\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
1,000
[ { "input": "ABA", "output": "NO" }, { "input": "BACFAB", "output": "YES" }, { "input": "AXBYBXA", "output": "NO" }, { "input": "ABABAB", "output": "YES" }, { "input": "BBBBBBBBBB", "output": "NO" }, { "input": "ABBA", "output": "YES" }, { "input": "ABAXXXAB", "output": "YES" }, { "input": "TESTABAXXABTEST", "output": "YES" }, { "input": "A", "output": "NO" }, { "input": "B", "output": "NO" }, { "input": "X", "output": "NO" }, { "input": "BA", "output": "NO" }, { "input": "AB", "output": "NO" }, { "input": "AA", "output": "NO" }, { "input": "BB", "output": "NO" }, { "input": "BAB", "output": "NO" }, { "input": "AAB", "output": "NO" }, { "input": "BAA", "output": "NO" }, { "input": "ABB", "output": "NO" }, { "input": "BBA", "output": "NO" }, { "input": "AAA", "output": "NO" }, { "input": "BBB", "output": "NO" }, { "input": "AXBXBXA", "output": "NO" }, { "input": "SKDSKDJABSDBADKFJDK", "output": "YES" }, { "input": "ABAXXBBXXAA", "output": "NO" }, { "input": "ABAB", "output": "NO" }, { "input": "BABA", "output": "NO" }, { "input": "AAAB", "output": "NO" }, { "input": "AAAA", "output": "NO" }, { "input": "AABA", "output": "NO" }, { "input": "ABAA", "output": "NO" }, { "input": "BAAA", "output": "NO" }, { "input": "AABB", "output": "NO" }, { "input": "BAAB", "output": "YES" }, { "input": "BBAA", "output": "NO" }, { "input": "BBBA", "output": "NO" }, { "input": "BBAB", "output": "NO" }, { "input": "BABB", "output": "NO" }, { "input": "ABBB", "output": "NO" }, { "input": "BBBB", "output": "NO" }, { "input": "BABAB", "output": "YES" }, { "input": "ABABA", "output": "YES" }, { "input": "AAABAAACBBBC", "output": "NO" }, { "input": "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC", "output": "YES" }, { "input": "CBBABDDBBADAC", "output": "YES" }, { "input": "ABYFAB", "output": "NO" }, { "input": "BABXXAB", "output": "YES" }, { "input": "ABAXAB", "output": "YES" }, { "input": "ABABXAB", "output": "YES" }, { "input": "ABXABXABXABXABXBAXBAXBAXBA", "output": "YES" }, { "input": "QQQQQQQQQABABQQQQQQQQ", "output": "NO" } ]
1,690,004,464
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
st = input() ab = st.count("AB") ba = st.count("BA") aba = st.count("ABA") print("NO") if ab==0 and ba==0 or aba!=0 else print("YES") # print("NO" if ab==0 and ba == 0 and aba!=0)
Title: Two Substrings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). Input Specification: The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. Output Specification: Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. Demo Input: ['ABA\n', 'BACFAB\n', 'AXBYBXA\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
```python st = input() ab = st.count("AB") ba = st.count("BA") aba = st.count("ABA") print("NO") if ab==0 and ba==0 or aba!=0 else print("YES") # print("NO" if ab==0 and ba == 0 and aba!=0) ```
0
522
A
Reposts
PROGRAMMING
1,200
[ "*special", "dfs and similar", "dp", "graphs", "trees" ]
null
null
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Print a single integer — the maximum length of a repost chain.
[ "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n", "1\nSoMeStRaNgEgUe reposted PoLyCaRp\n" ]
[ "6\n", "2\n", "2\n" ]
none
500
[ { "input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6" }, { "input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp", "output": "2" }, { "input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp", "output": "2" }, { "input": "1\niuNtwVf reposted POlYcarP", "output": "2" }, { "input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS", "output": "11" }, { "input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl", "output": "6" }, { "input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj", "output": "9" }, { "input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI", "output": "3" } ]
1,460,392,537
2,147,483,647
PyPy 3
OK
TESTS
36
124
102,400
__author__ = 'Utena' n=int(input()) reposts=dict() for i in range(n): s=input().split() reposts[s[0].lower()]=s[2].lower() prev=['polycarp'] t=1 while True: next=[] for a in reposts.keys(): if reposts[a] in prev: next.append(a) if next==[]: break else: t+=1 prev=next print(t)
Title: Reposts Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user. Output Specification: Print a single integer — the maximum length of a repost chain. Demo Input: ['5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n', '6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n', '1\nSoMeStRaNgEgUe reposted PoLyCaRp\n'] Demo Output: ['6\n', '2\n', '2\n'] Note: none
```python __author__ = 'Utena' n=int(input()) reposts=dict() for i in range(n): s=input().split() reposts[s[0].lower()]=s[2].lower() prev=['polycarp'] t=1 while True: next=[] for a in reposts.keys(): if reposts[a] in prev: next.append(a) if next==[]: break else: t+=1 prev=next print(t) ```
3
333
A
Secrets
PROGRAMMING
1,600
[ "greedy" ]
null
null
Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen. One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get? The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of *n* marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least *n* marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want.
The single line contains a single integer *n* (1<=≤<=*n*<=≤<=1017). Please, do not use the %lld specifier to read or write 64 bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with.
[ "1\n", "4\n" ]
[ "1\n", "2\n" ]
In the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change. In the second test case, if the buyer had exactly three coins of 3 marks, then, to give Gerald 4 marks, he will have to give two of these coins. The buyer cannot give three coins as he wants to minimize the number of coins that he gives.
500
[ { "input": "1", "output": "1" }, { "input": "4", "output": "2" }, { "input": "3", "output": "1" }, { "input": "8", "output": "3" }, { "input": "10", "output": "4" }, { "input": "100000000000000000", "output": "33333333333333334" }, { "input": "99999999999999999", "output": "3703703703703704" }, { "input": "50031545098999707", "output": "1" }, { "input": "16677181699666569", "output": "1" }, { "input": "72900000000000", "output": "33333333334" }, { "input": "99999999999999997", "output": "33333333333333333" }, { "input": "58061299250691018", "output": "32" }, { "input": "49664023559436051", "output": "128191526" }, { "input": "66708726798666276", "output": "2" }, { "input": "29442431889534807", "output": "48" }, { "input": "70414767176369958", "output": "13" }, { "input": "93886356235159944", "output": "51" }, { "input": "97626528902553453", "output": "551104613133" }, { "input": "52013157885656046", "output": "880847395988" }, { "input": "37586570003500923", "output": "548" }, { "input": "34391854792828422", "output": "582429080812" }, { "input": "205891132094649", "output": "1" }, { "input": "243", "output": "1" }, { "input": "5559060566555523", "output": "1" }, { "input": "81", "output": "1" }, { "input": "108", "output": "2" }, { "input": "2", "output": "1" }, { "input": "1129718145924", "output": "2" } ]
1,621,410,784
2,147,483,647
PyPy 3
OK
TESTS
28
184
0
n=int(input()) while n%3==0: n//=3 print((n-1)//3+1)
Title: Secrets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen. One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get? The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of *n* marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least *n* marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want. Input Specification: The single line contains a single integer *n* (1<=≤<=*n*<=≤<=1017). Please, do not use 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: In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with. Demo Input: ['1\n', '4\n'] Demo Output: ['1\n', '2\n'] Note: In the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change. In the second test case, if the buyer had exactly three coins of 3 marks, then, to give Gerald 4 marks, he will have to give two of these coins. The buyer cannot give three coins as he wants to minimize the number of coins that he gives.
```python n=int(input()) while n%3==0: n//=3 print((n-1)//3+1) ```
3
22
C
System Administrator
PROGRAMMING
1,700
[ "graphs" ]
C. System Administrator
1
256
Bob got a job as a system administrator in X corporation. His first task was to connect *n* servers with the help of *m* two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index *v* fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.
The first input line contains 3 space-separated integer numbers *n*, *m*, *v* (3<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105,<=1<=≤<=*v*<=≤<=*n*), *n* — amount of servers, *m* — amount of direct connections, *v* — index of the server that fails and leads to the failure of the whole system.
If it is impossible to connect the servers in the required way, output -1. Otherwise output *m* lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.
[ "5 6 3\n", "6 100 1\n" ]
[ "1 2\n2 3\n3 4\n4 5\n1 3\n3 5\n", "-1\n" ]
none
0
[ { "input": "5 6 3", "output": "1 3\n2 3\n4 3\n5 3\n1 2\n1 4" }, { "input": "6 100 1", "output": "-1" }, { "input": "10 26 1", "output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n4 5\n4 6\n4 7\n4 8" }, { "input": "20 155 1", "output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n5 12\n5 13\n5 14\n5 15\n5 16\n5 17\n5 18\n5 19\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n6 13\n6 14\n6 15\n6 16..." }, { "input": "30 393 29", "output": "1 29\n2 29\n3 29\n4 29\n5 29\n6 29\n7 29\n8 29\n9 29\n10 29\n11 29\n12 29\n13 29\n14 29\n15 29\n16 29\n17 29\n18 29\n19 29\n20 29\n21 29\n22 29\n23 29\n24 29\n25 29\n26 29\n27 29\n28 29\n30 29\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n3 4\n3 5\n3 6\n..." }, { "input": "50 535 8", "output": "1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n9 8\n10 8\n11 8\n12 8\n13 8\n14 8\n15 8\n16 8\n17 8\n18 8\n19 8\n20 8\n21 8\n22 8\n23 8\n24 8\n25 8\n26 8\n27 8\n28 8\n29 8\n30 8\n31 8\n32 8\n33 8\n34 8\n35 8\n36 8\n37 8\n38 8\n39 8\n40 8\n41 8\n42 8\n43 8\n44 8\n45 8\n46 8\n47 8\n48 8\n49 8\n50 8\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41..." }, { "input": "100 4283 65", "output": "1 65\n2 65\n3 65\n4 65\n5 65\n6 65\n7 65\n8 65\n9 65\n10 65\n11 65\n12 65\n13 65\n14 65\n15 65\n16 65\n17 65\n18 65\n19 65\n20 65\n21 65\n22 65\n23 65\n24 65\n25 65\n26 65\n27 65\n28 65\n29 65\n30 65\n31 65\n32 65\n33 65\n34 65\n35 65\n36 65\n37 65\n38 65\n39 65\n40 65\n41 65\n42 65\n43 65\n44 65\n45 65\n46 65\n47 65\n48 65\n49 65\n50 65\n51 65\n52 65\n53 65\n54 65\n55 65\n56 65\n57 65\n58 65\n59 65\n60 65\n61 65\n62 65\n63 65\n64 65\n66 65\n67 65\n68 65\n69 65\n70 65\n71 65\n72 65\n73 65\n74 65\n75 65\n76..." }, { "input": "1000 51277 488", "output": "1 488\n2 488\n3 488\n4 488\n5 488\n6 488\n7 488\n8 488\n9 488\n10 488\n11 488\n12 488\n13 488\n14 488\n15 488\n16 488\n17 488\n18 488\n19 488\n20 488\n21 488\n22 488\n23 488\n24 488\n25 488\n26 488\n27 488\n28 488\n29 488\n30 488\n31 488\n32 488\n33 488\n34 488\n35 488\n36 488\n37 488\n38 488\n39 488\n40 488\n41 488\n42 488\n43 488\n44 488\n45 488\n46 488\n47 488\n48 488\n49 488\n50 488\n51 488\n52 488\n53 488\n54 488\n55 488\n56 488\n57 488\n58 488\n59 488\n60 488\n61 488\n62 488\n63 488\n64 488\n65 488\n..." }, { "input": "10000 57971 8854", "output": "1 8854\n2 8854\n3 8854\n4 8854\n5 8854\n6 8854\n7 8854\n8 8854\n9 8854\n10 8854\n11 8854\n12 8854\n13 8854\n14 8854\n15 8854\n16 8854\n17 8854\n18 8854\n19 8854\n20 8854\n21 8854\n22 8854\n23 8854\n24 8854\n25 8854\n26 8854\n27 8854\n28 8854\n29 8854\n30 8854\n31 8854\n32 8854\n33 8854\n34 8854\n35 8854\n36 8854\n37 8854\n38 8854\n39 8854\n40 8854\n41 8854\n42 8854\n43 8854\n44 8854\n45 8854\n46 8854\n47 8854\n48 8854\n49 8854\n50 8854\n51 8854\n52 8854\n53 8854\n54 8854\n55 8854\n56 8854\n57 8854\n58 8854..." }, { "input": "100000 99999 41895", "output": "1 41895\n2 41895\n3 41895\n4 41895\n5 41895\n6 41895\n7 41895\n8 41895\n9 41895\n10 41895\n11 41895\n12 41895\n13 41895\n14 41895\n15 41895\n16 41895\n17 41895\n18 41895\n19 41895\n20 41895\n21 41895\n22 41895\n23 41895\n24 41895\n25 41895\n26 41895\n27 41895\n28 41895\n29 41895\n30 41895\n31 41895\n32 41895\n33 41895\n34 41895\n35 41895\n36 41895\n37 41895\n38 41895\n39 41895\n40 41895\n41 41895\n42 41895\n43 41895\n44 41895\n45 41895\n46 41895\n47 41895\n48 41895\n49 41895\n50 41895\n51 41895\n52 41895\n..." }, { "input": "99999 100000 66180", "output": "1 66180\n2 66180\n3 66180\n4 66180\n5 66180\n6 66180\n7 66180\n8 66180\n9 66180\n10 66180\n11 66180\n12 66180\n13 66180\n14 66180\n15 66180\n16 66180\n17 66180\n18 66180\n19 66180\n20 66180\n21 66180\n22 66180\n23 66180\n24 66180\n25 66180\n26 66180\n27 66180\n28 66180\n29 66180\n30 66180\n31 66180\n32 66180\n33 66180\n34 66180\n35 66180\n36 66180\n37 66180\n38 66180\n39 66180\n40 66180\n41 66180\n42 66180\n43 66180\n44 66180\n45 66180\n46 66180\n47 66180\n48 66180\n49 66180\n50 66180\n51 66180\n52 66180\n..." }, { "input": "99997 99997 72727", "output": "1 72727\n2 72727\n3 72727\n4 72727\n5 72727\n6 72727\n7 72727\n8 72727\n9 72727\n10 72727\n11 72727\n12 72727\n13 72727\n14 72727\n15 72727\n16 72727\n17 72727\n18 72727\n19 72727\n20 72727\n21 72727\n22 72727\n23 72727\n24 72727\n25 72727\n26 72727\n27 72727\n28 72727\n29 72727\n30 72727\n31 72727\n32 72727\n33 72727\n34 72727\n35 72727\n36 72727\n37 72727\n38 72727\n39 72727\n40 72727\n41 72727\n42 72727\n43 72727\n44 72727\n45 72727\n46 72727\n47 72727\n48 72727\n49 72727\n50 72727\n51 72727\n52 72727\n..." }, { "input": "100000 100000 100000", "output": "1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000\n7 100000\n8 100000\n9 100000\n10 100000\n11 100000\n12 100000\n13 100000\n14 100000\n15 100000\n16 100000\n17 100000\n18 100000\n19 100000\n20 100000\n21 100000\n22 100000\n23 100000\n24 100000\n25 100000\n26 100000\n27 100000\n28 100000\n29 100000\n30 100000\n31 100000\n32 100000\n33 100000\n34 100000\n35 100000\n36 100000\n37 100000\n38 100000\n39 100000\n40 100000\n41 100000\n42 100000\n43 100000\n44 100000\n45 100000\n46 100000\n47 100000\n48 ..." }, { "input": "100000 100000 1", "output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "100000 99999 100000", "output": "1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000\n7 100000\n8 100000\n9 100000\n10 100000\n11 100000\n12 100000\n13 100000\n14 100000\n15 100000\n16 100000\n17 100000\n18 100000\n19 100000\n20 100000\n21 100000\n22 100000\n23 100000\n24 100000\n25 100000\n26 100000\n27 100000\n28 100000\n29 100000\n30 100000\n31 100000\n32 100000\n33 100000\n34 100000\n35 100000\n36 100000\n37 100000\n38 100000\n39 100000\n40 100000\n41 100000\n42 100000\n43 100000\n44 100000\n45 100000\n46 100000\n47 100000\n48 ..." }, { "input": "100000 99999 1", "output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "100000 99998 100000", "output": "-1" }, { "input": "100000 99998 1", "output": "-1" }, { "input": "100000 0 100000", "output": "-1" }, { "input": "100000 0 1", "output": "-1" }, { "input": "10000 100000 10000", "output": "1 10000\n2 10000\n3 10000\n4 10000\n5 10000\n6 10000\n7 10000\n8 10000\n9 10000\n10 10000\n11 10000\n12 10000\n13 10000\n14 10000\n15 10000\n16 10000\n17 10000\n18 10000\n19 10000\n20 10000\n21 10000\n22 10000\n23 10000\n24 10000\n25 10000\n26 10000\n27 10000\n28 10000\n29 10000\n30 10000\n31 10000\n32 10000\n33 10000\n34 10000\n35 10000\n36 10000\n37 10000\n38 10000\n39 10000\n40 10000\n41 10000\n42 10000\n43 10000\n44 10000\n45 10000\n46 10000\n47 10000\n48 10000\n49 10000\n50 10000\n51 10000\n52 10000\n..." }, { "input": "10000 100000 1", "output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "123 13527 42", "output": "-1" }, { "input": "100 96943 65", "output": "-1" }, { "input": "10 39377 1", "output": "-1" }, { "input": "200 34305 75", "output": "-1" }, { "input": "300 44552 1", "output": "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ..." }, { "input": "300 44552 300", "output": "1 300\n2 300\n3 300\n4 300\n5 300\n6 300\n7 300\n8 300\n9 300\n10 300\n11 300\n12 300\n13 300\n14 300\n15 300\n16 300\n17 300\n18 300\n19 300\n20 300\n21 300\n22 300\n23 300\n24 300\n25 300\n26 300\n27 300\n28 300\n29 300\n30 300\n31 300\n32 300\n33 300\n34 300\n35 300\n36 300\n37 300\n38 300\n39 300\n40 300\n41 300\n42 300\n43 300\n44 300\n45 300\n46 300\n47 300\n48 300\n49 300\n50 300\n51 300\n52 300\n53 300\n54 300\n55 300\n56 300\n57 300\n58 300\n59 300\n60 300\n61 300\n62 300\n63 300\n64 300\n65 300\n..." }, { "input": "300 44553 1", "output": "-1" }, { "input": "300 44553 300", "output": "-1" } ]
1,599,835,561
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
109
0
nodes,connections,focal=[int(x) for x in input().split()] if connections>1+((nodes-1)*(nodes-2))//2: print(-1) else: counter=0 while counter<min(connections,nodes): if counter+1!=focal: print(focal,counter+1) counter+=1 nodes-=1 if connections>counter: for i in range(1,nodes+1): for j in range(i,nodes+1): if connections>counter: if i!=focal and j!=focal and i!=j: print(i,j) counter+=1 else: exit()
Title: System Administrator Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Bob got a job as a system administrator in X corporation. His first task was to connect *n* servers with the help of *m* two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index *v* fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers. Input Specification: The first input line contains 3 space-separated integer numbers *n*, *m*, *v* (3<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105,<=1<=≤<=*v*<=≤<=*n*), *n* — amount of servers, *m* — amount of direct connections, *v* — index of the server that fails and leads to the failure of the whole system. Output Specification: If it is impossible to connect the servers in the required way, output -1. Otherwise output *m* lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any. Demo Input: ['5 6 3\n', '6 100 1\n'] Demo Output: ['1 2\n2 3\n3 4\n4 5\n1 3\n3 5\n', '-1\n'] Note: none
```python nodes,connections,focal=[int(x) for x in input().split()] if connections>1+((nodes-1)*(nodes-2))//2: print(-1) else: counter=0 while counter<min(connections,nodes): if counter+1!=focal: print(focal,counter+1) counter+=1 nodes-=1 if connections>counter: for i in range(1,nodes+1): for j in range(i,nodes+1): if connections>counter: if i!=focal and j!=focal and i!=j: print(i,j) counter+=1 else: exit() ```
0
427
A
Police Recruits
PROGRAMMING
800
[ "implementation" ]
null
null
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated. Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Print a single integer, the number of crimes which will go untreated.
[ "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n" ]
[ "2\n", "1\n", "8\n" ]
Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired. The answer is one, as one crime (on step 5) will go untreated.
500
[ { "input": "3\n-1 -1 1", "output": "2" }, { "input": "8\n1 -1 1 -1 -1 1 1 1", "output": "1" }, { "input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "output": "8" }, { "input": "7\n-1 -1 1 1 -1 -1 1", "output": "2" }, { "input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5", "output": "5" }, { "input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -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": "13" }, { "input": "3\n-1 5 4", "output": "1" }, { "input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1", "output": "5" }, { "input": "1\n2", "output": "0" }, { "input": "1\n-1", "output": "1" }, { "input": "2\n1 -1", "output": "0" }, { "input": "2\n-1 1", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n-1 -1", "output": "2" }, { "input": "4\n10 -1 -1 -1", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "4\n-1 -1 1 1", "output": "2" } ]
1,685,574,558
2,147,483,647
Python 3
OK
TESTS
63
61
9,728,000
import sys import math def main(): #n,k = map(int, input().split()) #a = [int(x) for x in sys.stdin.readline().split()] #t = int(input()) t = int(input()) a = [int(x) for x in sys.stdin.readline().split()] crimes=0 soldiers=0 for x in a: if x >= 1: soldiers += x if x == -1: if soldiers>0: #crimes -= 1 soldiers -=1 else: crimes += 1 print(crimes) main()
Title: Police Recruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated. Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. Input Specification: The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. Output Specification: Print a single integer, the number of crimes which will go untreated. Demo Input: ['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n'] Demo Output: ['2\n', '1\n', '8\n'] Note: Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired. The answer is one, as one crime (on step 5) will go untreated.
```python import sys import math def main(): #n,k = map(int, input().split()) #a = [int(x) for x in sys.stdin.readline().split()] #t = int(input()) t = int(input()) a = [int(x) for x in sys.stdin.readline().split()] crimes=0 soldiers=0 for x in a: if x >= 1: soldiers += x if x == -1: if soldiers>0: #crimes -= 1 soldiers -=1 else: crimes += 1 print(crimes) main() ```
3
180
A
Defragmentation
PROGRAMMING
1,800
[ "implementation" ]
null
null
In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to *n*. The disk has *m* recorded files, the *i*-th file occupies clusters with numbers *a**i*,<=1, *a**i*,<=2, ..., *a**i*,<=*n**i*. These clusters are not necessarily located consecutively on the disk, but the order in which they are given corresponds to their sequence in the file (cluster *a**i*,<=1 contains the first fragment of the *i*-th file, cluster *a**i*,<=2 has the second fragment, etc.). Also the disc must have one or several clusters which are free from files. You are permitted to perform operations of copying the contents of cluster number *i* to cluster number *j* (*i* and *j* must be different). Moreover, if the cluster number *j* used to keep some information, it is lost forever. Clusters are not cleaned, but after the defragmentation is complete, some of them are simply declared unusable (although they may possibly still contain some fragments of files). Your task is to use a sequence of copy operations to ensure that each file occupies a contiguous area of memory. Each file should occupy a consecutive cluster section, the files must follow one after another from the beginning of the hard disk. After defragmentation all free (unused) clusters should be at the end of the hard disk. After defragmenting files can be placed in an arbitrary order. Clusters of each file should go consecutively from first to last. See explanatory examples in the notes. Print the sequence of operations leading to the disk defragmentation. Note that you do not have to minimize the number of operations, but it should not exceed 2*n*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200) — the number of clusters and the number of files, correspondingly. Next *m* lines contain descriptions of the files. The first number in the line is *n**i* (*n**i*<=≥<=1), the number of clusters occupied by the *i*-th file. Then follow *n**i* numbers *a**i*,<=1, *a**i*,<=2, ..., *a**i*,<=*n**i* (1<=≤<=*a**i*,<=*j*<=≤<=*n*). It is guaranteed that each cluster number occurs not more than once and , that is, there exists at least one unused cluster. Numbers on each line are separated by spaces.
In the first line print a single integer *k* (0<=≤<=*k*<=≤<=2*n*) — the number of operations needed to defragment the disk. Next *k* lines should contain the operations' descriptions as "*i* *j*" (copy the contents of the cluster number *i* to the cluster number *j*).
[ "7 2\n2 1 2\n3 3 4 5\n", "7 2\n2 1 3\n3 2 4 5\n" ]
[ "0\n", "3\n2 6\n3 2\n6 3\n" ]
Let's say that a disk consists of 8 clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation. Example 2: each file must occupy a contiguous area of memory. Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one. Example 4: violating the order of file fragments to each other is not allowed. Example 5: unused clusters should be located at the end, and in this example the unused clusters are 3, 7, 8.
0
[ { "input": "7 2\n2 1 2\n3 3 4 5", "output": "0" }, { "input": "7 2\n2 1 3\n3 2 4 5", "output": "3\n2 6\n3 2\n6 3" }, { "input": "2 1\n1 2", "output": "1\n2 1" }, { "input": "3 1\n2 3 1", "output": "2\n1 2\n3 1" }, { "input": "3 2\n1 3\n1 2", "output": "1\n3 1" }, { "input": "5 3\n1 2\n1 4\n1 5", "output": "3\n2 1\n4 2\n5 3" }, { "input": "7 3\n1 7\n2 6 5\n3 4 3 2", "output": "7\n7 1\n2 7\n6 2\n3 6\n5 3\n6 5\n7 6" }, { "input": "7 2\n3 1 3 5\n3 2 4 6", "output": "5\n2 7\n3 2\n5 3\n4 5\n7 4" }, { "input": "10 1\n5 7 4 6 9 2", "output": "7\n7 1\n2 3\n4 2\n3 4\n6 3\n4 5\n9 4" }, { "input": "7 2\n2 2 1\n3 3 4 5", "output": "3\n1 6\n2 1\n6 2" }, { "input": "7 2\n2 1 2\n3 4 5 6", "output": "3\n4 3\n5 4\n6 5" }, { "input": "20 5\n7 12 16 14 17 20 4 15\n2 7 8\n1 5\n5 3 6 18 11 2\n4 9 13 19 1", "output": "36\n1 10\n12 1\n2 12\n16 2\n3 16\n14 3\n4 14\n17 4\n5 17\n20 5\n6 20\n14 6\n7 14\n15 7\n8 15\n14 8\n9 14\n15 9\n10 15\n17 10\n11 17\n16 11\n12 16\n20 12\n13 20\n18 13\n14 18\n17 14\n15 17\n16 15\n18 16\n17 18\n20 17\n18 20\n19 18\n20 19" }, { "input": "20 10\n1 2\n2 14 11\n2 9 15\n2 16 8\n2 3 13\n3 17 12 6\n1 5\n1 7\n2 20 19\n1 1", "output": "25\n1 4\n2 1\n14 2\n3 10\n11 3\n4 11\n9 4\n5 9\n15 5\n6 14\n16 6\n7 15\n8 7\n10 8\n9 10\n13 9\n10 13\n17 10\n11 16\n12 11\n14 12\n15 14\n20 15\n16 17\n19 16" }, { "input": "100 30\n8 62 50 93 34 82 24 87 65\n2 64 86\n3 91 42 88\n2 76 7\n2 35 63\n3 78 84 15\n4 90 46 73 9\n4 74 13 95 58\n3 71 59 55\n2 4 31\n1 19\n1 10\n2 45 23\n2 27 69\n4 12 66 44 22\n1 36\n2 67 2\n2 77 54\n4 96 47 25 52\n5 18 29 43 70 56\n2 14 41\n2 100 6\n3 30 94 75\n2 32 28\n1 53\n9 26 39 51 68 33 99 79 89 49\n4 5 17 81 37\n3 57 8 16\n3 21 72 98\n4 83 48 40 61", "output": "168\n62 1\n2 3\n50 2\n3 11\n93 3\n4 20\n34 4\n5 34\n82 5\n6 38\n24 6\n7 24\n87 7\n8 50\n65 8\n9 60\n64 9\n10 62\n86 10\n11 64\n91 11\n12 65\n42 12\n13 42\n88 13\n14 80\n76 14\n15 76\n24 15\n16 24\n35 16\n17 35\n63 17\n18 63\n78 18\n19 78\n84 19\n20 82\n76 20\n21 76\n90 21\n22 84\n46 22\n23 46\n73 23\n24 73\n60 24\n25 60\n74 25\n26 74\n42 26\n27 42\n95 27\n28 85\n58 28\n29 58\n71 29\n30 71\n59 30\n31 59\n55 31\n32 55\n82 32\n33 82\n59 33\n34 59\n78 34\n35 78\n62 35\n36 62\n45 36\n37 45\n46 37\n38 46\n42 38\n..." }, { "input": "200 10\n17 110 31 67 40 144 57 90 186 25 112 3 14 79 193 159 26 165\n4 91 1 30 62\n11 64 94 60 49 176 172 54 106 68 51 22\n4 131 114 2 15\n33 58 83 164 190 5 21 17 19 181 46 7 140 29 82 147 6 28 192 27 39 196 101 10 53 156 23 98 48 195 88 126 170 55\n2 81 4\n10 177 16 32 78 119 69 171 127 117 133\n14 184 34 145 43 9 134 168 97 63 191 102 50 72 120\n2 45 99\n3 169 163 104", "output": "177\n1 8\n110 1\n2 11\n31 2\n3 12\n67 3\n4 13\n40 4\n5 18\n144 5\n6 20\n57 6\n7 24\n90 7\n8 31\n186 8\n9 33\n25 9\n10 25\n112 10\n11 35\n12 11\n14 12\n13 14\n79 13\n14 36\n193 14\n15 37\n159 15\n16 38\n26 16\n17 26\n165 17\n18 40\n91 18\n19 41\n31 19\n20 31\n30 20\n21 30\n62 21\n22 42\n64 22\n23 44\n94 23\n24 47\n60 24\n25 52\n49 25\n26 49\n176 26\n27 56\n172 27\n28 57\n54 28\n29 54\n106 29\n30 59\n68 30\n31 60\n51 31\n32 51\n42 32\n33 42\n131 33\n34 61\n114 34\n36 62\n37 36\n58 37\n38 58\n83 38\n39 64\n16..." } ]
1,584,480,894
2,147,483,647
Python 3
OK
TESTS
24
248
512,000
import sys n, m, *inp = map(int, sys.stdin.read().split()) inp.reverse() f = [[0 for x in range(201)] for y in range(201)] #2D Array c = [(0,0)]*201 f_size = [0]*201 def putData(f_id, s_id, c_id): global f, c f[f_id][s_id] = c_id c[c_id] = (f_id, s_id) for f_id in range(1, m+1): f_size[f_id] = inp.pop() for s_id in range(1, f_size[f_id]+1): c_id = inp.pop() putData(f_id, s_id, c_id) e_id = c[1:].index((0,0))+1 next_id = 1 op = [] for f_id in range(1, m+1): for s_id in range(1, f_size[f_id]+1): if c[next_id]==(f_id, s_id): next_id += 1 continue if c[next_id] != (0, 0): op.append((next_id, e_id)) putData(c[next_id][0], c[next_id][1], e_id) e_id = f[f_id][s_id] c[e_id] = (0,0) op.append((e_id, next_id)) putData(f_id, s_id, next_id) next_id += 1 print(len(op)) for p in op: print("%d %d" % p)
Title: Defragmentation Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to *n*. The disk has *m* recorded files, the *i*-th file occupies clusters with numbers *a**i*,<=1, *a**i*,<=2, ..., *a**i*,<=*n**i*. These clusters are not necessarily located consecutively on the disk, but the order in which they are given corresponds to their sequence in the file (cluster *a**i*,<=1 contains the first fragment of the *i*-th file, cluster *a**i*,<=2 has the second fragment, etc.). Also the disc must have one or several clusters which are free from files. You are permitted to perform operations of copying the contents of cluster number *i* to cluster number *j* (*i* and *j* must be different). Moreover, if the cluster number *j* used to keep some information, it is lost forever. Clusters are not cleaned, but after the defragmentation is complete, some of them are simply declared unusable (although they may possibly still contain some fragments of files). Your task is to use a sequence of copy operations to ensure that each file occupies a contiguous area of memory. Each file should occupy a consecutive cluster section, the files must follow one after another from the beginning of the hard disk. After defragmentation all free (unused) clusters should be at the end of the hard disk. After defragmenting files can be placed in an arbitrary order. Clusters of each file should go consecutively from first to last. See explanatory examples in the notes. Print the sequence of operations leading to the disk defragmentation. Note that you do not have to minimize the number of operations, but it should not exceed 2*n*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200) — the number of clusters and the number of files, correspondingly. Next *m* lines contain descriptions of the files. The first number in the line is *n**i* (*n**i*<=≥<=1), the number of clusters occupied by the *i*-th file. Then follow *n**i* numbers *a**i*,<=1, *a**i*,<=2, ..., *a**i*,<=*n**i* (1<=≤<=*a**i*,<=*j*<=≤<=*n*). It is guaranteed that each cluster number occurs not more than once and , that is, there exists at least one unused cluster. Numbers on each line are separated by spaces. Output Specification: In the first line print a single integer *k* (0<=≤<=*k*<=≤<=2*n*) — the number of operations needed to defragment the disk. Next *k* lines should contain the operations' descriptions as "*i* *j*" (copy the contents of the cluster number *i* to the cluster number *j*). Demo Input: ['7 2\n2 1 2\n3 3 4 5\n', '7 2\n2 1 3\n3 2 4 5\n'] Demo Output: ['0\n', '3\n2 6\n3 2\n6 3\n'] Note: Let's say that a disk consists of 8 clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation. Example 2: each file must occupy a contiguous area of memory. Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one. Example 4: violating the order of file fragments to each other is not allowed. Example 5: unused clusters should be located at the end, and in this example the unused clusters are 3, 7, 8.
```python import sys n, m, *inp = map(int, sys.stdin.read().split()) inp.reverse() f = [[0 for x in range(201)] for y in range(201)] #2D Array c = [(0,0)]*201 f_size = [0]*201 def putData(f_id, s_id, c_id): global f, c f[f_id][s_id] = c_id c[c_id] = (f_id, s_id) for f_id in range(1, m+1): f_size[f_id] = inp.pop() for s_id in range(1, f_size[f_id]+1): c_id = inp.pop() putData(f_id, s_id, c_id) e_id = c[1:].index((0,0))+1 next_id = 1 op = [] for f_id in range(1, m+1): for s_id in range(1, f_size[f_id]+1): if c[next_id]==(f_id, s_id): next_id += 1 continue if c[next_id] != (0, 0): op.append((next_id, e_id)) putData(c[next_id][0], c[next_id][1], e_id) e_id = f[f_id][s_id] c[e_id] = (0,0) op.append((e_id, next_id)) putData(f_id, s_id, next_id) next_id += 1 print(len(op)) for p in op: print("%d %d" % p) ```
3
952
F
2 + 2 != 4
PROGRAMMING
2,400
[]
null
null
One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution...
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive.
Reproduce the output of the reference solution, including the bug.
[ "8-7+6-5+4-3+2-1-0\n", "2+2\n", "112-37\n" ]
[ "4\n", "-46\n", "375\n" ]
none
0
[ { "input": "8-7+6-5+4-3+2-1-0", "output": "4" }, { "input": "2+2", "output": "-46" }, { "input": "112-37", "output": "375" }, { "input": "255+255+255+255+255+255+255+255+255+255", "output": "-42450" }, { "input": "0-255-255-255-255-255-255-255-255-255", "output": "24705" }, { "input": "0+0+0+0+0+0+0+0+0+0", "output": "-450" }, { "input": "0-0-0-0-0-0-0-0-0-0", "output": "270" }, { "input": "0+100+100+100+100+100+100+100+100+100", "output": "-44100" }, { "input": "255-100-100-100-100-100-100-100-100-100", "output": "26355" }, { "input": "45+5", "output": "0" }, { "input": "23+6-9", "output": "0" }, { "input": "123+234-56-78-90", "output": "-3967" }, { "input": "97+67+12+9+42+45+13", "output": "-2265" }, { "input": "9-109-22+23-87+27-40+10", "output": "2211" }, { "input": "66-165-34+209+76", "output": "-2048" }, { "input": "150+222-3-90-248-187+198", "output": "-3628" }, { "input": "136+90-200+6-102", "output": "5380" }, { "input": "255-12-34-56-69-78-90", "output": "1716" }, { "input": "243-173+90-56+78-53+53-21", "output": "2561" }, { "input": "131+49+249+71-251-61+159-111+51", "output": "-4913" }, { "input": "5-9-1-3+6+4-7+8-2", "output": "1" }, { "input": "101+200+195+231+107+222+146+254+160+209", "output": "-43175" }, { "input": "240-120-234-156-207-189", "output": "14334" }, { "input": "1-2+3-4+5-6", "output": "-13" }, { "input": "9-8+7-6+5-4+3-2+1-0", "output": "-45" } ]
1,666,681,531
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
from random import randint n = input() if n[0] = "8": print(4) elif n[0] == "2": print(-46) elif n[0] == "1": print(375) else: print(randint(-10**6, 10**6))
Title: 2 + 2 != 4 Time Limit: None seconds Memory Limit: None megabytes Problem Description: One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution... Input Specification: The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. Output Specification: Reproduce the output of the reference solution, including the bug. Demo Input: ['8-7+6-5+4-3+2-1-0\n', '2+2\n', '112-37\n'] Demo Output: ['4\n', '-46\n', '375\n'] Note: none
```python from random import randint n = input() if n[0] = "8": print(4) elif n[0] == "2": print(-46) elif n[0] == "1": print(375) else: print(randint(-10**6, 10**6)) ```
-1
25
C
Roads in Berland
PROGRAMMING
1,900
[ "graphs", "shortest paths" ]
C. Roads in Berland
2
256
There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance between them. Berland Government plans to build *k* new roads. For each of the planned road it is known its length, and what cities it will connect. To control the correctness of the construction of new roads, after the opening of another road Berland government wants to check the sum of the shortest distances between all pairs of cities. Help them — for a given matrix of shortest distances on the old roads and plans of all new roads, find out how the sum of the shortest distances between all pairs of cities changes after construction of each road.
The first line contains integer *n* (2<=≤<=*n*<=≤<=300) — amount of cities in Berland. Then there follow *n* lines with *n* integer numbers each — the matrix of shortest distances. *j*-th integer in the *i*-th row — *d**i*,<=*j*, the shortest distance between cities *i* and *j*. It is guaranteed that *d**i*,<=*i*<==<=0,<=*d**i*,<=*j*<==<=*d**j*,<=*i*, and a given matrix is a matrix of shortest distances for some set of two-way roads with integer lengths from 1 to 1000, such that from each city it is possible to get to any other city using these roads. Next line contains integer *k* (1<=≤<=*k*<=≤<=300) — amount of planned roads. Following *k* lines contain the description of the planned roads. Each road is described by three space-separated integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=1000) — *a**i* and *b**i* — pair of cities, which the road connects, *c**i* — the length of the road. It can be several roads between a pair of cities, but no road connects the city with itself.
Output *k* space-separated integers *q**i* (1<=≤<=*i*<=≤<=*k*). *q**i* should be equal to the sum of shortest distances between all pairs of cities after the construction of roads with indexes from 1 to *i*. Roads are numbered from 1 in the input order. Each pair of cities should be taken into account in the sum exactly once, i. e. we count unordered pairs.
[ "2\n0 5\n5 0\n1\n1 2 3\n", "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n" ]
[ "3 ", "17 12 " ]
none
0
[ { "input": "2\n0 5\n5 0\n1\n1 2 3", "output": "3 " }, { "input": "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1", "output": "17 12 " }, { "input": "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763", "output": "1480 1480 1480 " }, { "input": "4\n0 537 1064 656\n537 0 527 119\n1064 527 0 408\n656 119 408 0\n4\n1 4 123\n1 4 344\n3 2 982\n3 2 587", "output": "1950 1950 1950 1950 " }, { "input": "5\n0 954 1255 266 751\n954 0 1677 688 1173\n1255 1677 0 989 504\n266 688 989 0 485\n751 1173 504 485 0\n5\n5 2 837\n3 4 692\n3 5 756\n3 1 151\n2 5 262", "output": "8070 7476 7476 6062 5111 " } ]
1,697,096,338
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
12,185,600
from collections import defaultdict def dijkstra(graph, start, end): import heapq heap = [(0, start)] # cost from start node,end node visited = set() while heap: (cost, u) = heapq.heappop(heap) if u in visited: continue visited.add(u) if u == end: return cost for v, c in graph[u]: if v in visited: continue next_item = cost + c heapq.heappush(heap, (next_item, v)) return -1 def main(): n = int(input()) graph = defaultdict(list) for i in range(n): row = list(map(int, input().split())) for j in range(n): graph[i].append((j, row[j])) graph[j].append((i, row[j])) ans = [] k = int(input()) for _ in range(k): a,b,c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) tot = 0 for u in range(n): for v in range(u): cur = dijkstra(graph, u, v) tot += cur ans.append(tot) print(*ans) main()
Title: Roads in Berland Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance between them. Berland Government plans to build *k* new roads. For each of the planned road it is known its length, and what cities it will connect. To control the correctness of the construction of new roads, after the opening of another road Berland government wants to check the sum of the shortest distances between all pairs of cities. Help them — for a given matrix of shortest distances on the old roads and plans of all new roads, find out how the sum of the shortest distances between all pairs of cities changes after construction of each road. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=300) — amount of cities in Berland. Then there follow *n* lines with *n* integer numbers each — the matrix of shortest distances. *j*-th integer in the *i*-th row — *d**i*,<=*j*, the shortest distance between cities *i* and *j*. It is guaranteed that *d**i*,<=*i*<==<=0,<=*d**i*,<=*j*<==<=*d**j*,<=*i*, and a given matrix is a matrix of shortest distances for some set of two-way roads with integer lengths from 1 to 1000, such that from each city it is possible to get to any other city using these roads. Next line contains integer *k* (1<=≤<=*k*<=≤<=300) — amount of planned roads. Following *k* lines contain the description of the planned roads. Each road is described by three space-separated integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=1000) — *a**i* and *b**i* — pair of cities, which the road connects, *c**i* — the length of the road. It can be several roads between a pair of cities, but no road connects the city with itself. Output Specification: Output *k* space-separated integers *q**i* (1<=≤<=*i*<=≤<=*k*). *q**i* should be equal to the sum of shortest distances between all pairs of cities after the construction of roads with indexes from 1 to *i*. Roads are numbered from 1 in the input order. Each pair of cities should be taken into account in the sum exactly once, i. e. we count unordered pairs. Demo Input: ['2\n0 5\n5 0\n1\n1 2 3\n', '3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n'] Demo Output: ['3 ', '17 12 '] Note: none
```python from collections import defaultdict def dijkstra(graph, start, end): import heapq heap = [(0, start)] # cost from start node,end node visited = set() while heap: (cost, u) = heapq.heappop(heap) if u in visited: continue visited.add(u) if u == end: return cost for v, c in graph[u]: if v in visited: continue next_item = cost + c heapq.heappush(heap, (next_item, v)) return -1 def main(): n = int(input()) graph = defaultdict(list) for i in range(n): row = list(map(int, input().split())) for j in range(n): graph[i].append((j, row[j])) graph[j].append((i, row[j])) ans = [] k = int(input()) for _ in range(k): a,b,c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) tot = 0 for u in range(n): for v in range(u): cur = dijkstra(graph, u, v) tot += cur ans.append(tot) print(*ans) main() ```
0
715
D
Create a Maze
PROGRAMMING
3,100
[ "constructive algorithms" ]
null
null
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of *n*<=×<=*m* rooms, and the rooms are arranged in *n* rows (numbered from the top to the bottom starting from 1) and *m* columns (numbered from the left to the right starting from 1). The room in the *i*-th row and *j*-th column is denoted by (*i*,<=*j*). A player starts in the room (1,<=1) and wants to reach the room (*n*,<=*m*). Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (*i*,<=*j*) and (*i*,<=*j*<=+<=1) is locked, then we can't go from (*i*,<=*j*) to (*i*,<=*j*<=+<=1). Also, one can only travel between the rooms downwards (from the room (*i*,<=*j*) to the room (*i*<=+<=1,<=*j*)) or rightwards (from the room (*i*,<=*j*) to the room (*i*,<=*j*<=+<=1)) provided the corresponding door is not locked. ZS the Coder considers a maze to have difficulty *x* if there is exactly *x* ways of travelling from the room (1,<=1) to the room (*n*,<=*m*). Two ways are considered different if they differ by the sequence of rooms visited while travelling. Your task is to create a maze such that its difficulty is exactly equal to *T*. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
The first and only line of the input contains a single integer *T* (1<=≤<=*T*<=≤<=1018), the difficulty of the required maze.
The first line should contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and columns of the maze respectively. The next line should contain a single integer *k* (0<=≤<=*k*<=≤<=300) — the number of locked doors in the maze. Then, *k* lines describing locked doors should follow. Each of them should contain four integers, *x*1,<=*y*1,<=*x*2,<=*y*2. This means that the door connecting room (*x*1,<=*y*1) and room (*x*2,<=*y*2) is locked. Note that room (*x*2,<=*y*2) should be adjacent either to the right or to the bottom of (*x*1,<=*y*1), i.e. *x*2<=+<=*y*2 should be equal to *x*1<=+<=*y*1<=+<=1. There should not be a locked door that appears twice in the list. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
[ "3\n", "4\n" ]
[ "3 2\n0\n", "4 3\n3\n1 2 2 2\n3 2 3 3\n1 3 2 3" ]
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door. In the first sample case: In the second sample case:
2,500
[ { "input": "3", "output": "4 4\n5\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n4 1 4 2" }, { "input": "4", "output": "4 4\n4\n1 2 2 2\n1 3 2 3\n2 1 2 2\n4 1 4 2" }, { "input": "576460752303423488", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 1..." }, { "input": "576460752303423487", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 1..." }, { "input": "99999988898898889", "output": "46 46\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n..." }, { "input": "989466010702279111", "output": "50 50\n251\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 1..." }, { "input": "1000000000000000000", "output": "50 50\n240\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 ..." }, { "input": "1", "output": "4 4\n5\n1 2 2 2\n1 3 2 3\n2 1 2 2\n3 1 3 2\n4 1 4 2" }, { "input": "2", "output": "4 4\n4\n1 2 2 2\n1 3 2 3\n2 1 2 2\n3 1 3 2" }, { "input": "201620162016201600", "output": "48 48\n241\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..." }, { "input": "138944482508455329", "output": "48 48\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11..." }, { "input": "327543848458922240", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12..." }, { "input": "516143210114421854", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13..." }, { "input": "481370539210112956", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 ..." }, { "input": "639733286738742273", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 13 10\n12 11..." }, { "input": "604960615834433375", "output": "48 48\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n1..." }, { "input": "793559981784900286", "output": "50 50\n252\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n..." }, { "input": "982159343440399900", "output": "50 50\n240\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..." }, { "input": "170758705095899514", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..." }, { "input": "513930638418673772", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 ..." }, { "input": "702530000074173386", "output": "48 48\n242\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..." }, { "input": "891129366024640296", "output": "50 50\n247\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12..." }, { "input": "79728727680139911", "output": "46 46\n224\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9..." }, { "input": "268328089335639525", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 ..." }, { "input": "297819469440675531", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n1..." }, { "input": "486418831096175146", "output": "48 48\n237\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 ..." }, { "input": "675018197046642056", "output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 1..." }, { "input": "863617562997108966", "output": "50 50\n252\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 1..." }, { "input": "632172093115904261", "output": "48 48\n227\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 13 10\n12..." }, { "input": "395388853680415542", "output": "48 48\n237\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n1..." }, { "input": "583988219630882453", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13..." }, { "input": "772587581286382067", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 ..." }, { "input": "737814910382073169", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13..." }, { "input": "926414272037572783", "output": "50 50\n251\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 ..." }, { "input": "179277684702417302", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 ..." }, { "input": "367877050652884212", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 ..." }, { "input": "333104375453608019", "output": "48 48\n230\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 ..." }, { "input": "325030946722146418", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12..." }, { "input": "513630312672613328", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14..." }, { "input": "53475036382348801", "output": "46 46\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 ..." }, { "input": "242074398037848415", "output": "48 48\n227\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n1..." }, { "input": "430673763988315325", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n..." }, { "input": "619273125643814940", "output": "48 48\n238\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 ..." }, { "input": "807872491594281850", "output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12..." }, { "input": "837363867404350560", "output": "50 50\n254\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 ..." }, { "input": "25963229059850175", "output": "46 46\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 1..." }, { "input": "281442720373954210", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 ..." }, { "input": "983117125129112380", "output": "50 50\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10..." }, { "input": "171716491079579290", "output": "48 48\n227\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 1..." }, { "input": "934933251644090571", "output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..." }, { "input": "123532617594557481", "output": "46 46\n221\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 1..." }, { "input": "312131979250057096", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10..." }, { "input": "500731345200524006", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 11 ..." }, { "input": "465958670001247812", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12..." }, { "input": "718822086961059627", "output": "48 48\n226\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 ..." }, { "input": "487376621374822218", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12..." }, { "input": "675975978735354536", "output": "48 48\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 1..." }, { "input": "864575344685821446", "output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 1..." }, { "input": "53174706341321061", "output": "46 46\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..." }, { "input": "880549474766385254", "output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..." }, { "input": "69148836421884868", "output": "46 46\n219\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n..." }, { "input": "257748198077384482", "output": "48 48\n230\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14..." }, { "input": "446347564027851393", "output": "48 48\n241\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..." }, { "input": "634946925683351007", "output": "48 48\n227\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n1..." }, { "input": "467765511106458502", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n1..." }, { "input": "656364872761958116", "output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n..." }, { "input": "621592201857649219", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 ..." }, { "input": "810191567808116129", "output": "50 50\n247\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 1..." }, { "input": "998790929463615743", "output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 ..." }, { "input": "762007690028127024", "output": "48 48\n241\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 9 12 10\n12 ..." }, { "input": "950607055978593934", "output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 1..." }, { "input": "139206417634093549", "output": "48 48\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 1..." }, { "input": "104433742434817355", "output": "46 46\n220\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10..." }, { "input": "96360313703355754", "output": "46 46\n215\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 1..." }, { "input": "125851689513424465", "output": "46 46\n224\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12..." }, { "input": "314451055463891375", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 ..." }, { "input": "503050417119390989", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 1..." }, { "input": "691649783069857899", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13..." }, { "input": "880249149020324810", "output": "50 50\n255\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..." }, { "input": "420093872730060283", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 ..." }, { "input": "608693234385559897", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 ..." }, { "input": "797292600336026807", "output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n..." }, { "input": "789219171604565206", "output": "48 48\n229\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 11 13 11\n12 14..." }, { "input": "754446496405289013", "output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 ..." }, { "input": "7309909070133531", "output": "44 44\n210\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14 12 1..." }, { "input": "195909270725633145", "output": "48 48\n240\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8..." }, { "input": "384508636676100056", "output": "48 48\n237\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 1..." }, { "input": "349735961476823862", "output": "48 48\n236\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10..." }, { "input": "538335327427290772", "output": "48 48\n231\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13..." }, { "input": "301552087991802053", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 ..." }, { "input": "490151453942268963", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..." }, { "input": "258705984061064258", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10..." }, { "input": "447305350011531169", "output": "48 48\n230\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9..." }, { "input": "635904715961998079", "output": "48 48\n221\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 11 13 11\n..." }, { "input": "665396091772066789", "output": "48 48\n236\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 ..." }, { "input": "853995453427566404", "output": "50 50\n240\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n1..." }, { "input": "42594815083066018", "output": "46 46\n216\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 ..." }, { "input": "231194181033532928", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n1..." }, { "input": "419793542689032543", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8..." }, { "input": "183010307548511120", "output": "48 48\n230\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..." }, { "input": "977109881915691245", "output": "50 50\n252\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..." }, { "input": "165709243571190859", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 1..." }, { "input": "354308605226690473", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 ..." }, { "input": "542907971177157383", "output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n..." }, { "input": "572399346987226094", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..." }, { "input": "760998712937693004", "output": "48 48\n238\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10..." }, { "input": "949598074593192619", "output": "50 50\n249\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8..." }, { "input": "138197440543659529", "output": "48 48\n237\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8..." }, { "input": "326796802199159143", "output": "48 48\n224\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 ..." }, { "input": "446665360611696202", "output": "48 48\n239\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13..." }, { "input": "635264726562163113", "output": "48 48\n230\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 9 12 10\n1..." }, { "input": "823864088217662727", "output": "50 50\n250\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 1..." }, { "input": "789091417313353829", "output": "48 48\n221\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14 12 15\n12 16 13 16\n12 1..." }, { "input": "977690778968853444", "output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..." }, { "input": "230554191633697962", "output": "48 48\n237\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 ..." }, { "input": "419153557584164872", "output": "48 48\n237\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..." }, { "input": "384380882384888679", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 1..." }, { "input": "572980248335355589", "output": "48 48\n236\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..." }, { "input": "761579609990855203", "output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 1..." }, { "input": "104751543313629461", "output": "46 46\n213\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 ..." }, { "input": "293350904969129075", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..." }, { "input": "481950270919595985", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 1..." }, { "input": "670549632575095600", "output": "48 48\n241\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 14\n..." }, { "input": "859148998525562510", "output": "50 50\n248\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 1..." }, { "input": "888640378630598516", "output": "50 50\n252\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 1..." }, { "input": "77239735991130835", "output": "46 46\n226\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13..." }, { "input": "265839101941597745", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13..." }, { "input": "454438463597097359", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9..." }, { "input": "222992998010859950", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n..." }, { "input": "986209758575371231", "output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 1..." }, { "input": "174809124525838142", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 1..." }, { "input": "363408486181337756", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 1..." }, { "input": "552007852131804666", "output": "48 48\n232\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n..." }, { "input": "517235176932528472", "output": "48 48\n226\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 1..." }, { "input": "770098593892340287", "output": "48 48\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 ..." }, { "input": "958697959842807197", "output": "50 50\n245\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n1..." }, { "input": "147297317203339516", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8..." }, { "input": "915851851617102107", "output": "50 50\n239\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..." }, { "input": "104451213272601721", "output": "46 46\n224\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 1..." }, { "input": "867667978132080298", "output": "50 50\n243\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 1..." }, { "input": "832895302932804104", "output": "50 50\n245\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9..." }, { "input": "21494668883271014", "output": "44 44\n214\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n1..." }, { "input": "210094030538770629", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9..." }, { "input": "398693396489237539", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10..." }, { "input": "428184772299306249", "output": "48 48\n236\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 ..." }, { "input": "616784138249773160", "output": "48 48\n234\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 1..." }, { "input": "608710709518311559", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n11 14 12 14\n12 8 12 9\n12 10 13 ..." }, { "input": "797310071173811173", "output": "50 50\n244\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n..." }, { "input": "762537395974534979", "output": "48 48\n235\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12..." }, { "input": "525754160834013556", "output": "48 48\n227\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 11 13 11\n..." }, { "input": "789730223053602816", "output": "50 50\n279\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n..." }, { "input": "789730223053602815", "output": "48 48\n199\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 13 11\n12 14 12 15\n12 16 13 16\n12 17 13 17\n13..." }, { "input": "947676267664323379", "output": "50 50\n256\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13..." }, { "input": "315892089221441126", "output": "48 48\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 10 13 10\n12 11 ..." }, { "input": "473838133832161689", "output": "48 48\n245\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 ..." }, { "input": "631784178442882252", "output": "48 48\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12 1..." }, { "input": "999999999999999999", "output": "50 50\n241\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n5 8 6 8\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 ..." }, { "input": "12345678987654321", "output": "44 44\n219\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n..." }, { "input": "100055128505716009", "output": "46 46\n222\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 1..." }, { "input": "981168724994134051", "output": "50 50\n243\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n11 14 12 1..." }, { "input": "213025900602118694", "output": "48 48\n233\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 7 9 8\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n1..." }, { "input": "163428781826190151", "output": "48 48\n243\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 5 7 6\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 9 11 10\n11 12 11 13\n11 13 12 13\n12 8 12 9\n..." }, { "input": "149046408559208370", "output": "48 48\n238\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 1 3 2\n3 4 3 5\n3 5 4 5\n3 6 4 6\n4 1 4 2\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 3 6 4\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n9 12 10 12\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n1..." }, { "input": "718882536615471983", "output": "48 48\n228\n1 2 2 2\n1 3 2 3\n2 1 2 2\n2 4 2 5\n2 6 3 6\n2 7 3 7\n3 4 3 5\n3 5 4 5\n4 2 5 2\n4 3 5 3\n4 6 4 7\n4 8 5 8\n4 9 5 9\n5 3 5 4\n5 6 5 7\n5 7 6 7\n6 2 6 3\n6 4 7 4\n6 5 7 5\n6 8 6 9\n6 10 7 10\n6 11 7 11\n7 2 7 3\n7 8 7 9\n7 9 8 9\n7 10 8 10\n8 4 8 5\n8 5 8 6\n8 6 9 6\n8 7 9 7\n8 10 8 11\n8 12 9 12\n8 13 9 13\n9 4 9 5\n9 10 9 11\n9 11 10 11\n10 6 10 7\n10 7 10 8\n10 8 11 8\n10 9 11 9\n10 12 10 13\n10 14 11 14\n10 15 11 15\n11 6 11 7\n11 12 11 13\n11 13 12 13\n12 8 12 9\n12 9 12 10\n12 10 13 10\n12..." } ]
1,653,312,338
2,147,483,647
PyPy 3
OK
TESTS
164
93
2,457,600
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m T = int(input()) a = [] while T: a.append(T % 6) T //= 6 L = len(a) n = m = L * 2 + 2 ans = [(1, 2, 2, 2), (2, 1, 2, 2)] f = [[1] * 9 for i in range(7)] f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0 f[4][5] = f[4][6] = f[5][2] = f[5][5] = f[5][6] = 0 p = [0] * 9 p[1] = 3, 1, 3, 2 p[2] = 4, 1, 4, 2 p[3] = 4, 2, 5, 2 p[4] = 4, 3, 5, 3 p[5] = 1, 3, 2, 3 p[6] = 1, 4, 2, 4 p[7] = 2, 4, 2, 5 p[8] = 3, 4, 3, 5 for i in range(L): bit = a[L - i - 1] for j in range(1, 9): if not f[bit][j]: continue x1, y1, x2, y2 = p[j]; D = 2 * i x1 += D; y1 += D; x2 += D; y2 += D if corr(x2, y2): ans.append((x1, y1, x2, y2)) for i in range(L - 1): x1, y1 = 5 + i * 2, 1 + i * 2 x2, y2 = 1 + i * 2, 5 + i * 2 ans.append((x1, y1, x1 + 1, y1)) ans.append((x1, y1 + 1, x1 + 1, y1 + 1)) ans.append((x2, y2, x2, y2 + 1)) ans.append((x2 + 1, y2, x2 + 1, y2 + 1)) print(n, m) print(len(ans)) [print(*i) for i in ans]
Title: Create a Maze Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of *n*<=×<=*m* rooms, and the rooms are arranged in *n* rows (numbered from the top to the bottom starting from 1) and *m* columns (numbered from the left to the right starting from 1). The room in the *i*-th row and *j*-th column is denoted by (*i*,<=*j*). A player starts in the room (1,<=1) and wants to reach the room (*n*,<=*m*). Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (*i*,<=*j*) and (*i*,<=*j*<=+<=1) is locked, then we can't go from (*i*,<=*j*) to (*i*,<=*j*<=+<=1). Also, one can only travel between the rooms downwards (from the room (*i*,<=*j*) to the room (*i*<=+<=1,<=*j*)) or rightwards (from the room (*i*,<=*j*) to the room (*i*,<=*j*<=+<=1)) provided the corresponding door is not locked. ZS the Coder considers a maze to have difficulty *x* if there is exactly *x* ways of travelling from the room (1,<=1) to the room (*n*,<=*m*). Two ways are considered different if they differ by the sequence of rooms visited while travelling. Your task is to create a maze such that its difficulty is exactly equal to *T*. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right? Input Specification: The first and only line of the input contains a single integer *T* (1<=≤<=*T*<=≤<=1018), the difficulty of the required maze. Output Specification: The first line should contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and columns of the maze respectively. The next line should contain a single integer *k* (0<=≤<=*k*<=≤<=300) — the number of locked doors in the maze. Then, *k* lines describing locked doors should follow. Each of them should contain four integers, *x*1,<=*y*1,<=*x*2,<=*y*2. This means that the door connecting room (*x*1,<=*y*1) and room (*x*2,<=*y*2) is locked. Note that room (*x*2,<=*y*2) should be adjacent either to the right or to the bottom of (*x*1,<=*y*1), i.e. *x*2<=+<=*y*2 should be equal to *x*1<=+<=*y*1<=+<=1. There should not be a locked door that appears twice in the list. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them. Demo Input: ['3\n', '4\n'] Demo Output: ['3 2\n0\n', '4 3\n3\n1 2 2 2\n3 2 3 3\n1 3 2 3'] Note: Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door. In the first sample case: In the second sample case:
```python corr = lambda x, y: 1 <= x <= n and 1 <= y <= m T = int(input()) a = [] while T: a.append(T % 6) T //= 6 L = len(a) n = m = L * 2 + 2 ans = [(1, 2, 2, 2), (2, 1, 2, 2)] f = [[1] * 9 for i in range(7)] f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0 f[4][5] = f[4][6] = f[5][2] = f[5][5] = f[5][6] = 0 p = [0] * 9 p[1] = 3, 1, 3, 2 p[2] = 4, 1, 4, 2 p[3] = 4, 2, 5, 2 p[4] = 4, 3, 5, 3 p[5] = 1, 3, 2, 3 p[6] = 1, 4, 2, 4 p[7] = 2, 4, 2, 5 p[8] = 3, 4, 3, 5 for i in range(L): bit = a[L - i - 1] for j in range(1, 9): if not f[bit][j]: continue x1, y1, x2, y2 = p[j]; D = 2 * i x1 += D; y1 += D; x2 += D; y2 += D if corr(x2, y2): ans.append((x1, y1, x2, y2)) for i in range(L - 1): x1, y1 = 5 + i * 2, 1 + i * 2 x2, y2 = 1 + i * 2, 5 + i * 2 ans.append((x1, y1, x1 + 1, y1)) ans.append((x1, y1 + 1, x1 + 1, y1 + 1)) ans.append((x2, y2, x2, y2 + 1)) ans.append((x2 + 1, y2, x2 + 1, y2 + 1)) print(n, m) print(len(ans)) [print(*i) for i in ans] ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,601,870,017
2,147,483,647
Python 3
OK
TESTS
40
109
0
li = ['h','e','l','l','o'] str = input() i=0 for j in range(0,len(str)): if(str[j] == li[i]): i=i+1 if(i==len(li)): break; if(i>=5): print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python li = ['h','e','l','l','o'] str = input() i=0 for j in range(0,len(str)): if(str[j] == li[i]): i=i+1 if(i==len(li)): break; if(i>=5): print('YES') else: print('NO') ```
3.9455
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 7", "output": "5" }, { "input": "14 5 5", "output": "6" }, { "input": "16 6 9", "output": "10" }, { "input": "20 13 17", "output": "7" }, { "input": "22 4 8", "output": "9" }, { "input": "23 8 14", "output": "15" }, { "input": "26 18 22", "output": "8" }, { "input": "28 6 1", "output": "2" }, { "input": "29 5 23", "output": "24" }, { "input": "32 27 15", "output": "5" }, { "input": "33 11 5", "output": "6" }, { "input": "37 21 15", "output": "16" }, { "input": "39 34 33", "output": "5" }, { "input": "41 27 11", "output": "12" }, { "input": "42 25 16", "output": "17" }, { "input": "45 7 43", "output": "38" }, { "input": "47 16 17", "output": "18" }, { "input": "49 11 37", "output": "38" }, { "input": "51 38 39", "output": "13" }, { "input": "52 29 7", "output": "8" }, { "input": "56 43 12", "output": "13" }, { "input": "58 57 28", "output": "1" }, { "input": "59 12 39", "output": "40" }, { "input": "62 9 52", "output": "53" }, { "input": "63 29 44", "output": "34" }, { "input": "65 30 22", "output": "23" }, { "input": "66 27 38", "output": "39" }, { "input": "71 33 53", "output": "38" }, { "input": "73 14 12", "output": "13" }, { "input": "73 37 35", "output": "36" }, { "input": "76 69 44", "output": "7" }, { "input": "79 25 20", "output": "21" }, { "input": "81 60 20", "output": "21" }, { "input": "81 79 14", "output": "2" }, { "input": "84 0 42", "output": "43" }, { "input": "88 79 8", "output": "9" }, { "input": "90 76 59", "output": "14" }, { "input": "92 2 22", "output": "23" }, { "input": "94 5 88", "output": "89" }, { "input": "94 62 48", "output": "32" }, { "input": "96 22 72", "output": "73" }, { "input": "100 11 88", "output": "89" }, { "input": "100 81 91", "output": "19" }, { "input": "1 0 0", "output": "1" } ]
1,685,643,367
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
60
0
n, x, y = map(int, input().split()) possible_spots = max(n - x, y) print(possible_spots)
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. Input Specification: The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100). Output Specification: Print the single number — the number of the sought positions. Demo Input: ['3 1 1\n', '5 2 3\n'] Demo Output: ['2\n', '3\n'] Note: The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
```python n, x, y = map(int, input().split()) possible_spots = max(n - x, y) print(possible_spots) ```
0
735
A
Ostap and Grasshopper
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
[ "5 2\n#G#T#\n", "6 1\nT....G\n", "7 3\nT..#..G\n", "6 2\n..GT..\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
500
[ { "input": "5 2\n#G#T#", "output": "YES" }, { "input": "6 1\nT....G", "output": "YES" }, { "input": "7 3\nT..#..G", "output": "NO" }, { "input": "6 2\n..GT..", "output": "NO" }, { "input": "2 1\nGT", "output": "YES" }, { "input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####", "output": "YES" }, { "input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####", "output": "NO" }, { "input": "2 1\nTG", "output": "YES" }, { "input": "99 1\n...T.............................................................................................G.", "output": "YES" }, { "input": "100 2\nG............#.....#...........#....#...........##............#............#......................T.", "output": "NO" }, { "input": "100 1\n#.#.#.##..#..##.#....##.##.##.#....####..##.#.##..GT..##...###.#.##.#..#..##.###..#.####..#.#.##..##", "output": "YES" }, { "input": "100 2\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.", "output": "NO" }, { "input": "100 3\nG..................................................................................................T", "output": "YES" }, { "input": "100 3\nG..................................................................................................T", "output": "YES" }, { "input": "100 3\nG..................................#......#......#.......#.#..........#........#......#..........#.T", "output": "NO" }, { "input": "100 3\nG..............#..........#...#..............#.#.....................#......#........#.........#...T", "output": "NO" }, { "input": "100 3\nG##################################################################################################T", "output": "NO" }, { "input": "100 33\nG..................................................................................................T", "output": "YES" }, { "input": "100 33\nG..................................................................................................T", "output": "YES" }, { "input": "100 33\nG.........#........#..........#..............#.................#............................#.#....T", "output": "YES" }, { "input": "100 33\nG.......#..................#..............................#............................#..........T.", "output": "NO" }, { "input": "100 33\nG#..........##...#.#.....................#.#.#.........##..#...........#....#...........##...#..###T", "output": "YES" }, { "input": "100 33\nG..#.#..#..####......#......##...##...#.##........#...#...#.##....###..#...###..##.#.....#......#.T.", "output": "NO" }, { "input": "100 33\nG#....#..#..##.##..#.##.#......#.#.##..##.#.#.##.##....#.#.....####..##...#....##..##..........#...T", "output": "NO" }, { "input": "100 33\nG#######.#..##.##.#...#..#.###.#.##.##.#..#.###..####.##.#.##....####...##..####.#..##.##.##.#....#T", "output": "NO" }, { "input": "100 33\nG#####.#.##.###########.##..##..#######..########..###.###..#.####.######.############..####..#####T", "output": "NO" }, { "input": "100 99\nT..................................................................................................G", "output": "YES" }, { "input": "100 99\nT..................................................................................................G", "output": "YES" }, { "input": "100 99\nT.#...............................#............#..............................##...................G", "output": "YES" }, { "input": "100 99\nT..#....#.##...##########.#.#.#.#...####..#.....#..##..#######.######..#.....###..###...#.......#.#G", "output": "YES" }, { "input": "100 99\nG##################################################################################################T", "output": "YES" }, { "input": "100 9\nT..................................................................................................G", "output": "YES" }, { "input": "100 9\nT.................................................................................................G.", "output": "NO" }, { "input": "100 9\nT................................................................................................G..", "output": "NO" }, { "input": "100 1\nG..................................................................................................T", "output": "YES" }, { "input": "100 1\nT..................................................................................................G", "output": "YES" }, { "input": "100 1\n##########G.........T###############################################################################", "output": "YES" }, { "input": "100 1\n#################################################################################################G.T", "output": "YES" }, { "input": "100 17\n##########G################.################.################.################T#####################", "output": "YES" }, { "input": "100 17\n####.#..#.G######.#########.##..##########.#.################.################T######.####.#########", "output": "YES" }, { "input": "100 17\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##", "output": "YES" }, { "input": "100 1\nG.............................................#....................................................T", "output": "NO" }, { "input": "100 1\nT.#................................................................................................G", "output": "NO" }, { "input": "100 1\n##########G....#....T###############################################################################", "output": "NO" }, { "input": "100 1\n#################################################################################################G#T", "output": "NO" }, { "input": "100 17\nG################.#################################.################T###############################", "output": "NO" }, { "input": "100 17\nG################.###############..###.######.#######.###.#######.##T######################.###.####", "output": "NO" }, { "input": "100 17\nG####.##.##.#####.####....##.####.#########.##.#..#.###############.T############.#########.#.####.#", "output": "NO" }, { "input": "48 1\nT..............................................G", "output": "YES" }, { "input": "23 1\nT.....................G", "output": "YES" }, { "input": "49 1\nG...............................................T", "output": "YES" }, { "input": "3 1\nTG#", "output": "YES" }, { "input": "6 2\n..TG..", "output": "NO" }, { "input": "14 3\n...G.....#..T.", "output": "NO" }, { "input": "5 4\n##GT#", "output": "NO" }, { "input": "6 2\nT#..G.", "output": "YES" }, { "input": "5 2\nT.G.#", "output": "YES" }, { "input": "6 1\nT...G#", "output": "YES" }, { "input": "5 1\nTG###", "output": "YES" }, { "input": "5 4\n.G..T", "output": "NO" }, { "input": "7 2\nT#...#G", "output": "YES" }, { "input": "7 1\n##TG###", "output": "YES" }, { "input": "7 1\n###GT##", "output": "YES" }, { "input": "5 2\nG..T.", "output": "NO" }, { "input": "5 1\nG.T##", "output": "YES" }, { "input": "6 2\nG.T###", "output": "YES" }, { "input": "6 2\nG#T###", "output": "YES" }, { "input": "10 2\n####T..G..", "output": "NO" }, { "input": "3 1\nGT#", "output": "YES" }, { "input": "4 1\nTG##", "output": "YES" }, { "input": "6 1\n.G..T.", "output": "YES" }, { "input": "10 3\n......G..T", "output": "YES" }, { "input": "3 2\nG.T", "output": "YES" }, { "input": "4 1\n#G.T", "output": "YES" }, { "input": "5 2\nT#G##", "output": "YES" }, { "input": "4 2\nG#.T", "output": "NO" }, { "input": "4 1\nGT##", "output": "YES" } ]
1,556,849,174
374
Python 3
RUNTIME_ERROR
TESTS
11
108
0
n, k = map(int, input().split()) s = input() G, T = -1, -1 for i in range(n): if s[i] == 'G': G = i elif s[i] == 'T': T = i if G < T: while G < T and s[G] != '#': G += k if s[G] == 'T': print('YES') exit() print('NO') else: while G > T and s[G] != '#': G -= k if s[G] == 'T': print('YES') exit() print('NO')
Title: Ostap and Grasshopper Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. Input Specification: The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. Output Specification: If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). Demo Input: ['5 2\n#G#T#\n', '6 1\nT....G\n', '7 3\nT..#..G\n', '6 2\n..GT..\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
```python n, k = map(int, input().split()) s = input() G, T = -1, -1 for i in range(n): if s[i] == 'G': G = i elif s[i] == 'T': T = i if G < T: while G < T and s[G] != '#': G += k if s[G] == 'T': print('YES') exit() print('NO') else: while G > T and s[G] != '#': G -= k if s[G] == 'T': print('YES') exit() print('NO') ```
-1
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,618,547,461
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
n=int(input()) l=list(map(int,input().split())) e,o=0,0 e_i,o_i=0,0 for i in range(n): if l[i]%2==0: e+=1 e_i=i if l[i]%2==1: o+=1 o_i=i if e>1 and o==1: print(l[o_i]) break if o>1 and e==1: print(l[e_i]) break
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()) l=list(map(int,input().split())) e,o=0,0 e_i,o_i=0,0 for i in range(n): if l[i]%2==0: e+=1 e_i=i if l[i]%2==1: o+=1 o_i=i if e>1 and o==1: print(l[o_i]) break if o>1 and e==1: print(l[e_i]) break ```
0
525
A
Vitaliy and Pie
PROGRAMMING
1,100
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number.
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1.
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
250
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY", "output": "13" }, { "input": "5\naArRaRaR", "output": "2" }, { "input": "2\ndA", "output": "1" }, { "input": "2\ncB", "output": "1" }, { "input": "10\nhNcMeXsSlHsUwYeMcA", "output": "7" }, { "input": "100\nqDpInBmCrFwXpDbFgOzVvOcEmJrUcToAdEwEgTvBvBfWwRpGyEaXgDdRwVlQnYgWmWhMrHaIzPyXvGaFlRsVzHhZrOuVpXrKxFzAmWwPlFtNfPtJxVmLuHjKfYyArHrEnSwSzOvDpQhCgCqLlAcNpGhXrEeFuCmAqIkXyYtSsQwIxJzNiIuTgEbVuWrMwPrAlLyKaZ", "output": "42" }, { "input": "2\ndD", "output": "0" }, { "input": "2\ndE", "output": "1" }, { "input": "3\ndDdD", "output": "0" }, { "input": "3\ndEdD", "output": "1" }, { "input": "3\ndEeD", "output": "1" }, { "input": "3\ndEeF", "output": "2" } ]
1,685,625,248
2,147,483,647
Python 3
OK
TESTS
46
140
409,600
n = int(input()) s = input() d = {} lt = 'qwertyuiopasdfghjklmnbvcxz' for l in lt: d[l] = 0 cnt = 0 for i in s: if i.islower(): d[i] += 1 else: if d[i.lower()] <= 0: cnt += 1 else: d[i.lower()] -= 1 print(cnt)
Title: Vitaliy and Pie Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number. Input Specification: The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1. Output Specification: Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. Demo Input: ['3\naAbB\n', '4\naBaCaB\n', '5\nxYyXzZaZ\n'] Demo Output: ['0\n', '3\n', '2\n'] Note: none
```python n = int(input()) s = input() d = {} lt = 'qwertyuiopasdfghjklmnbvcxz' for l in lt: d[l] = 0 cnt = 0 for i in s: if i.islower(): d[i] += 1 else: if d[i.lower()] <= 0: cnt += 1 else: d[i.lower()] -= 1 print(cnt) ```
3
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "output": "YES" }, { "input": "1\n999993399999", "output": "NO" }, { "input": "9\n111 121 131 111 121 131 111 121 131", "output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO" }, { "input": "1\n1", "output": "NO" }, { "input": "1\n10", "output": "NO" }, { "input": "1\n976197352729", "output": "NO" }, { "input": "1\n1000000000000", "output": "NO" }, { "input": "1\n9", "output": "YES" }, { "input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n223092870 6469693230 200560490130", "output": "NO\nNO\nNO" }, { "input": "2\n81 25", "output": "NO\nYES" }, { "input": "1\n16", "output": "NO" }, { "input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "1\n225", "output": "NO" }, { "input": "1\n1521", "output": "NO" }, { "input": "1\n81", "output": "NO" } ]
1,696,927,014
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
122
2,867,200
t=int(input()) for i in range(0,t): n=map(int,input().split()) for j in n: count=0 for w in range(1,j+1): if(j%w==0): count=count+1 if(count==3): print("YES") else: print("NO")
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. Input Specification: The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. Output Specification: Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. Demo Input: ['3\n4 5 6\n'] Demo Output: ['YES\nNO\nNO\n'] Note: The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
```python t=int(input()) for i in range(0,t): n=map(int,input().split()) for j in n: count=0 for w in range(1,j+1): if(j%w==0): count=count+1 if(count==3): print("YES") else: print("NO") ```
-1
152
A
Marks
PROGRAMMING
900
[ "implementation" ]
null
null
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at. Your task is to find the number of successful students in the group.
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.
Print the single number — the number of successful students in the given group.
[ "3 3\n223\n232\n112\n", "3 5\n91728\n11828\n11111\n" ]
[ "2\n", "3\n" ]
In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject. In the second sample test each student is the best at at least one subject.
500
[ { "input": "3 3\n223\n232\n112", "output": "2" }, { "input": "3 5\n91728\n11828\n11111", "output": "3" }, { "input": "2 2\n48\n27", "output": "1" }, { "input": "2 1\n4\n6", "output": "1" }, { "input": "1 2\n57", "output": "1" }, { "input": "1 1\n5", "output": "1" }, { "input": "3 4\n2553\n6856\n5133", "output": "2" }, { "input": "8 7\n6264676\n7854895\n3244128\n2465944\n8958761\n1378945\n3859353\n6615285", "output": "6" }, { "input": "9 8\n61531121\n43529859\n18841327\n88683622\n98995641\n62741632\n57441743\n49396792\n63381994", "output": "4" }, { "input": "10 20\n26855662887514171367\n48525577498621511535\n47683778377545341138\n47331616748732562762\n44876938191354974293\n24577238399664382695\n42724955594463126746\n79187344479926159359\n48349683283914388185\n82157191115518781898", "output": "9" }, { "input": "20 15\n471187383859588\n652657222494199\n245695867594992\n726154672861295\n614617827782772\n862889444974692\n373977167653235\n645434268565473\n785993468314573\n722176861496755\n518276853323939\n723712762593348\n728935312568886\n373898548522463\n769777587165681\n247592995114377\n182375946483965\n497496542536127\n988239919677856\n859844339819143", "output": "18" }, { "input": "13 9\n514562255\n322655246\n135162979\n733845982\n473117129\n513967187\n965649829\n799122777\n661249521\n298618978\n659352422\n747778378\n723261619", "output": "11" }, { "input": "75 1\n2\n3\n8\n3\n2\n1\n3\n1\n5\n1\n5\n4\n8\n8\n4\n2\n5\n1\n7\n6\n3\n2\n2\n3\n5\n5\n2\n4\n7\n7\n9\n2\n9\n5\n1\n4\n9\n5\n2\n4\n6\n6\n3\n3\n9\n3\n3\n2\n3\n4\n2\n6\n9\n1\n1\n1\n1\n7\n2\n3\n2\n9\n7\n4\n9\n1\n7\n5\n6\n8\n3\n4\n3\n4\n6", "output": "7" }, { "input": "92 3\n418\n665\n861\n766\n529\n416\n476\n676\n561\n995\n415\n185\n291\n176\n776\n631\n556\n488\n118\n188\n437\n496\n466\n131\n914\n118\n766\n365\n113\n897\n386\n639\n276\n946\n759\n169\n494\n837\n338\n351\n783\n311\n261\n862\n598\n132\n246\n982\n575\n364\n615\n347\n374\n368\n523\n132\n774\n161\n552\n492\n598\n474\n639\n681\n635\n342\n516\n483\n141\n197\n571\n336\n175\n596\n481\n327\n841\n133\n142\n146\n246\n396\n287\n582\n556\n996\n479\n814\n497\n363\n963\n162", "output": "23" }, { "input": "100 1\n1\n6\n9\n1\n1\n5\n5\n4\n6\n9\n6\n1\n7\n8\n7\n3\n8\n8\n7\n6\n2\n1\n5\n8\n7\n3\n5\n4\n9\n7\n1\n2\n4\n1\n6\n5\n1\n3\n9\n4\n5\n8\n1\n2\n1\n9\n7\n3\n7\n1\n2\n2\n2\n2\n3\n9\n7\n2\n4\n7\n1\n6\n8\n1\n5\n6\n1\n1\n2\n9\n7\n4\n9\n1\n9\n4\n1\n3\n5\n2\n4\n4\n6\n5\n1\n4\n5\n8\n4\n7\n6\n5\n6\n9\n5\n8\n1\n5\n1\n6", "output": "10" }, { "input": "100 2\n71\n87\n99\n47\n22\n87\n49\n73\n21\n12\n77\n43\n18\n41\n78\n62\n61\n16\n64\n89\n81\n54\n53\n92\n93\n94\n68\n93\n15\n68\n42\n93\n28\n19\n86\n16\n97\n17\n11\n43\n72\n76\n54\n95\n58\n53\n48\n45\n85\n85\n74\n21\n44\n51\n89\n75\n76\n17\n38\n62\n81\n22\n66\n59\n89\n85\n91\n87\n12\n97\n52\n87\n43\n89\n51\n58\n57\n98\n78\n68\n82\n41\n87\n29\n75\n72\n48\n14\n35\n71\n74\n91\n66\n67\n42\n98\n52\n54\n22\n41", "output": "21" }, { "input": "5 20\n11111111111111111111\n11111111111111111111\n11111111111111111111\n99999999999999999999\n11111111111111111119", "output": "2" }, { "input": "3 3\n111\n111\n999", "output": "1" }, { "input": "3 3\n119\n181\n711", "output": "3" }, { "input": "15 5\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111", "output": "15" }, { "input": "2 20\n22222222222222222222\n11111111111111111111", "output": "1" }, { "input": "3 3\n233\n222\n111", "output": "2" }, { "input": "4 15\n222222222222222\n111111111111119\n111111111111119\n111111111111111", "output": "3" }, { "input": "4 1\n1\n9\n9\n9", "output": "3" }, { "input": "3 3\n123\n321\n132", "output": "3" }, { "input": "3 3\n113\n332\n322", "output": "3" }, { "input": "2 100\n2222222222222222222222222222222222222222222222222222222222222222222222221222222222222222222222222222\n1111111111111111111111111111111111111111111111111111111111111111111111119111111111111111111111111111", "output": "2" }, { "input": "3 3\n321\n231\n123", "output": "3" }, { "input": "2 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222", "output": "1" }, { "input": "3 3\n221\n111\n111", "output": "3" } ]
1,446,896,860
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
import operator n,m = list(map(int,input().split(" "))) s = [] r = [0 for d in range(n)] for i in range(n): s.append(list(map(int,[d for d in input()]))) for i in range(m): g = [d[i] for d in s] max_index = max(enumerate(g), key=operator.itemgetter(1))[0] r[max_index] = 1 print(n-r.count(0))
Title: Marks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at. Your task is to find the number of successful students in the group. Input Specification: The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces. Output Specification: Print the single number — the number of successful students in the given group. Demo Input: ['3 3\n223\n232\n112\n', '3 5\n91728\n11828\n11111\n'] Demo Output: ['2\n', '3\n'] Note: In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject. In the second sample test each student is the best at at least one subject.
```python import operator n,m = list(map(int,input().split(" "))) s = [] r = [0 for d in range(n)] for i in range(n): s.append(list(map(int,[d for d in input()]))) for i in range(m): g = [d[i] for d in s] max_index = max(enumerate(g), key=operator.itemgetter(1))[0] r[max_index] = 1 print(n-r.count(0)) ```
0
1,003
A
Polycarp's Pockets
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$. Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
[ "6\n1 2 4 3 3 2\n", "1\n100\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "6\n1 2 4 3 3 2", "output": "2" }, { "input": "1\n100", "output": "1" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71", "output": "51" }, { "input": "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29", "output": "1" }, { "input": "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24", "output": "2" }, { "input": "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6", "output": "10" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 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": "99" }, { "input": "7\n1 2 3 3 3 1 2", "output": "3" }, { "input": "5\n1 2 3 4 5", "output": "1" }, { "input": "7\n1 2 3 4 5 6 7", "output": "1" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "1" }, { "input": "3\n2 1 1", "output": "2" }, { "input": "11\n1 2 3 4 5 6 7 8 9 1 1", "output": "3" }, { "input": "12\n1 2 1 1 1 1 1 1 1 1 1 1", "output": "11" }, { "input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "13" }, { "input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "14" }, { "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "15" }, { "input": "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "16" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "10\n1 1 1 1 2 2 1 1 9 10", "output": "6" }, { "input": "2\n1 1", "output": "2" }, { "input": "56\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", "output": "56" }, { "input": "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92", "output": "6" }, { "input": "10\n1 2 2 3 3 3 4 4 4 4", "output": "4" }, { "input": "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21", "output": "3" }, { "input": "5\n5 5 5 5 1", "output": "4" }, { "input": "6\n2 3 2 5 2 6", "output": "3" }, { "input": "3\n58 59 58", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 8", "output": "2" }, { "input": "97\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", "output": "97" }, { "input": "3\n95 95 4", "output": "2" }, { "input": "3\n2 2 5", "output": "2" } ]
1,599,199,869
2,147,483,647
PyPy 3
OK
TESTS
37
140
0
n=int(input()) l=input().split() li=[int(i) for i in l] maxa=0 hashi=dict() for i in li: if i in hashi: hashi[i]+=1 else: hashi[i]=1 for i in hashi: maxa=max(maxa,hashi[i]) print(maxa)
Title: Polycarp's Pockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$. Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that. Input Specification: The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. Output Specification: Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. Demo Input: ['6\n1 2 4 3 3 2\n', '1\n100\n'] Demo Output: ['2\n', '1\n'] Note: none
```python n=int(input()) l=input().split() li=[int(i) for i in l] maxa=0 hashi=dict() for i in li: if i in hashi: hashi[i]+=1 else: hashi[i]=1 for i in hashi: maxa=max(maxa,hashi[i]) print(maxa) ```
3
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, { "input": "20\n44444444444444444444", "output": "YES" }, { "input": "2\n44", "output": "YES" }, { "input": "10\n4745474547", "output": "NO" }, { "input": "14\n77770004444444", "output": "NO" }, { "input": "10\n4747777744", "output": "YES" }, { "input": "10\n1234567890", "output": "NO" }, { "input": "50\n44444444444444444444444444444444444444444444444444", "output": "YES" }, { "input": "50\n44444444444444444444444444444444444444444444444447", "output": "NO" }, { "input": "50\n74444444444444444444444444444444444444444444444444", "output": "NO" }, { "input": "50\n07777777777777777777777777777777777777777777777770", "output": "NO" }, { "input": "50\n77777777777777777777777777777777777777777777777777", "output": "YES" }, { "input": "50\n44747747774474747747747447777447774747447477444474", "output": "YES" }, { "input": "48\n447474444777444474747747744774447444747474774474", "output": "YES" }, { "input": "32\n74474474777444474444747774474774", "output": "YES" }, { "input": "40\n4747777444447747777447447747447474774777", "output": "YES" }, { "input": "10\n4477477444", "output": "YES" }, { "input": "18\n447747474447744747", "output": "YES" }, { "input": "26\n44747744444774744774474447", "output": "YES" }, { "input": "50\n44707747774474747747747447777447774747447477444474", "output": "NO" }, { "input": "40\n4747777444447737777447447747447474774777", "output": "NO" }, { "input": "36\n764477744747444444447747747474744444", "output": "NO" }, { "input": "22\n4477407474777477744447", "output": "NO" }, { "input": "32\n74274474777444474444747774474774", "output": "NO" }, { "input": "16\n4744447974444747", "output": "NO" }, { "input": "2\n11", "output": "NO" }, { "input": "2\n22", "output": "NO" }, { "input": "2\n33", "output": "NO" }, { "input": "2\n74", "output": "NO" }, { "input": "2\n55", "output": "NO" }, { "input": "2\n66", "output": "NO" }, { "input": "2\n77", "output": "YES" }, { "input": "2\n88", "output": "NO" }, { "input": "2\n99", "output": "NO" }, { "input": "4\n4004", "output": "NO" }, { "input": "14\n00077774444444", "output": "NO" }, { "input": "6\n004444", "output": "NO" }, { "input": "4\n0044", "output": "NO" }, { "input": "14\n77771114444444", "output": "NO" }, { "input": "14\n44444447777000", "output": "NO" }, { "input": "6\n004774", "output": "NO" } ]
1,587,410,500
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
280
0
n = int(input()) s = input() print('NYOE S'[sum(int(i) for i in s[:n // 2]) == sum(int(i) for i in s[n // 2:]) and set(s) == {'4', '7'} :: 2])
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. Input Specification: The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. Output Specification: On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['2\n47\n', '4\n4738\n', '4\n4774\n'] Demo Output: ['NO\n', 'NO\n', 'YES\n'] Note: In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
```python n = int(input()) s = input() print('NYOE S'[sum(int(i) for i in s[:n // 2]) == sum(int(i) for i in s[n // 2:]) and set(s) == {'4', '7'} :: 2]) ```
0
294
B
Shaass and Bookshelf
PROGRAMMING
1,700
[ "dp", "greedy" ]
null
null
Shaass has *n* books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the *i*-th book is *t**i* and its pages' width is equal to *w**i*. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the bookshelf in the following way. First he selects some of the books and put them vertically. Then he puts the rest of the books horizontally above the vertical books. The sum of the widths of the horizontal books must be no more than the total thickness of the vertical books. A sample arrangement of the books is depicted in the figure. Help Shaass to find the minimum total thickness of the vertical books that we can achieve.
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). Each of the next *n* lines contains two integers *t**i* and *w**i* denoting the thickness and width of the *i*-th book correspondingly, (1<=≤<=*t**i*<=≤<=2,<=1<=≤<=*w**i*<=≤<=100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
[ "5\n1 12\n1 3\n2 15\n2 5\n2 1\n", "3\n1 10\n2 1\n2 4\n" ]
[ "5\n", "3\n" ]
none
1,000
[ { "input": "5\n1 12\n1 3\n2 15\n2 5\n2 1", "output": "5" }, { "input": "3\n1 10\n2 1\n2 4", "output": "3" }, { "input": "10\n2 10\n2 4\n2 8\n2 3\n2 5\n2 6\n1 2\n1 10\n1 10\n2 5", "output": "12" }, { "input": "1\n2 7", "output": "2" }, { "input": "50\n1 24\n1 16\n1 33\n2 34\n1 26\n2 35\n1 39\n2 44\n2 29\n2 28\n1 44\n2 48\n2 50\n2 41\n2 9\n1 22\n2 11\n2 27\n1 12\n1 50\n2 49\n1 17\n2 43\n2 6\n1 39\n2 28\n1 47\n1 45\n2 32\n1 43\n2 40\n1 10\n1 44\n2 31\n2 26\n2 15\n2 20\n1 49\n1 36\n2 43\n2 8\n1 46\n2 43\n2 26\n1 30\n1 23\n2 26\n1 32\n2 25\n2 42", "output": "67" }, { "input": "20\n2 4\n1 2\n2 2\n1 2\n2 1\n1 3\n2 5\n1 3\n1 1\n2 3\n1 4\n2 3\n1 5\n1 4\n1 4\n1 2\n2 5\n1 5\n2 2\n2 2", "output": "16" }, { "input": "30\n1 48\n1 3\n2 20\n2 41\n1 33\n2 46\n2 22\n2 21\n1 6\n2 44\n1 23\n2 28\n1 39\n1 19\n2 15\n2 49\n1 26\n1 22\n2 42\n2 27\n2 31\n1 49\n1 11\n1 33\n1 1\n2 31\n2 9\n1 18\n2 27\n1 18", "output": "38" }, { "input": "40\n2 14\n1 13\n1 51\n2 18\n2 99\n2 85\n1 37\n2 54\n2 82\n1 93\n1 71\n1 76\n1 40\n2 14\n1 61\n1 74\n2 83\n2 75\n1 12\n1 23\n1 95\n1 84\n2 90\n1 40\n1 96\n2 25\n2 68\n2 87\n2 34\n2 66\n2 60\n2 65\n2 18\n2 48\n1 97\n2 71\n1 94\n1 5\n1 47\n1 29", "output": "53" }, { "input": "1\n1 1", "output": "1" }, { "input": "1\n1 2", "output": "1" }, { "input": "2\n1 2\n2 2", "output": "2" }, { "input": "100\n2 2\n1 2\n1 1\n2 1\n1 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n2 2\n2 1\n1 1\n1 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 2\n1 2\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n1 2\n2 2\n1 2\n1 1\n1 1\n1 1\n2 1\n2 1\n1 2\n1 2\n2 2\n1 2\n1 2\n1 1\n2 1\n2 1\n2 2\n1 2\n2 1\n1 1\n2 1\n1 2\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 1\n1 2\n2 1\n1 1\n1 1\n2 2\n2 2\n1 1\n2 1\n1 2\n2 2\n2 1\n1 2\n1 2\n1 2\n1 1\n2 1", "output": "60" }, { "input": "100\n2 2\n1 2\n1 5\n1 5\n1 2\n1 4\n2 3\n1 2\n1 5\n2 1\n2 2\n2 4\n1 2\n2 3\n1 1\n1 1\n2 5\n2 3\n2 2\n1 2\n2 1\n2 2\n1 5\n2 1\n2 4\n1 4\n1 4\n2 2\n1 1\n2 4\n1 4\n2 4\n1 2\n2 3\n2 3\n1 5\n1 5\n2 3\n1 4\n1 5\n2 2\n1 3\n2 2\n2 2\n1 1\n2 1\n2 5\n1 1\n2 3\n2 5\n1 5\n1 3\n1 5\n2 4\n1 5\n2 3\n2 5\n1 4\n2 3\n2 2\n2 5\n2 4\n1 1\n1 1\n1 3\n2 3\n2 1\n2 1\n1 2\n1 1\n2 5\n2 2\n2 1\n2 3\n2 2\n1 5\n1 2\n1 2\n1 1\n1 2\n1 4\n1 5\n1 4\n1 3\n1 1\n1 2\n2 2\n2 4\n1 2\n1 1\n2 3\n2 3\n2 5\n2 1\n1 5\n1 5\n1 4\n2 2\n1 4\n2 4", "output": "76" }, { "input": "50\n1 69\n2 39\n1 32\n2 35\n1 25\n2 24\n1 59\n2 99\n2 48\n2 54\n1 87\n1 81\n2 42\n2 8\n2 92\n1 78\n2 70\n2 91\n1 86\n1 87\n2 15\n1 93\n1 82\n2 36\n1 12\n1 56\n2 84\n1 98\n1 89\n2 79\n1 22\n1 65\n1 40\n2 13\n2 95\n2 93\n1 9\n2 99\n2 100\n1 76\n2 56\n1 10\n1 2\n2 93\n2 21\n2 33\n1 21\n1 81\n2 10\n2 93", "output": "66" }, { "input": "10\n1 61\n1 92\n2 97\n1 70\n2 37\n2 44\n2 29\n1 94\n2 65\n1 48", "output": "15" }, { "input": "40\n2 14\n1 13\n1 51\n2 18\n2 99\n2 85\n1 37\n2 54\n2 82\n1 93\n1 71\n1 76\n1 40\n2 14\n1 61\n1 74\n2 83\n2 75\n1 12\n1 23\n1 95\n1 84\n2 90\n1 40\n1 96\n2 25\n2 68\n2 87\n2 34\n2 66\n2 60\n2 65\n2 18\n2 48\n1 97\n2 71\n1 94\n1 5\n1 47\n1 29", "output": "53" }, { "input": "2\n1 100\n1 100", "output": "2" }, { "input": "3\n2 5\n2 5\n2 5", "output": "6" } ]
1,661,278,359
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
11
93
10,956,800
import sys import math import collections from heapq import heappush, heappop from functools import reduce input = sys.stdin.readline ints = lambda: list(map(int, input().split())) n = int(input()) b = [] mx = 0 for _ in range(n): t, w = ints() mx += w b.append((t, w)) dp = [[math.inf for _ in range(mx + 1)] for _ in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(mx + 1): if dp[i][j] != math.inf: dp[i + 1][j] = min(dp[i + 1][j], b[i][0] + dp[i][j]) dp[i + 1][j + b[i][1]] = min(dp[i + 1][j + b[i][1]], dp[i][j]) ans = math.inf for i in range(mx + 1): if i <= dp[-1][i]: ans = min(ans, dp[-1][i]) print(ans)
Title: Shaass and Bookshelf Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has *n* books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the *i*-th book is *t**i* and its pages' width is equal to *w**i*. The thickness of each book is either 1 or 2. All books have the same page heights. Shaass puts the books on the bookshelf in the following way. First he selects some of the books and put them vertically. Then he puts the rest of the books horizontally above the vertical books. The sum of the widths of the horizontal books must be no more than the total thickness of the vertical books. A sample arrangement of the books is depicted in the figure. Help Shaass to find the minimum total thickness of the vertical books that we can achieve. Input Specification: The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). Each of the next *n* lines contains two integers *t**i* and *w**i* denoting the thickness and width of the *i*-th book correspondingly, (1<=≤<=*t**i*<=≤<=2,<=1<=≤<=*w**i*<=≤<=100). Output Specification: On the only line of the output print the minimum total thickness of the vertical books that we can achieve. Demo Input: ['5\n1 12\n1 3\n2 15\n2 5\n2 1\n', '3\n1 10\n2 1\n2 4\n'] Demo Output: ['5\n', '3\n'] Note: none
```python import sys import math import collections from heapq import heappush, heappop from functools import reduce input = sys.stdin.readline ints = lambda: list(map(int, input().split())) n = int(input()) b = [] mx = 0 for _ in range(n): t, w = ints() mx += w b.append((t, w)) dp = [[math.inf for _ in range(mx + 1)] for _ in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(mx + 1): if dp[i][j] != math.inf: dp[i + 1][j] = min(dp[i + 1][j], b[i][0] + dp[i][j]) dp[i + 1][j + b[i][1]] = min(dp[i + 1][j + b[i][1]], dp[i][j]) ans = math.inf for i in range(mx + 1): if i <= dp[-1][i]: ans = min(ans, dp[-1][i]) print(ans) ```
0
896
A
Nephren gives a riddle
PROGRAMMING
1,700
[ "binary search", "dfs and similar" ]
null
null
Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, *f*0... ∞. *f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? Are you busy? Will you send "*f**i*<=-<=1"?" for all *i*<=≥<=1. For example, *f*1 is "What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of *f*1. It can be seen that the characters in *f**i* are letters, question marks, (possibly) quotation marks and spaces. Nephren will ask the little leprechauns *q* times. Each time she will let them find the *k*-th character of *f**n*. The characters are indexed starting from 1. If *f**n* consists of less than *k* characters, output '.' (without quotes). Can you answer her queries?
The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions. Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018).
One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query.
[ "3\n1 1\n1 2\n1 111111111111\n", "5\n0 69\n1 194\n1 139\n0 47\n1 66\n", "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n" ]
[ "Wh.", "abdef", "Areyoubusy" ]
For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend.
500
[ { "input": "3\n1 1\n1 2\n1 111111111111", "output": "Wh." }, { "input": "5\n0 69\n1 194\n1 139\n0 47\n1 66", "output": "abdef" }, { "input": "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474", "output": "Areyoubusy" }, { "input": "1\n0 1", "output": "W" }, { "input": "1\n999 1000000000000000000", "output": "?" }, { "input": "10\n1 8\n1 8\n9 5\n0 1\n8 1\n7 3\n5 2\n0 9\n4 6\n9 4", "output": "ee WWah at" }, { "input": "10\n5 235941360876088213\n10 65160787148797531\n0 531970131175601601\n2 938108094014908387\n3 340499457696664259\n5 56614532774539063\n5 719524142056884004\n10 370927072502555372\n2 555965798821270052\n10 492559401050725258", "output": ".........." }, { "input": "10\n72939 670999605706502447\n67498 428341803949410086\n62539 938370976591475035\n58889 657471364021290792\n11809 145226347556228466\n77111 294430864855433173\n29099 912050147755964704\n27793 196249143894732547\n118 154392540400153863\n62843 63234003203996349", "output": "?usaglrnyh" }, { "input": "10\n74 752400948436334811\n22 75900251524550494\n48 106700456127359025\n20 623493261724933249\n90 642991963097110817\n42 47750435275360941\n24 297055789449373682\n65 514620361483452045\n99 833434466044716497\n0 928523848526511085", "output": "h... .. d." }, { "input": "10\n26302 2898997\n2168 31686909\n56241 27404733\n9550 44513376\n70116 90169838\n14419 95334944\n61553 16593205\n85883 42147334\n55209 74676056\n57866 68603505", "output": "donts ly o" }, { "input": "9\n50 161003686678495163\n50 161003686678495164\n50 161003686678495165\n51 322007373356990395\n51 322007373356990396\n51 322007373356990397\n52 644014746713980859\n52 644014746713980860\n52 644014746713980861", "output": "\"?.\"?.\"?." }, { "input": "10\n100000 1000000000000000000\n99999 999999999999998683\n99998 999999999999997366\n99997 999999999999996049\n99996 999999999999994732\n99995 999999999999993415\n99994 999999999999992098\n99993 999999999999990781\n99992 999999999999989464\n99991 999999999999988147", "output": "o u lugW? " }, { "input": "10\n94455 839022536766957828\n98640 878267599238035211\n90388 54356607570140506\n93536 261222577013066170\n91362 421089574363407592\n95907 561235487589345620\n91888 938806156011561508\n90820 141726323964466814\n97856 461989202234320135\n92518 602709074380260370", "output": "youni iiee" }, { "input": "10\n100000 873326525630182716\n100000 620513733919162415\n100000 482953375281256917\n100000 485328193417229962\n100000 353549227094721271\n100000 367447590857326107\n100000 627193846053528323\n100000 243833127760837417\n100000 287297493528203749\n100000 70867563577617188", "output": "o W rlot" }, { "input": "10\n1 1\n1 34\n1 35\n1 109\n1 110\n1 141\n1 142\n1 216\n1 217\n1 218", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n5 1\n5 34\n5 35\n5 2254\n5 2255\n5 2286\n5 2287\n5 4506\n5 4507\n5 4508", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n10 1\n10 34\n10 35\n10 73182\n10 73183\n10 73214\n10 73215\n10 146362\n10 146363\n10 146364", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n15 1\n15 34\n15 35\n15 2342878\n15 2342879\n15 2342910\n15 2342911\n15 4685754\n15 4685755\n15 4685756", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n35 1\n35 34\n35 35\n35 2456721293278\n35 2456721293279\n35 2456721293310\n35 2456721293311\n35 4913442586554\n35 4913442586555\n35 4913442586556", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n47 1\n47 34\n47 35\n47 10062730417405918\n47 10062730417405919\n47 10062730417405950\n47 10062730417405951\n47 20125460834811834\n47 20125460834811835\n47 20125460834811836", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n50 1\n50 34\n50 35\n50 80501843339247582\n50 80501843339247583\n50 80501843339247614\n50 80501843339247615\n50 161003686678495162\n50 161003686678495163\n50 161003686678495164", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n52 1\n52 34\n52 35\n52 322007373356990430\n52 322007373356990431\n52 322007373356990462\n52 322007373356990463\n52 644014746713980858\n52 644014746713980859\n52 644014746713980860", "output": "W\"W?\"\"W?\"?" }, { "input": "10\n54986 859285936548585889\n49540 198101079999865795\n96121 658386311981208488\n27027 787731514451843966\n60674 736617460878411577\n57761 569094390437687993\n93877 230086639196124716\n75612 765187050118682698\n75690 960915623784157529\n1788 121643460920471434", "output": "oru A\" de\"" }, { "input": "10\n13599 295514896417102030\n70868 206213281730527977\n99964 675362501525687265\n8545 202563221795027954\n62885 775051601455683055\n44196 552672589494215033\n38017 996305706075726957\n82157 778541544539864990\n13148 755735956771594947\n66133 739544460375378867", "output": "t?W y wnr" }, { "input": "10\n23519 731743847695683578\n67849 214325487756157455\n39048 468966654215390234\n30476 617394929138211942\n40748 813485737737987237\n30632 759622821110550585\n30851 539152740395520686\n23942 567423516617312907\n93605 75958684925842506\n24977 610678262374451619", "output": "WonreeuhAn" }, { "input": "10\n66613 890998077399614704\n59059 389024292752123693\n10265 813853582068134597\n71434 128404685079108014\n76180 582880920044162144\n1123 411409570241705915\n9032 611954441092300071\n78951 57503725302368508\n32102 824738435154619172\n44951 53991552354407935", "output": "i oio u? " }, { "input": "10\n96988 938722606709261427\n97034 794402579184858837\n96440 476737696947281053\n96913 651380108479508367\n99570 535723325634376015\n97425 180427887538234591\n97817 142113098762476646\n96432 446510004868669235\n98788 476529766139390976\n96231 263034481360542586", "output": "eunWwdtnA " }, { "input": "10\n99440 374951566577777567\n98662 802514785210488315\n97117 493713886491759829\n97252 66211820117659651\n98298 574157457621712902\n99067 164006086594761631\n99577 684960128787303079\n96999 12019940091341344\n97772 796752494293638534\n96958 134168283359615339", "output": "idrd? o nl" }, { "input": "10\n95365 811180517856359115\n97710 810626986941150496\n98426 510690080331205902\n99117 481043523165876343\n95501 612591593904017084\n96340 370956318211097183\n96335 451179199961872617\n95409 800901907873821965\n97650 893603181298142989\n96159 781930052798879580", "output": "oisv\"sb ta" }, { "input": "10\n96759 970434747560290241\n95684 985325796232084031\n99418 855577012478917561\n98767 992053283401739711\n99232 381986776210191990\n97804 22743067342252513\n95150 523980900658652001\n98478 290982116558877566\n98012 642382931526919655\n96374 448615375338644407", "output": " e\"atdW? e" }, { "input": "10\n5 929947814902665291\n0 270929202623248779\n10 917958578362357217\n3 674632947904782968\n7 19875145653630834\n8 744882317760093379\n4 471398991908637021\n7 253934163977433229\n7 125334789085610404\n10 841267552326270425", "output": ".........." }, { "input": "10\n3 366176770476214135\n10 55669371794102449\n1 934934767906835993\n0 384681214954881520\n4 684989729845321867\n8 231000356557573162\n1 336780423782602481\n2 300230185318227609\n7 23423148068105278\n1 733131408103947638", "output": ".........." }, { "input": "10\n6 25777762904538788\n1 63781573524764630\n5 951910961746282066\n9 280924325736375136\n6 96743418218239198\n1 712038707283212867\n4 780465093108032992\n4 608326071277553255\n8 542408204244362417\n3 360163123764607419", "output": ".........." }, { "input": "10\n1 185031988313502617\n8 461852423965441269\n2 296797889599026429\n3 15306118532047016\n6 866138600524414105\n10 587197493269144005\n2 853266793804812376\n2 98406279962608857\n3 291187954473139083\n0 26848446304372246", "output": ".........." }, { "input": "10\n27314 39\n71465 12\n29327 53\n33250 85\n52608 41\n19454 55\n72760 12\n83873 90\n67859 78\n91505 73", "output": " u nrhuiy " }, { "input": "10\n76311 57\n79978 83\n34607 89\n62441 98\n28700 35\n54426 67\n66596 15\n30889 21\n68793 7\n29916 71", "output": "lohiW ohra" } ]
1,662,622,532
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
102,400
from functools import cache import sys sys.setrecursionlimit(100004) input=sys.stdin.readline if __name__=='__main__': s0="What are you doing at the end of the world? Are you busy? Will you save us?" # print(len(s0)) head='What are you doing while sending "' # print(len(head)) mid='"? Are you busy? Will you send "' # print(len(mid)) tail='"?' # print(len(tail)) @cache def length(n): return 75 if n==0 else length(n-1)+34+32+2 def found(n,k): if n==0: return s0[k] if k<=75 else '.' pre,now=length(n-1),length(n) s1,s2,s3,s4=34,34+pre,34+pre+32,34+pre+32+pre # print(s1,s2,s3,s4) if k<s1: return head[k] elif s1<=k<s2: return found(n-1,k-s1) elif s2<=k<s3: return mid[k-s2] elif s3<=k<s4: return found(n-1,k-s3) elif s4<=k<now: return tail[k-s4] else: return '.' t=int(input()) for _ in range(t): n,k=map(int,input().split()) print(found(n,k-1),end='')
Title: Nephren gives a riddle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, *f*0... ∞. *f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? Are you busy? Will you send "*f**i*<=-<=1"?" for all *i*<=≥<=1. For example, *f*1 is "What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of *f*1. It can be seen that the characters in *f**i* are letters, question marks, (possibly) quotation marks and spaces. Nephren will ask the little leprechauns *q* times. Each time she will let them find the *k*-th character of *f**n*. The characters are indexed starting from 1. If *f**n* consists of less than *k* characters, output '.' (without quotes). Can you answer her queries? Input Specification: The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions. Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018). Output Specification: One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query. Demo Input: ['3\n1 1\n1 2\n1 111111111111\n', '5\n0 69\n1 194\n1 139\n0 47\n1 66\n', '10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n'] Demo Output: ['Wh.', 'abdef', 'Areyoubusy'] Note: For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend.
```python from functools import cache import sys sys.setrecursionlimit(100004) input=sys.stdin.readline if __name__=='__main__': s0="What are you doing at the end of the world? Are you busy? Will you save us?" # print(len(s0)) head='What are you doing while sending "' # print(len(head)) mid='"? Are you busy? Will you send "' # print(len(mid)) tail='"?' # print(len(tail)) @cache def length(n): return 75 if n==0 else length(n-1)+34+32+2 def found(n,k): if n==0: return s0[k] if k<=75 else '.' pre,now=length(n-1),length(n) s1,s2,s3,s4=34,34+pre,34+pre+32,34+pre+32+pre # print(s1,s2,s3,s4) if k<s1: return head[k] elif s1<=k<s2: return found(n-1,k-s1) elif s2<=k<s3: return mid[k-s2] elif s3<=k<s4: return found(n-1,k-s3) elif s4<=k<now: return tail[k-s4] else: return '.' t=int(input()) for _ in range(t): n,k=map(int,input().split()) print(found(n,k-1),end='') ```
-1
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307", "output": "22258199.5000000000" }, { "input": "2 1000000000\n0 1000000000", "output": "500000000.0000000000" }, { "input": "2 555\n200 300", "output": "255.0000000000" }, { "input": "1 1\n1", "output": "1.0000000000" }, { "input": "1 1\n0", "output": "1.0000000000" }, { "input": "1 1000000000\n0", "output": "1000000000.0000000000" }, { "input": "1 1000000000\n1000000000", "output": "1000000000.0000000000" }, { "input": "1 999999999\n499999999", "output": "500000000.0000000000" }, { "input": "4 700\n0 250 475 700", "output": "125.0000000000" }, { "input": "4 700\n0 225 450 700", "output": "125.0000000000" }, { "input": "5 1000\n0 250 500 750 1000", "output": "125.0000000000" }, { "input": "5 2000\n1001 1001 1001 1001 1001", "output": "1001.0000000000" }, { "input": "1 999\n501", "output": "501.0000000000" }, { "input": "2 1000\n400 600", "output": "400.0000000000" }, { "input": "4 15\n1 3 9 11", "output": "4.0000000000" }, { "input": "1 5\n2", "output": "3.0000000000" } ]
1,687,443,780
1,080
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n , l = map(int , input().split()) arr = sorted( map( int, input().split() ) ) min_d = max( arr[0] , l - arr[-1] ) dist = [ min_d ] for i in range(l-1): a, b = arr[i] , arr[i+1] mid = (a+b)/2 -a if mid > min_d : dist.append( mid ) dist = sorted( dist ) for d in dist: is_true = True for i in range(l-1): a, b = arr[i] , arr[i+1] mid = (a+b)/2 -a if mid > d: is_true = False break if is_true: print(d) break
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? Input Specification: The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. Output Specification: Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. Demo Input: ['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n'] Demo Output: ['2.5000000000\n', '2.0000000000\n'] Note: Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
```python n , l = map(int , input().split()) arr = sorted( map( int, input().split() ) ) min_d = max( arr[0] , l - arr[-1] ) dist = [ min_d ] for i in range(l-1): a, b = arr[i] , arr[i+1] mid = (a+b)/2 -a if mid > min_d : dist.append( mid ) dist = sorted( dist ) for d in dist: is_true = True for i in range(l-1): a, b = arr[i] , arr[i+1] mid = (a+b)/2 -a if mid > d: is_true = False break if is_true: print(d) break ```
-1
979
C
Kuro and Walking Route
PROGRAMMING
1,600
[ "dfs and similar", "trees" ]
null
null
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$). Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him. Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.
The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.
A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route.
[ "3 1 3\n1 2\n2 3\n", "3 1 3\n1 2\n1 3\n" ]
[ "5", "4" ]
On the first example, Kuro can choose these pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$. Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order). On the second example, Kuro can choose the following pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$.
1,250
[ { "input": "3 1 3\n1 2\n2 3", "output": "5" }, { "input": "3 1 3\n1 2\n1 3", "output": "4" }, { "input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 2\n35 27\n39 20\n1 24\n1 53\n35 58\n39 37\n61 13\n61 16\n1 12\n32 17\n1 40\n33 47\n29 52\n1 39\n35 19\n39 50\n27 6\n26 3\n26 55\n35 31\n1 61\n1 23\n27 45\n39 7\n1 35\n39 29\n27 5\n39 32\n27 48\n35 49\n29 54\n1 46\n35 36\n31 33", "output": "3657" }, { "input": "8 5 1\n5 8\n1 5\n1 3\n1 4\n5 6\n6 7\n1 2", "output": "40" }, { "input": "31 29 20\n29 23\n29 18\n22 14\n29 20\n1 21\n29 10\n28 2\n1 17\n17 15\n1 11\n29 31\n28 6\n12 29\n12 26\n1 13\n22 4\n29 25\n28 22\n17 5\n28 30\n20 27\n29 8\n12 28\n1 12\n12 24\n22 7\n12 16\n12 3\n28 9\n1 19", "output": "872" }, { "input": "8 6 4\n1 2\n1 4\n1 8\n1 3\n1 7\n2 6\n2 5", "output": "55" }, { "input": "7 7 3\n3 2\n3 5\n3 7\n1 3\n1 4\n5 6", "output": "36" }, { "input": "70 42 32\n25 50\n51 7\n39 61\n1 33\n20 5\n1 70\n1 63\n42 35\n64 16\n1 11\n39 42\n20 54\n11 14\n57 44\n1 59\n55 40\n25 3\n31 18\n38 68\n57 23\n39 57\n28 10\n39 20\n42 26\n58 6\n20 56\n57 2\n13 21\n15 69\n39 64\n1 39\n62 53\n39 13\n1 41\n22 12\n13 30\n68 67\n20 31\n51 15\n57 32\n59 34\n39 4\n31 65\n58 24\n20 55\n15 27\n25 46\n20 22\n57 49\n68 52\n39 8\n54 58\n39 28\n13 48\n15 43\n25 66\n1 29\n15 37\n31 60\n1 19\n62 38\n39 17\n64 36\n59 25\n57 45\n57 9\n11 62\n20 51\n54 47", "output": "4827" }, { "input": "13 5 13\n2 5\n5 8\n1 2\n13 7\n2 3\n1 13\n13 11\n13 4\n10 6\n10 12\n7 9\n1 10", "output": "146" }, { "input": "72 16 5\n1 20\n8 4\n23 19\n16 63\n45 65\n27 67\n58 21\n36 17\n20 52\n1 71\n8 59\n20 26\n28 16\n23 3\n45 42\n61 51\n6 31\n1 15\n1 11\n6 62\n43 60\n20 27\n20 32\n1 8\n68 25\n1 57\n20 70\n1 64\n1 13\n8 18\n8 46\n28 49\n8 39\n64 58\n28 47\n27 14\n8 10\n11 53\n1 24\n28 2\n72 30\n36 29\n1 45\n24 23\n1 72\n46 61\n45 56\n72 35\n11 50\n8 55\n8 28\n1 38\n61 41\n1 44\n61 40\n27 33\n72 69\n46 36\n43 66\n61 22\n45 5\n27 43\n46 12\n1 7\n16 68\n1 6\n1 9\n45 37\n27 34\n8 54\n20 48", "output": "5108" }, { "input": "2 1 2\n1 2", "output": "1" }, { "input": "2 1 2\n2 1", "output": "1" } ]
1,528,091,861
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
51,916,800
n,x,y=[int(x)for x in input().split()] adj=[[]for i in range(n+1)] for i in range(n-1): a,b = [int(x) for x in input().split()] adj[a].append(b) adj[b].append(a) v=[0]*(n+1) ph=[] def dfs(i=x): ph.append(i) if i==y: return True v[i]=1 for ss in adj[i]: if v[ss]==0: if dfs(ss): return True ph.pop() return False dfs() # print(ph) def get_num(r,ex): visit=[0]*(n+1) visit[ex]=1 visit[r]=1 next=[r] i=0 while i<len(next): for ss in adj[next[i]]: if visit[ss]==0: next.append(ss) visit[ss]=1 i+=1 return len(next) xx=get_num(x,ph[1]) yy=get_num(y,ph[-2]) print(n*n-n-xx*yy)
Title: Kuro and Walking Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$). Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him. Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem. Input Specification: The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree. Output Specification: A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route. Demo Input: ['3 1 3\n1 2\n2 3\n', '3 1 3\n1 2\n1 3\n'] Demo Output: ['5', '4'] Note: On the first example, Kuro can choose these pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$. Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order). On the second example, Kuro can choose the following pairs: - $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$.
```python n,x,y=[int(x)for x in input().split()] adj=[[]for i in range(n+1)] for i in range(n-1): a,b = [int(x) for x in input().split()] adj[a].append(b) adj[b].append(a) v=[0]*(n+1) ph=[] def dfs(i=x): ph.append(i) if i==y: return True v[i]=1 for ss in adj[i]: if v[ss]==0: if dfs(ss): return True ph.pop() return False dfs() # print(ph) def get_num(r,ex): visit=[0]*(n+1) visit[ex]=1 visit[r]=1 next=[r] i=0 while i<len(next): for ss in adj[next[i]]: if visit[ss]==0: next.append(ss) visit[ss]=1 i+=1 return len(next) xx=get_num(x,ph[1]) yy=get_num(y,ph[-2]) print(n*n-n-xx*yy) ```
0
1,008
A
Romaji
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese.
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).
[ "sumimasen\n", "ninja\n", "codeforces\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
500
[ { "input": "sumimasen", "output": "YES" }, { "input": "ninja", "output": "YES" }, { "input": "codeforces", "output": "NO" }, { "input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "output": "YES" }, { "input": "n", "output": "YES" }, { "input": "necnei", "output": "NO" }, { "input": "nternn", "output": "NO" }, { "input": "aucunuohja", "output": "NO" }, { "input": "a", "output": "YES" }, { "input": "b", "output": "NO" }, { "input": "nn", "output": "YES" }, { "input": "nnnzaaa", "output": "YES" }, { "input": "zn", "output": "NO" }, { "input": "ab", "output": "NO" }, { "input": "aaaaaaaaaa", "output": "YES" }, { "input": "aaaaaaaaab", "output": "NO" }, { "input": "aaaaaaaaan", "output": "YES" }, { "input": "baaaaaaaaa", "output": "YES" }, { "input": "naaaaaaaaa", "output": "YES" }, { "input": "nbaaaaaaaa", "output": "YES" }, { "input": "bbaaaaaaaa", "output": "NO" }, { "input": "bnaaaaaaaa", "output": "NO" }, { "input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu", "output": "YES" }, { "input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino", "output": "NO" }, { "input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul", "output": "NO" }, { "input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu", "output": "YES" }, { "input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo", "output": "NO" }, { "input": "y", "output": "NO" }, { "input": "by", "output": "NO" }, { "input": "yy", "output": "NO" }, { "input": "nbn", "output": "NO" }, { "input": "nz", "output": "NO" }, { "input": "king", "output": "NO" }, { "input": "g", "output": "NO" }, { "input": "az", "output": "NO" }, { "input": "x", "output": "NO" }, { "input": "z", "output": "NO" }, { "input": "yn", "output": "NO" }, { "input": "aeo", "output": "YES" }, { "input": "nb", "output": "NO" }, { "input": "npn", "output": "NO" }, { "input": "kini", "output": "YES" }, { "input": "pya", "output": "NO" }, { "input": "m", "output": "NO" }, { "input": "p", "output": "NO" }, { "input": "aaaaaaaak", "output": "NO" }, { "input": "aab", "output": "NO" }, { "input": "d", "output": "NO" }, { "input": "at", "output": "NO" }, { "input": "aaaaaak", "output": "NO" }, { "input": "aaz", "output": "NO" }, { "input": "aaab", "output": "NO" }, { "input": "s", "output": "NO" }, { "input": "nzzen", "output": "NO" }, { "input": "aeionnhhhn", "output": "NO" }, { "input": "h", "output": "NO" }, { "input": "ny", "output": "NO" } ]
1,637,167,506
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
a=input() v='aeioun' l=len(a)-1 count=0 c=False k=0 for i in a: if i in v: k+=1 if k==len(a): print("YES") else: if a[l] in v: for i in range(l): if a[i] not in v: if a[i+1] in v: c=True else: count+=1 if c==True and count==0: print("YES") else: print("NO") else: print("NO")
Title: Romaji Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese. Input Specification: The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. Output Specification: Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower). Demo Input: ['sumimasen\n', 'ninja\n', 'codeforces\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
```python a=input() v='aeioun' l=len(a)-1 count=0 c=False k=0 for i in a: if i in v: k+=1 if k==len(a): print("YES") else: if a[l] in v: for i in range(l): if a[i] not in v: if a[i+1] in v: c=True else: count+=1 if c==True and count==0: print("YES") else: print("NO") else: print("NO") ```
0
409
D
Big Data
PROGRAMMING
1,700
[ "*special" ]
null
null
Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts: - The highest mountain above sea level in the world is Mount Everest. Its peak rises to 8848 m. - The largest board game tournament consisted of 958 participants playing chapaev.- The largest online maths competition consisted of 12766 participants.- The Nile is credited as the longest river in the world. From its farthest stream in Burundi, it extends 6695 km in length.- While not in flood, the main stretches of the Amazon river in South America can reach widths of up to 1100 km at its widest points.- Angel Falls is the highest waterfall. Its greatest single drop measures 807 m.- The Hotel Everest View above Namche, Nepal — the village closest to Everest base camp – is at a record height of 31962 m- Uranium is the heaviest of all the naturally occurring elements. Its most common isotope has a nucleus containing 146 neutrons.- The coldest permanently inhabited place is the Siberian village of Oymyakon, where the temperature of -68°C was registered in the twentieth century.- The longest snake held in captivity is over 25 feet long. Its name is Medusa.- Colonel Meow holds the world record for longest fur on a cat — almost 134 centimeters.- Sea otters can have up to 10000 hairs per square inch. This is the most dense fur in the animal kingdom.- The largest state of USA is Alaska; its area is 663268 square miles- Alaska has a longer coastline than all of the other 49 U.S. States put together: it is 154103 miles long.- Lake Baikal is the largest freshwater lake in the world. It reaches 1642 meters in depth and contains around one-fifth of the world’s unfrozen fresh water.- The most colorful national flag is the one of Turkmenistan, with 106 colors.
The input will contain a single integer between 1 and 16.
Output a single integer.
[ "1\n", "7\n" ]
[ "1\n", "0\n" ]
none
0
[ { "input": "1", "output": "1" }, { "input": "7", "output": "0" }, { "input": "13", "output": "1" }, { "input": "3", "output": "0" }, { "input": "8", "output": "1" }, { "input": "16", "output": "0" }, { "input": "11", "output": "0" }, { "input": "2", "output": "0" }, { "input": "5", "output": "0" }, { "input": "10", "output": "1" }, { "input": "9", "output": "1" }, { "input": "15", "output": "1" }, { "input": "4", "output": "1" }, { "input": "12", "output": "0" }, { "input": "6", "output": "1" }, { "input": "14", "output": "0" } ]
1,622,285,409
2,147,483,647
Python 3
OK
TESTS
16
62
0
print("1001010111001010"[int(input())-1])
Title: Big Data Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts: - The highest mountain above sea level in the world is Mount Everest. Its peak rises to 8848 m. - The largest board game tournament consisted of 958 participants playing chapaev.- The largest online maths competition consisted of 12766 participants.- The Nile is credited as the longest river in the world. From its farthest stream in Burundi, it extends 6695 km in length.- While not in flood, the main stretches of the Amazon river in South America can reach widths of up to 1100 km at its widest points.- Angel Falls is the highest waterfall. Its greatest single drop measures 807 m.- The Hotel Everest View above Namche, Nepal — the village closest to Everest base camp – is at a record height of 31962 m- Uranium is the heaviest of all the naturally occurring elements. Its most common isotope has a nucleus containing 146 neutrons.- The coldest permanently inhabited place is the Siberian village of Oymyakon, where the temperature of -68°C was registered in the twentieth century.- The longest snake held in captivity is over 25 feet long. Its name is Medusa.- Colonel Meow holds the world record for longest fur on a cat — almost 134 centimeters.- Sea otters can have up to 10000 hairs per square inch. This is the most dense fur in the animal kingdom.- The largest state of USA is Alaska; its area is 663268 square miles- Alaska has a longer coastline than all of the other 49 U.S. States put together: it is 154103 miles long.- Lake Baikal is the largest freshwater lake in the world. It reaches 1642 meters in depth and contains around one-fifth of the world’s unfrozen fresh water.- The most colorful national flag is the one of Turkmenistan, with 106 colors. Input Specification: The input will contain a single integer between 1 and 16. Output Specification: Output a single integer. Demo Input: ['1\n', '7\n'] Demo Output: ['1\n', '0\n'] Note: none
```python print("1001010111001010"[int(input())-1]) ```
3
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", "output": "21223442" }, { "input": "91730629", "output": "91230320" }, { "input": "420062703497", "output": "420032203402" }, { "input": "332711047202", "output": "332211042202" }, { "input": "3395184971407775", "output": "3304114021402224" }, { "input": "8464062628894325", "output": "1434032321104324" }, { "input": "164324828731963982", "output": "134324121231033012" }, { "input": "384979173822804784", "output": "314020123122104214" }, { "input": "41312150450968417", "output": "41312140440031412" }, { "input": "2156", "output": "2143" }, { "input": "1932", "output": "1032" }, { "input": "5902", "output": "4002" }, { "input": "5728", "output": "4221" }, { "input": "8537", "output": "1432" }, { "input": "55403857", "output": "44403142" }, { "input": "270739", "output": "220230" }, { "input": "28746918", "output": "21243011" }, { "input": "10279211", "output": "10220211" }, { "input": "40289679", "output": "40210320" }, { "input": "545203238506", "output": "444203231403" }, { "input": "461117063340", "output": "431112033340" }, { "input": "658492686568", "output": "341402313431" }, { "input": "857373361868", "output": "142323331131" }, { "input": "429325660016", "output": "420324330013" }, { "input": "9894448650287940", "output": "9104441340212040" }, { "input": "6354510839296263", "output": "3344410130203233" }, { "input": "6873575462224593", "output": "3123424432224403" }, { "input": "4237951492601449", "output": "4232041402301440" }, { "input": "2680352384836991", "output": "2310342314133001" }, { "input": "606187734191890310", "output": "303112234101100310" }, { "input": "351499943576823355", "output": "341400043423123344" }, { "input": "180593481782177068", "output": "110403411212122031" }, { "input": "999999999999999999", "output": "900000000000000000" }, { "input": "1000000000000000000", "output": "1000000000000000000" }, { "input": "9999", "output": "9000" }, { "input": "99", "output": "90" }, { "input": "9991", "output": "9001" } ]
1,682,724,748
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
x = list(map(int, list(input()))) y = [9-a for a in x] ans = str(x[0]) for i in range(1, len(x)): ans += str(min(x[i], y[i])) print(ans)
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. Input Specification: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. Output Specification: Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. Demo Input: ['27\n', '4545\n'] Demo Output: ['22\n', '4444\n'] Note: none
```python x = list(map(int, list(input()))) y = [9-a for a in x] ans = str(x[0]) for i in range(1, len(x)): ans += str(min(x[i], y[i])) print(ans) ```
0
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" }, { "input": "lwzjp\ninjit", "output": "-1" }, { "input": "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm", "output": "eodnlemiicdedmkcgavqbnqmm" }, { "input": "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs", "output": "-1" }, { "input": "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf", "output": "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf" }, { "input": "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen", "output": "-1" }, { "input": "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb", "output": "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb" }, { "input": "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym", "output": "-1" }, { "input": "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib", "output": "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib" }, { "input": "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew", "output": "-1" }, { "input": "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv", "output": "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv" }, { "input": "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns", "output": "-1" }, { "input": "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf", "output": "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf" }, { "input": "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp", "output": "-1" }, { "input": "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp", "output": "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp" }, { "input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej", "output": "-1" }, { "input": "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe", "output": "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe" }, { "input": "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang", "output": "-1" }, { "input": "ftfr\nftfr", "output": "ftfr" }, { "input": "ftr\nftr", "output": "ftr" }, { "input": "shftr\nshftr", "output": "shftr" }, { "input": "vkvkkv\nvkvkkv", "output": "vkvkkv" }, { "input": "ftrd\nftrd", "output": "ftrd" }, { "input": "fztr\nfztr", "output": "fztr" }, { "input": "frtr\nfrtr", "output": "frtr" }, { "input": "shdftr\nshdftr", "output": "shdftr" }, { "input": "zzz\nzzz", "output": "zzz" }, { "input": "shtr\nshtr", "output": "shtr" }, { "input": "aaaaa\nzzzzz", "output": "-1" }, { "input": "efr\nefr", "output": "efr" } ]
1,616,514,367
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
108
0
try: x = input() z = input() y = "" v = True for i in range(len(x)): if ascii(x[i]) < ascii(z[i]): print(-1) v = False else: y = y + z[i] if v: print(y) except: pass
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. Input Specification: The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. Output Specification: If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. Demo Input: ['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n'] Demo Output: ['ba\n', 'xiyez\n', '-1\n'] Note: The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
```python try: x = input() z = input() y = "" v = True for i in range(len(x)): if ascii(x[i]) < ascii(z[i]): print(-1) v = False else: y = y + z[i] if v: print(y) except: pass ```
0
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer — the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { "input": "2 6 4 5 6 5 1 3", "output": "0" }, { "input": "1 7 3 5 3 6 2 1", "output": "6" }, { "input": "2 4 5 4 5 7 3 2", "output": "1" }, { "input": "2 3 6 5 7 8 2 1", "output": "4" }, { "input": "1 4 5 5 3 10 3 1", "output": "6" }, { "input": "1 4 6 7 3 5 1 3", "output": "1" }, { "input": "1 6 5 5 5 8 3 1", "output": "8" }, { "input": "1 7 5 3 3 9 2 1", "output": "9" }, { "input": "3 5 3 7 6 10 3 1", "output": "1" }, { "input": "3 6 3 5 3 6 3 1", "output": "2" }, { "input": "1 7 5 5 5 5 2 2", "output": "2" }, { "input": "2 5 3 5 6 9 2 1", "output": "3" }, { "input": "3 4 3 5 3 6 2 1", "output": "2" }, { "input": "1 5 5 4 7 6 3 1", "output": "6" }, { "input": "2 3 7 6 5 9 3 1", "output": "3" }, { "input": "2 6 5 3 3 8 1 1", "output": "4" }, { "input": "2 4 7 3 4 10 2 1", "output": "5" }, { "input": "1 1000 1000 1000 1000 1000 1 1", "output": "1000" }, { "input": "17 1000 1000 1000 1000 1000 3 7", "output": "8" }, { "input": "115 1000 1000 1000 1000 1000 17 15", "output": "0" }, { "input": "1 587 981 1 2 1 1 1", "output": "1" }, { "input": "1 1 2 1 2 2 1 1", "output": "2" } ]
1,684,320,878
2,147,483,647
Python 3
OK
TESTS
27
92
0
a,b,c,d,e,f,g,h=map(int,input().split()) q=b*c w=q//g e=d*e r=f//h print(int(min(w,e,r)/a))
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? Input Specification: The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. Output Specification: Print a single integer — the number of toasts each friend can make. Demo Input: ['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n'] Demo Output: ['2\n', '3\n', '0\n'] Note: A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
```python a,b,c,d,e,f,g,h=map(int,input().split()) q=b*c w=q//g e=d*e r=f//h print(int(min(w,e,r)/a)) ```
3
722
A
Broken Clock
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format. For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
[ "24\n17:30\n", "12\n17:30\n", "24\n99:99\n" ]
[ "17:30\n", "07:30\n", "09:09\n" ]
none
500
[ { "input": "24\n17:30", "output": "17:30" }, { "input": "12\n17:30", "output": "07:30" }, { "input": "24\n99:99", "output": "09:09" }, { "input": "12\n05:54", "output": "05:54" }, { "input": "12\n00:05", "output": "01:05" }, { "input": "24\n23:80", "output": "23:00" }, { "input": "24\n73:16", "output": "03:16" }, { "input": "12\n03:77", "output": "03:07" }, { "input": "12\n47:83", "output": "07:03" }, { "input": "24\n23:88", "output": "23:08" }, { "input": "24\n51:67", "output": "01:07" }, { "input": "12\n10:33", "output": "10:33" }, { "input": "12\n00:01", "output": "01:01" }, { "input": "12\n07:74", "output": "07:04" }, { "input": "12\n00:60", "output": "01:00" }, { "input": "24\n08:32", "output": "08:32" }, { "input": "24\n42:59", "output": "02:59" }, { "input": "24\n19:87", "output": "19:07" }, { "input": "24\n26:98", "output": "06:08" }, { "input": "12\n12:91", "output": "12:01" }, { "input": "12\n11:30", "output": "11:30" }, { "input": "12\n90:32", "output": "10:32" }, { "input": "12\n03:69", "output": "03:09" }, { "input": "12\n33:83", "output": "03:03" }, { "input": "24\n10:45", "output": "10:45" }, { "input": "24\n65:12", "output": "05:12" }, { "input": "24\n22:64", "output": "22:04" }, { "input": "24\n48:91", "output": "08:01" }, { "input": "12\n02:51", "output": "02:51" }, { "input": "12\n40:11", "output": "10:11" }, { "input": "12\n02:86", "output": "02:06" }, { "input": "12\n99:96", "output": "09:06" }, { "input": "24\n19:24", "output": "19:24" }, { "input": "24\n55:49", "output": "05:49" }, { "input": "24\n01:97", "output": "01:07" }, { "input": "24\n39:68", "output": "09:08" }, { "input": "24\n24:00", "output": "04:00" }, { "input": "12\n91:00", "output": "01:00" }, { "input": "24\n00:30", "output": "00:30" }, { "input": "12\n13:20", "output": "03:20" }, { "input": "12\n13:00", "output": "03:00" }, { "input": "12\n42:35", "output": "02:35" }, { "input": "12\n20:00", "output": "10:00" }, { "input": "12\n21:00", "output": "01:00" }, { "input": "24\n10:10", "output": "10:10" }, { "input": "24\n30:40", "output": "00:40" }, { "input": "24\n12:00", "output": "12:00" }, { "input": "12\n10:60", "output": "10:00" }, { "input": "24\n30:00", "output": "00:00" }, { "input": "24\n34:00", "output": "04:00" }, { "input": "12\n22:00", "output": "02:00" }, { "input": "12\n20:20", "output": "10:20" } ]
1,475,334,021
3,321
Python 3
WRONG_ANSWER
PRETESTS
0
30
0
mode = int(input()) time = input() i = 0 h = 0 m = 0 while(time[i] != ':'): h = h * 10 + int(time[i]) i += 1 i += 1 while(i < 4): m = m * 10 + int(time[i]) i += 1 if(mode == 24): if(not(0 <= h <= 23)): h %= 10 if(not(0 <= m <= 59)): m %= 10 if(mode == 12): if(not(1 <= h <= 12)): h %= 10 if(not(0 <= m <= 59)): m %= 10 print(h // 10, h % 10, ':', m // 10, m % 10, sep='')
Title: Broken Clock Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format. For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39. Input Specification: The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes. Output Specification: The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them. Demo Input: ['24\n17:30\n', '12\n17:30\n', '24\n99:99\n'] Demo Output: ['17:30\n', '07:30\n', '09:09\n'] Note: none
```python mode = int(input()) time = input() i = 0 h = 0 m = 0 while(time[i] != ':'): h = h * 10 + int(time[i]) i += 1 i += 1 while(i < 4): m = m * 10 + int(time[i]) i += 1 if(mode == 24): if(not(0 <= h <= 23)): h %= 10 if(not(0 <= m <= 59)): m %= 10 if(mode == 12): if(not(1 <= h <= 12)): h %= 10 if(not(0 <= m <= 59)): m %= 10 print(h // 10, h % 10, ':', m // 10, m % 10, sep='') ```
0
873
B
Balanced Substring
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of *s*.
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
[ "8\n11010111\n", "3\n111\n" ]
[ "4\n", "0\n" ]
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
0
[ { "input": "8\n11010111", "output": "4" }, { "input": "3\n111", "output": "0" }, { "input": "11\n00001000100", "output": "2" }, { "input": "10\n0100000000", "output": "2" }, { "input": "13\n0001000011010", "output": "6" }, { "input": "14\n00000100101011", "output": "10" }, { "input": "14\n01111101111111", "output": "2" }, { "input": "18\n110010101101111111", "output": "10" }, { "input": "11\n00010000011", "output": "4" }, { "input": "10\n1000010110", "output": "6" }, { "input": "15\n100000100000011", "output": "4" }, { "input": "18\n011010101110111101", "output": "8" }, { "input": "10\n0011011111", "output": "6" }, { "input": "3\n011", "output": "2" }, { "input": "14\n11111111111111", "output": "0" }, { "input": "65\n11001000110001001011011110111100000000101001001010101111000100010", "output": "48" }, { "input": "10\n0011111000", "output": "10" }, { "input": "13\n1110000001110", "output": "12" }, { "input": "3\n110", "output": "2" }, { "input": "4\n1110", "output": "2" }, { "input": "9\n001011001", "output": "8" }, { "input": "2\n10", "output": "2" }, { "input": "2\n01", "output": "2" }, { "input": "12\n110000110000", "output": "8" }, { "input": "3\n001", "output": "2" }, { "input": "14\n11000011000000", "output": "8" }, { "input": "19\n0000011111111100000", "output": "18" }, { "input": "45\n011010001100001111110001011100000001101100111", "output": "44" }, { "input": "18\n000001111111100000", "output": "16" }, { "input": "4\n0101", "output": "4" }, { "input": "12\n000101011001", "output": "10" } ]
1,511,419,209
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
n = int(input()) a = list(input()) s1 = [] s2 = [] for i in range(n): a[i] = int(a[i]) if a[i] == 0: a[i] = -1 s = 0 for i in range(n-1 ): s += a[i] if i % 2 == 1: s1.append(s) else: s2.append(s) r = 0 rmax = 0 for i in range(len(s1)-1): if s1[i] == s1[i+1]: r += 1 if r >= rmax: rmax = r else: r = 0 r = 0 for i in range(len(s1)-1): if s2[i] == s2[i+1]: r += 1 if r >= rmax: rmax = r else: r = 0 print(rmax*2)
Title: Balanced Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of *s*. Input Specification: The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. Output Specification: If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. Demo Input: ['8\n11010111\n', '3\n111\n'] Demo Output: ['4\n', '0\n'] Note: In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
```python n = int(input()) a = list(input()) s1 = [] s2 = [] for i in range(n): a[i] = int(a[i]) if a[i] == 0: a[i] = -1 s = 0 for i in range(n-1 ): s += a[i] if i % 2 == 1: s1.append(s) else: s2.append(s) r = 0 rmax = 0 for i in range(len(s1)-1): if s1[i] == s1[i+1]: r += 1 if r >= rmax: rmax = r else: r = 0 r = 0 for i in range(len(s1)-1): if s2[i] == s2[i+1]: r += 1 if r >= rmax: rmax = r else: r = 0 print(rmax*2) ```
0
1,009
A
Game Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy every game in that order. When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop. Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game. For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 &gt; a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$. Your task is to get the number of games Maxim will buy.
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet.
Print a single integer — the number of games Maxim will buy.
[ "5 4\n2 4 5 2 4\n5 3 4 6\n", "5 2\n20 40 50 20 40\n19 20\n", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n" ]
[ "3\n", "0\n", "4\n" ]
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
0
[ { "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3" }, { "input": "5 2\n20 40 50 20 40\n19 20", "output": "0" }, { "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4" }, { "input": "5 1\n1 1 1 1 1\n5", "output": "1" }, { "input": "5 1\n10 1 1 1 1\n1000", "output": "1" }, { "input": "5 1\n100 100 100 100 100\n100", "output": "1" }, { "input": "2 1\n2 1\n1", "output": "1" }, { "input": "2 3\n3 1\n2 4 2", "output": "1" }, { "input": "1 5\n4\n1 4 3 3 2", "output": "0" }, { "input": "5 3\n4 2 3 1 1\n2 1 3", "output": "3" }, { "input": "3 5\n5 2 5\n1 4 1 4 2", "output": "0" }, { "input": "7 3\n9 7 10 2 1 1 1\n8 9 6", "output": "3" }, { "input": "5 3\n2 5 3 3 2\n2 5 3", "output": "3" } ]
1,547,913,598
2,147,483,647
Python 3
OK
TESTS
19
109
0
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) zero1 = 0 ; zero2 = 0 for i in a: if zero2 < m and i <= b[zero2]: zero1 += 1 ; zero2 += 1 print(zero1)
Title: Game Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy every game in that order. When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop. Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game. For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 &gt; a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$. Your task is to get the number of games Maxim will buy. Input Specification: The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. Output Specification: Print a single integer — the number of games Maxim will buy. Demo Input: ['5 4\n2 4 5 2 4\n5 3 4 6\n', '5 2\n20 40 50 20 40\n19 20\n', '6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n'] Demo Output: ['3\n', '0\n', '4\n'] Note: The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
```python n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) zero1 = 0 ; zero2 = 0 for i in a: if zero2 < m and i <= b[zero2]: zero1 += 1 ; zero2 += 1 print(zero1) ```
3
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, { "input": "8 8 1 1 1", "output": "Second" }, { "input": "15 14 32 65 28", "output": "First" }, { "input": "894 197 325 232 902", "output": "First" }, { "input": "1 2 8 8 5", "output": "Friendship" }, { "input": "37 261 207 1 1000", "output": "Friendship" }, { "input": "29 344 406 900 1", "output": "Friendship" }, { "input": "1 2 8 9 8", "output": "First" }, { "input": "2 9 8 8 9", "output": "Friendship" }, { "input": "213 480 811 134 745", "output": "First" }, { "input": "2 313 856 964 421", "output": "Friendship" }, { "input": "1 10 2 6 10", "output": "Friendship" }, { "input": "2 7 6 2 3", "output": "Friendship" }, { "input": "637 324 69 612 998", "output": "Second" }, { "input": "13 849 819 723 918", "output": "Friendship" }, { "input": "9 5 7 8 7", "output": "First" }, { "input": "6 5 7 10 4", "output": "Friendship" }, { "input": "61 464 623 89 548", "output": "First" }, { "input": "641 31 29 161 802", "output": "Friendship" }, { "input": "3 3 1 6 9", "output": "Friendship" }, { "input": "2 3 9 8 2", "output": "Friendship" }, { "input": "485 117 368 567 609", "output": "First" }, { "input": "4 202 512 995 375", "output": "Friendship" }, { "input": "424 41 41 909 909", "output": "Friendship" }, { "input": "884 913 263 641 265", "output": "Second" }, { "input": "12 462 8 311 327", "output": "Second" }, { "input": "436 306 266 493 580", "output": "Second" }, { "input": "69 1 2 1 2", "output": "First" } ]
1,628,969,138
2,147,483,647
PyPy 3
OK
TESTS
32
108
20,172,800
from sys import stdin, stdout def read(): return stdin.readline().rstrip() def read_int(): return int(read()) def read_ints(): return list(map(int, read().split())) def solve(): s,v1,v2,t1,t2 = read_ints() if v1*s+2*t1 < v2*s+2*t2: print("First") elif v1*s+2*t1 > v2*s+2*t2: print("Second") else: print("Friendship") solve()
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python from sys import stdin, stdout def read(): return stdin.readline().rstrip() def read_int(): return int(read()) def read_ints(): return list(map(int, read().split())) def solve(): s,v1,v2,t1,t2 = read_ints() if v1*s+2*t1 < v2*s+2*t2: print("First") elif v1*s+2*t1 > v2*s+2*t2: print("Second") else: print("Friendship") solve() ```
3
560
A
Currency System in Geraldion
PROGRAMMING
1,000
[ "implementation", "sortings" ]
null
null
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum?
The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion. The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1.
[ "5\n1 2 3 4 5\n" ]
[ "-1\n" ]
none
500
[ { "input": "5\n1 2 3 4 5", "output": "-1" }, { "input": "1\n2", "output": "1" }, { "input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837", "output": "-1" }, { "input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264", "output": "1" }, { "input": "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97866 124255 950067 697612 244256 782385 789882 37608 82153 399889 598867 416717 377988 535636 511221 792568 683271 131077 290194 496712 330720 587436 563481 645817 942562 654093 980561 382937 48293 582608 116156", "output": "-1" }, { "input": "50\n474421 421097 217233 156339 27075 733996 281778 863492 184707 956857 288561 70997 393786 337382 663642 131184 637 273801 799870 295017 392338 842567 161819 297705 102013 930684 375703 838048 154915 138503 629056 256591 893619 19263 787927 684541 320265 841090 421423 490879 394582 493952 619247 633202 612928 50907 276653 407819 489945 153173", "output": "1" }, { "input": "1\n1", "output": "-1" }, { "input": "1\n1000000", "output": "1" }, { "input": "2\n3 2", "output": "1" }, { "input": "2\n2 3", "output": "1" } ]
1,439,450,701
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
11
77
3,993,600
def prost(n): a = 2 while n % a != 0 and n**0.5 > a : a += 1 if n % a == 0 and n != 2: return 0 else: return 1 n = int(input()) ai = list(map(int,input().split())) nums = [0]*1000000 answer = -1 for i in range(n): nums[ai[i]] = 1 if nums[1] != 1: answer = 1 print(answer)
Title: Currency System in Geraldion Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum? Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion. The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. Output Specification: Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. Demo Input: ['5\n1 2 3 4 5\n'] Demo Output: ['-1\n'] Note: none
```python def prost(n): a = 2 while n % a != 0 and n**0.5 > a : a += 1 if n % a == 0 and n != 2: return 0 else: return 1 n = int(input()) ai = list(map(int,input().split())) nums = [0]*1000000 answer = -1 for i in range(n): nums[ai[i]] = 1 if nums[1] != 1: answer = 1 print(answer) ```
-1
26
B
Regular Bracket Sequence
PROGRAMMING
1,400
[ "greedy" ]
B. Regular Bracket Sequence
5
256
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output the maximum possible length of a regular bracket sequence.
[ "(()))(\n", "((()())\n" ]
[ "4\n", "6\n" ]
none
1,000
[ { "input": "(()))(", "output": "4" }, { "input": "((()())", "output": "6" }, { "input": "(", "output": "0" }, { "input": ")", "output": "0" }, { "input": ")(()(", "output": "2" }, { "input": "))))))(", "output": "0" }, { "input": "()()(()(((", "output": "6" }, { "input": "()))(()((((()(())", "output": "10" }, { "input": "())))((()())())))))())", "output": "14" }, { "input": ")))((((())(()((()((((()()())((", "output": "16" }, { "input": "))()()((()()))())()(((((((())((((((((())()()((())(", "output": "32" }, { "input": "))())))))))())))))()()))()()))))())))))()))))))))))))(()))())(()))))(()))))())))((((()()))))()))()))", "output": "48" } ]
1,679,224,950
2,147,483,647
Python 3
OK
TESTS
38
872
6,144,000
x = list(input()) c1 = 0 c2 = 0 for i in range(len(x)): if x[-1] == "(" and c1 == 0: x.pop() elif x[-1] == ")": x.pop() c1+=1 else: x.pop() c1-=1 c2+=2 print(c2)
Title: Regular Bracket Sequence Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained? Input Specification: Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. Output Specification: Output the maximum possible length of a regular bracket sequence. Demo Input: ['(()))(\n', '((()())\n'] Demo Output: ['4\n', '6\n'] Note: none
```python x = list(input()) c1 = 0 c2 = 0 for i in range(len(x)): if x[-1] == "(" and c1 == 0: x.pop() elif x[-1] == ")": x.pop() c1+=1 else: x.pop() c1-=1 c2+=2 print(c2) ```
3.901356
437
C
The Child and Toy
PROGRAMMING
1,400
[ "graphs", "greedy", "sortings" ]
null
null
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part *i* as *v**i*. The child spend *v**f*1<=+<=*v**f*2<=+<=...<=+<=*v**f**k* energy for removing part *i* where *f*1,<=*f*2,<=...,<=*f**k* are the parts that are directly connected to the *i*-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all *n* parts.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*; *x**i*<=≠<=*y**i*). Consider all the parts are numbered from 1 to *n*.
Output the minimum total energy the child should spend to remove all *n* parts of the toy.
[ "4 3\n10 20 30 40\n1 4\n1 2\n2 3\n", "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n", "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n" ]
[ "40\n", "400\n", "160\n" ]
One of the optimal sequence of actions in the first sample is: - First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
1,500
[ { "input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3", "output": "40" }, { "input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4", "output": "400" }, { "input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4", "output": "160" }, { "input": "1 0\n23333", "output": "0" }, { "input": "5 4\n1 2 2 2 2\n1 2\n1 3\n1 4\n1 5", "output": "4" }, { "input": "10 30\n3 6 17 15 13 15 6 12 9 1\n3 8\n1 10\n4 7\n1 7\n3 7\n2 9\n8 10\n3 1\n3 4\n8 6\n10 3\n3 9\n2 3\n10 4\n2 10\n5 8\n9 5\n6 1\n2 1\n7 2\n7 6\n7 10\n4 8\n5 6\n3 6\n4 1\n8 9\n7 9\n4 2\n5 10", "output": "188" }, { "input": "3 3\n1 1 1\n1 2\n2 3\n3 1", "output": "3" } ]
1,640,872,503
2,147,483,647
Python 3
OK
TESTS
29
62
102,400
from collections import defaultdict n,m = map(int,input().split()) A = list(map(int,input().split())) d = defaultdict(list) ans = 0 for i in range(m): a,b = map(int,input().split()) ans += min(A[a-1],A[b-1]) print(ans)
Title: The Child and Toy Time Limit: None seconds Memory Limit: None megabytes Problem Description: On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part *i* as *v**i*. The child spend *v**f*1<=+<=*v**f*2<=+<=...<=+<=*v**f**k* energy for removing part *i* where *f*1,<=*f*2,<=...,<=*f**k* are the parts that are directly connected to the *i*-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all *n* parts. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*; *x**i*<=≠<=*y**i*). Consider all the parts are numbered from 1 to *n*. Output Specification: Output the minimum total energy the child should spend to remove all *n* parts of the toy. Demo Input: ['4 3\n10 20 30 40\n1 4\n1 2\n2 3\n', '4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n', '7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n'] Demo Output: ['40\n', '400\n', '160\n'] Note: One of the optimal sequence of actions in the first sample is: - First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
```python from collections import defaultdict n,m = map(int,input().split()) A = list(map(int,input().split())) d = defaultdict(list) ans = 0 for i in range(m): a,b = map(int,input().split()) ans += min(A[a-1],A[b-1]) print(ans) ```
3
626
E
Simple Skewness
PROGRAMMING
2,400
[ "binary search", "math", "ternary search" ]
null
null
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of *n* (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200 000) — the number of elements in the list. The second line contains *n* integers *x**i* (0<=≤<=*x**i*<=≤<=1<=000<=000) — the *i*th element of the list.
In the first line, print a single integer *k* — the size of the subset. In the second line, print *k* integers — the elements of the subset in any order. If there are multiple optimal subsets, print any.
[ "4\n1 2 3 12\n", "4\n1 1 2 2\n", "2\n1 2\n" ]
[ "3\n1 2 12 \n", "3\n1 1 2 \n", "2\n1 2\n" ]
In the first case, the optimal subset is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/04cdbd07a0375de9c557422eca077386392a9349.png" style="max-width: 100.0%;max-height: 100.0%;"/>, which has mean 5, median 2, and simple skewness of 5 - 2 = 3. In the second case, the optimal subset is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/af49670de7c27def20edf0ec421d9bb17d904c94.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that repetition is allowed. In the last case, any subset has the same median and mean, so all have simple skewness of 0.
2,000
[ { "input": "4\n1 2 3 12", "output": "3\n1 2 12 " }, { "input": "4\n1 1 2 2", "output": "3\n1 1 2 " }, { "input": "2\n1 2", "output": "2\n1 2" }, { "input": "1\n1000000", "output": "1\n1000000 " }, { "input": "20\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 983616 967232 934464 868928 737856 475712", "output": "1\n475712 " }, { "input": "21\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 983616 967232 934464 868928 737856 475712 1000000", "output": "1\n475712 " }, { "input": "40\n999999 999999 999998 999998 999996 999996 999992 999992 999984 999984 999968 999968 999936 999936 999872 999872 999744 999744 999488 999488 998976 998976 997952 997952 995904 995904 991808 991808 983616 983616 967232 967232 934464 934464 868928 868928 737856 737856 475712 0", "output": "3\n737856 737856 999999 " }, { "input": "1\n534166", "output": "1\n534166 " }, { "input": "1\n412237", "output": "1\n412237 " }, { "input": "1\n253309", "output": "1\n253309 " }, { "input": "1\n94381", "output": "1\n94381 " }, { "input": "1\n935454", "output": "1\n935454 " }, { "input": "2\n847420 569122", "output": "2\n847420 569122" }, { "input": "2\n725491 635622", "output": "2\n725491 635622" }, { "input": "2\n566563 590441", "output": "2\n566563 590441" }, { "input": "2\n407635 619942", "output": "2\n407635 619942" }, { "input": "2\n248707 649443", "output": "2\n248707 649443" }, { "input": "3\n198356 154895 894059", "output": "3\n154895 198356 894059 " }, { "input": "3\n76427 184396 963319", "output": "3\n76427 184396 963319 " }, { "input": "3\n880502 176898 958582", "output": "1\n176898 " }, { "input": "3\n758573 206400 991528", "output": "1\n206400 " }, { "input": "3\n599645 198217 986791", "output": "1\n198217 " }, { "input": "4\n549294 703669 96824 126683", "output": "3\n96824 126683 703669 " }, { "input": "4\n390366 733171 92086 595244", "output": "3\n92086 390366 733171 " }, { "input": "4\n231438 762672 125033 26806", "output": "3\n26806 125033 762672 " }, { "input": "4\n109509 792173 120296 495368", "output": "3\n109509 120296 792173 " }, { "input": "4\n950582 784676 190241 964614", "output": "1\n190241 " }, { "input": "5\n900232 289442 225592 622868 113587", "output": "3\n113587 225592 900232 " }, { "input": "5\n741304 281944 258539 54430 284591", "output": "3\n281944 284591 741304 " }, { "input": "5\n582376 311446 253801 560676 530279", "output": "3\n253801 311446 582376 " }, { "input": "5\n460447 303948 286063 992238 738282", "output": "3\n286063 303948 992238 " }, { "input": "5\n301519 370449 319010 460799 983970", "output": "3\n301519 319010 983970 " }, { "input": "21\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 983616 967232 934464 868928 737856 475712 999998", "output": "3\n999998 999998 999999 " } ]
1,644,314,034
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
30
0
n = int(input()) array = list(map(int,input().split())) array.sort() dataarray = [] skewness = [] for i in range(1, n): temparray = [] temparray.append(array[i]) for j in range(min(i, len(array)-i)): if sum(temparray)/len(temparray) < (array[i-j-1]+array[-1-j])/2: temparray.insert(0,array[i-j-1]) temparray.append(array[-1-j]) if j == min(i, len(array)-i)-1: skewness.append((sum(temparray)/len(temparray))-array[i]) dataarray.append(temparray) else: skewness.append((sum(temparray) / len(temparray)) - array[i]) dataarray.append(temparray) break print(len(dataarray[skewness.index(max(skewness))])) print(" ".join(list(map(str,dataarray[skewness.index(max(skewness))]))))
Title: Simple Skewness Time Limit: None seconds Memory Limit: None megabytes Problem Description: Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of *n* (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200 000) — the number of elements in the list. The second line contains *n* integers *x**i* (0<=≤<=*x**i*<=≤<=1<=000<=000) — the *i*th element of the list. Output Specification: In the first line, print a single integer *k* — the size of the subset. In the second line, print *k* integers — the elements of the subset in any order. If there are multiple optimal subsets, print any. Demo Input: ['4\n1 2 3 12\n', '4\n1 1 2 2\n', '2\n1 2\n'] Demo Output: ['3\n1 2 12 \n', '3\n1 1 2 \n', '2\n1 2\n'] Note: In the first case, the optimal subset is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/04cdbd07a0375de9c557422eca077386392a9349.png" style="max-width: 100.0%;max-height: 100.0%;"/>, which has mean 5, median 2, and simple skewness of 5 - 2 = 3. In the second case, the optimal subset is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/af49670de7c27def20edf0ec421d9bb17d904c94.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that repetition is allowed. In the last case, any subset has the same median and mean, so all have simple skewness of 0.
```python n = int(input()) array = list(map(int,input().split())) array.sort() dataarray = [] skewness = [] for i in range(1, n): temparray = [] temparray.append(array[i]) for j in range(min(i, len(array)-i)): if sum(temparray)/len(temparray) < (array[i-j-1]+array[-1-j])/2: temparray.insert(0,array[i-j-1]) temparray.append(array[-1-j]) if j == min(i, len(array)-i)-1: skewness.append((sum(temparray)/len(temparray))-array[i]) dataarray.append(temparray) else: skewness.append((sum(temparray) / len(temparray)) - array[i]) dataarray.append(temparray) break print(len(dataarray[skewness.index(max(skewness))])) print(" ".join(list(map(str,dataarray[skewness.index(max(skewness))])))) ```
-1
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,679,124,450
2,147,483,647
Python 3
OK
TESTS
40
92
0
#using inclusion exclusion principle def lcm(l): if len(l)==2: for i in range(1,l[0]*l[1]+1): if i%l[0]==0 and i%l[1]==0: return i if len(l)==3: for i in range(1,l[0]*l[1]*l[2]+1): if i%l[0]==0 and i%l[1]==0 and i%l[2]==0: return i if len(l)==4: for i in range(1,l[0]*l[1]*l[2]*l[3]+1): if i%l[0]==0 and i%l[1]==0 and i%l[2]==0 and i%l[3]==0: return i a=int(input()) b=int(input()) c=int(input()) d=int(input()) n=int(input()) lcm_ab=n//lcm([a,b]) lcm_ac=n//lcm([a,c]) lcm_ad=n//lcm([a,d]) lcm_bc=n//lcm([b,c]) lcm_bd=n//lcm([b,d]) lcm_cd=n//lcm([c,d]) lcm_abc=n//lcm([a,b,c]) lcm_abd=n//lcm([a,b,d]) lcm_acd=n//lcm([a,c,d]) lcm_bcd=n//lcm([b,c,d]) lcm_abcd=n//lcm([a,b,c,d]) dragons=(n//a+n//b+n//c+n//d)-(lcm_ab+lcm_ac+lcm_ad+lcm_bc+lcm_bd+lcm_cd)+(lcm_abc+lcm_abd+lcm_acd+lcm_bcd)-lcm_abcd print(dragons) #alternate method but time inefficient '''a=int(input()) b=int(input()) c=int(input()) d=int(input()) n=int(input()) l=[] if a==1 or b==1 or c==1 or d==1: print(n) elif a>n and b>n and c>n and d>n: print(0) else: for i in range(1,n+1): l.append(i) damaged=[] for i in range(1,n+1,a): if i not in damaged: damaged.append(i) for i in range(1,n+1,b): if i not in damaged: damaged.append(i) for i in range(1,n+1,c): if i not in damaged: damaged.append(i) for i in range(1,n+1,d): if i not in damaged: damaged.append(i) print(len(damaged))'''
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 #using inclusion exclusion principle def lcm(l): if len(l)==2: for i in range(1,l[0]*l[1]+1): if i%l[0]==0 and i%l[1]==0: return i if len(l)==3: for i in range(1,l[0]*l[1]*l[2]+1): if i%l[0]==0 and i%l[1]==0 and i%l[2]==0: return i if len(l)==4: for i in range(1,l[0]*l[1]*l[2]*l[3]+1): if i%l[0]==0 and i%l[1]==0 and i%l[2]==0 and i%l[3]==0: return i a=int(input()) b=int(input()) c=int(input()) d=int(input()) n=int(input()) lcm_ab=n//lcm([a,b]) lcm_ac=n//lcm([a,c]) lcm_ad=n//lcm([a,d]) lcm_bc=n//lcm([b,c]) lcm_bd=n//lcm([b,d]) lcm_cd=n//lcm([c,d]) lcm_abc=n//lcm([a,b,c]) lcm_abd=n//lcm([a,b,d]) lcm_acd=n//lcm([a,c,d]) lcm_bcd=n//lcm([b,c,d]) lcm_abcd=n//lcm([a,b,c,d]) dragons=(n//a+n//b+n//c+n//d)-(lcm_ab+lcm_ac+lcm_ad+lcm_bc+lcm_bd+lcm_cd)+(lcm_abc+lcm_abd+lcm_acd+lcm_bcd)-lcm_abcd print(dragons) #alternate method but time inefficient '''a=int(input()) b=int(input()) c=int(input()) d=int(input()) n=int(input()) l=[] if a==1 or b==1 or c==1 or d==1: print(n) elif a>n and b>n and c>n and d>n: print(0) else: for i in range(1,n+1): l.append(i) damaged=[] for i in range(1,n+1,a): if i not in damaged: damaged.append(i) for i in range(1,n+1,b): if i not in damaged: damaged.append(i) for i in range(1,n+1,c): if i not in damaged: damaged.append(i) for i in range(1,n+1,d): if i not in damaged: damaged.append(i) print(len(damaged))''' ```
3
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,694,456,959
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
154
2,252,800
import re x = input() if re.match(r'WUB', x): x = re.sub(r'WUB', ' ', x) c=0 for i in x: if i==' ': c+=1 else: break print(x[c:])
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python import re x = input() if re.match(r'WUB', x): x = re.sub(r'WUB', ' ', x) c=0 for i in x: if i==' ': c+=1 else: break print(x[c:]) ```
0
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,687,615,289
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n=int(input()) list1=list(map(int,input().split())) list1.sort() list1.reverse() jawad=0 yara=0 for x in list1: if list1.index(x)%2!=0: jawad+=x else: yara+=x print(yara,jawad)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python n=int(input()) list1=list(map(int,input().split())) list1.sort() list1.reverse() jawad=0 yara=0 for x in list1: if list1.index(x)%2!=0: jawad+=x else: yara+=x print(yara,jawad) ```
0
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874", "output": "11 9 8 2 2 1 5 5 0 0 1" }, { "input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897", "output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11" }, { "input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9", "output": "1 1 2 2 3 3 4 4 5" }, { "input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1", "output": "1" }, { "input": "5 1\n1 3 3 3 5\n3", "output": "4" }, { "input": "4 5\n1 1 1 4\n1 5 5 4 3", "output": "3 4 4 4 3" }, { "input": "5 4\n0 5 5 5 6\n5 1 6 3", "output": "4 1 5 1" }, { "input": "1 3\n0\n-1 0 1", "output": "0 1 1" }, { "input": "96 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\n1", "output": "96" }, { "input": "7 1\n1 2 3 4 5 6 7\n1", "output": "1" }, { "input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "7 13 7 13 7 13 7 13 7 13 7 13 7" }, { "input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5", "output": "1 2 3 4 5" }, { "input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1", "output": "3 3 3 3 3 3 3 3" }, { "input": "1 1\n-11111\n-5938", "output": "1" }, { "input": "1 1\n1\n400000009", "output": "1" }, { "input": "1 1\n1\n300000009", "output": "1" }, { "input": "1 1\n1\n200000009", "output": "1" }, { "input": "1 1\n1\n200000003", "output": "1" } ]
1,650,817,694
2,147,483,647
Python 3
OK
TESTS
60
623
17,203,200
from bisect import * I=lambda:map(int,input().split()) I() l=sorted(I()) for e in I():print(bisect_right(l,e),end=' ')
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). Output Specification: Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. Demo Input: ['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n'] Demo Output: ['3 2 1 4\n', '4 2 4 2 5\n'] Note: none
```python from bisect import * I=lambda:map(int,input().split()) I() l=sorted(I()) for e in I():print(bisect_right(l,e),end=' ') ```
3
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,621,341,220
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
1,536,000
n, k = list(map(int, input().split())) b = 10**k l = max(n,b) s = min(n,b) i = l while True: if i%s == 0: print(i) break else: i += l
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python n, k = list(map(int, input().split())) b = 10**k l = max(n,b) s = min(n,b) i = l while True: if i%s == 0: print(i) break else: i += l ```
0
10
D
LCIS
PROGRAMMING
2,800
[ "dp" ]
D. LCIS
1
256
This problem differs from one which was on the online contest. The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=&lt;<=*a**i*<=+<=1 for *i*<=&lt;<=*n*. The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of indexes 1<=≤<=*i*1<=&lt;<=*i*2<=&lt;<=...<=&lt;<=*i**k*<=≤<=*n* that *a**i**j*<==<=*s**j*. In other words, the sequence *s* can be derived from the sequence *a* by crossing out some elements. You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=500) — the length of the first sequence. The second line contains *n* space-separated integers from the range [0,<=109] — elements of the first sequence. The third line contains an integer *m* (1<=≤<=*m*<=≤<=500) — the length of the second sequence. The fourth line contains *m* space-separated integers from the range [0,<=109] — elements of the second sequence.
In the first line output *k* — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.
[ "7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n", "5\n1 2 0 2 1\n3\n1 0 1\n" ]
[ "3\n3 5 6 \n", "2\n0 1 \n" ]
none
0
[ { "input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "output": "3\n3 5 6 " }, { "input": "5\n1 2 0 2 1\n3\n1 0 1", "output": "2\n0 1 " }, { "input": "2\n6 10\n3\n6 3 3", "output": "1\n6 " }, { "input": "1\n7\n2\n7 9", "output": "1\n7 " }, { "input": "3\n37 49 24\n3\n33 5 70", "output": "0" }, { "input": "10\n7 10 1 2 1 7 1 5 9 9\n9\n6 2 5 6 7 7 5 5 2", "output": "2\n2 7 " }, { "input": "9\n7 0 1 2 6 0 10 3 5\n4\n8 4 0 3", "output": "2\n0 3 " }, { "input": "9\n7 4 4 5 0 6 5 4 10\n4\n5 2 10 9", "output": "2\n5 10 " }, { "input": "8\n7 8 6 6 8 10 3 3\n5\n7 4 10 8 7", "output": "2\n7 8 " }, { "input": "7\n4 2 4 3 10 3 6\n9\n7 5 2 3 0 1 6 1 4", "output": "3\n2 3 6 " }, { "input": "1\n7\n10\n1 8 8 10 9 10 4 6 0 5", "output": "0" }, { "input": "2\n5 2\n4\n8 8 0 4", "output": "0" }, { "input": "3\n1 3 9\n10\n8 0 10 5 7 0 3 1 2 4", "output": "1\n1 " }, { "input": "15\n10 4 7 7 10 1 4 9 1 10 9 6 8 8 2\n2\n0 4", "output": "1\n4 " }, { "input": "16\n8 8 6 7 10 0 10 1 7 6 6 0 4 2 6 7\n12\n9 3 8 4 10 3 9 8 3 7 10 4", "output": "2\n8 10 " }, { "input": "23\n174 172 196 135 91 174 208 92 132 53 202 118 5 244 161 140 71 21 185 56 60 195 217\n17\n38 218 120 77 22 214 164 194 79 195 36 167 42 89 201 80 11", "output": "1\n195 " }, { "input": "53\n135 168 160 123 6 250 251 158 245 184 206 35 189 64 138 12 69 21 112 198 165 211 109 40 192 98 236 216 255 98 136 38 67 79 25 196 216 64 134 124 102 232 229 102 179 138 111 123 2 93 25 162 57\n57\n64 143 41 144 73 26 11 17 224 209 167 162 129 39 102 224 254 45 120 2 138 213 139 133 169 54 7 143 242 118 155 189 100 185 145 168 248 131 83 216 142 180 225 35 226 202 8 15 200 192 75 140 191 189 75 116 202", "output": "3\n64 138 192 " }, { "input": "83\n95 164 123 111 177 71 38 225 103 59 210 209 117 139 115 140 66 21 39 84 14 227 0 43 90 233 96 98 232 237 108 139 55 220 14 225 134 39 68 167 193 125 86 216 87 14 94 75 255 24 165 98 177 191 239 123 98 90 29 52 155 231 187 90 180 1 31 237 167 145 242 115 61 190 47 41 61 206 191 248 126 196 26\n49\n234 134 9 207 37 95 116 239 105 197 191 15 151 249 156 235 17 161 197 199 87 78 191 188 44 151 179 238 72 29 228 157 174 99 190 114 95 185 160 168 58 216 131 151 233 204 213 87 76", "output": "2\n95 233 " }, { "input": "13\n55 160 86 99 92 148 81 36 216 191 214 127 44\n85\n92 12 64 21 221 225 119 243 147 47 244 112 212 237 209 121 81 239 43 104 3 254 52 13 1 210 28 18 199 75 251 146 77 28 253 211 50 35 42 160 157 104 155 37 241 78 42 190 150 228 193 96 190 178 232 65 231 186 1 123 212 126 239 22 214 186 245 249 66 234 57 78 173 229 185 23 240 91 127 177 240 105 77 208 86", "output": "2\n160 214 " }, { "input": "94\n100 161 99 102 209 51 5 188 217 53 121 5 233 55 25 156 136 195 243 157 110 202 136 151 86 171 253 38 126 40 27 76 60 119 222 52 134 104 184 146 133 220 88 108 246 61 215 184 181 134 223 164 41 193 232 217 38 192 226 91 81 99 204 232 178 4 187 61 160 255 121 142 191 114 114 181 226 49 86 55 252 169 59 190 246 93 21 22 17 18 120 88 93 144\n30\n61 51 176 38 119 33 100 185 103 84 161 166 103 227 43 200 127 53 52 89 19 215 76 254 110 30 239 247 11 182", "output": "3\n51 53 110 " }, { "input": "6\n3 5 4 6 8 1\n10\n3 3 0 5 4 0 10 5 6 8", "output": "4\n3 5 6 8 " }, { "input": "10\n0 1 2 3 4 5 6 7 8 9\n10\n0 1 2 3 4 5 6 7 8 9", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "8\n2 3 4 5 6 8 9 5\n9\n2 2 3 4 5 6 6 8 9", "output": "7\n2 3 4 5 6 8 9 " }, { "input": "8\n0 4 10 6 7 2 8 5\n7\n0 4 6 7 7 0 8", "output": "5\n0 4 6 7 8 " }, { "input": "10\n0 1 2 3 4 5 6 7 8 9\n10\n0 1 2 3 4 5 6 7 8 9", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "17\n12 17 39 156 100 177 188 129 14 142 45 144 243 151 158 194 245\n16\n125 12 17 199 65 39 100 185 129 194 142 144 62 92 158 194", "output": "9\n12 17 39 100 129 142 144 158 194 " }, { "input": "20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207\n20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207", "output": "20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207 " }, { "input": "13\n0 46 104 116 63 118 158 16 221 222 136 245 223\n9\n0 46 104 116 118 158 221 222 245", "output": "9\n0 46 104 116 118 158 221 222 245 " }, { "input": "13\n34 38 51 57 73 125 147 158 160 178 188 198 235\n15\n34 38 51 57 73 125 147 158 160 178 255 67 188 198 235", "output": "13\n34 38 51 57 73 125 147 158 160 178 188 198 235 " }, { "input": "17\n25 29 37 207 122 189 118 42 54 95 154 160 162 225 228 237 248\n19\n25 29 248 37 147 209 42 54 255 95 154 160 162 225 228 237 73 248 10", "output": "13\n25 29 37 42 54 95 154 160 162 225 228 237 248 " }, { "input": "10\n62914292 123971042 784965687 324817892 379711365 394545872 813282270 822333477 865397146 437913515\n9\n297835672 62914292 123971042 324817892 379711365 394545872 813282270 822333477 865397146", "output": "8\n62914292 123971042 324817892 379711365 394545872 813282270 822333477 865397146 " }, { "input": "10\n130077811 57466561 335978192 71385678 434259735 454136111 482887469 530031703 688581885 809880630\n8\n373627898 57466561 71385678 434259735 454136111 482887469 530031703 809880630", "output": "7\n57466561 71385678 434259735 454136111 482887469 530031703 809880630 " }, { "input": "17\n364396044 90653796 82853043 311258337 326557522 362475139 415783272 428510002 840021181 469284863 541444887 650535473 649258258 750028895 791368777 808443140 959785237\n13\n82853043 311258337 326557522 362475139 415783272 428510002 469284863 541444887 649258258 750028895 791368777 808443140 959785237", "output": "13\n82853043 311258337 326557522 362475139 415783272 428510002 469284863 541444887 649258258 750028895 791368777 808443140 959785237 " }, { "input": "3\n6379263 55134355 76061584\n3\n6379263 55134355 76061584", "output": "3\n6379263 55134355 76061584 " }, { "input": "3\n48875076 71023491 76538219\n3\n48875076 71023491 76538219", "output": "3\n48875076 71023491 76538219 " }, { "input": "5\n6621317 78540394 52064998 89150480 53659440\n3\n78540394 46008538 839195", "output": "1\n78540394 " }, { "input": "2\n34665180 51128665\n5\n71074966 34665180 47089728 44119345 51128665", "output": "2\n34665180 51128665 " }, { "input": "4\n3 4 9 1\n7\n5 3 8 9 10 2 1", "output": "2\n3 9 " } ]
1,608,455,491
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
77
204,800
n = int(input()) arr1 = list(map(int, input().split())) m = int(input()) arr2 = list(map(int, input().split())) D = [] for i in range(0, n+1): D.append([]) D[i].append([]) for j in range(1, m+1): D[0].append([]) for i in range(1, n+1): for j in range(1, m+1): if arr1[i-1]==arr2[j-1]: D[i].append(list(D[i-1][j-1])) D[i][j].append(arr1[i-1]) elif len(D[i-1][j])>len(D[i][j-1]): D[i].append(D[i-1][j]) else: D[i].append(D[i][j-1]) print(len(D[n][m])) print(*D[n][m])
Title: LCIS Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: This problem differs from one which was on the online contest. The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=&lt;<=*a**i*<=+<=1 for *i*<=&lt;<=*n*. The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of indexes 1<=≤<=*i*1<=&lt;<=*i*2<=&lt;<=...<=&lt;<=*i**k*<=≤<=*n* that *a**i**j*<==<=*s**j*. In other words, the sequence *s* can be derived from the sequence *a* by crossing out some elements. You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=500) — the length of the first sequence. The second line contains *n* space-separated integers from the range [0,<=109] — elements of the first sequence. The third line contains an integer *m* (1<=≤<=*m*<=≤<=500) — the length of the second sequence. The fourth line contains *m* space-separated integers from the range [0,<=109] — elements of the second sequence. Output Specification: In the first line output *k* — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any. Demo Input: ['7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n', '5\n1 2 0 2 1\n3\n1 0 1\n'] Demo Output: ['3\n3 5 6 \n', '2\n0 1 \n'] Note: none
```python n = int(input()) arr1 = list(map(int, input().split())) m = int(input()) arr2 = list(map(int, input().split())) D = [] for i in range(0, n+1): D.append([]) D[i].append([]) for j in range(1, m+1): D[0].append([]) for i in range(1, n+1): for j in range(1, m+1): if arr1[i-1]==arr2[j-1]: D[i].append(list(D[i-1][j-1])) D[i][j].append(arr1[i-1]) elif len(D[i-1][j])>len(D[i][j-1]): D[i].append(D[i-1][j]) else: D[i].append(D[i][j-1]) print(len(D[n][m])) print(*D[n][m]) ```
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,510,507,817
5,117
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
4
2,000
14,233,600
n = int(input()) s = [int(k) for k in input().split()] s1 = [] for i in range(0, n): if s[i] in s1: s1.remove(s[i]) s1.append(s[i]) print(s1[0])
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()) s = [int(k) for k in input().split()] s1 = [] for i in range(0, n): if s[i] in s1: s1.remove(s[i]) s1.append(s[i]) print(s1[0]) ```
0
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR", "output": "67" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU", "output": "99" }, { "input": "3\nRUR", "output": "2" }, { "input": "1\nR", "output": "1" }, { "input": "5\nRURUU", "output": "3" }, { "input": "1\nU", "output": "1" }, { "input": "2\nUR", "output": "1" }, { "input": "23\nUUUUUUUUUUUUUUUUUUUUUUU", "output": "23" } ]
1,637,549,303
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input(' ')) s = input(' ') c=0 d=0 while d<n-1: if((s[d]=='U' and s[d+1]=='R') or (s[d]=='R' and s[d+1]=='U')) c = c + 1 i = i + 2 else: i = i + 1 result = n - count print(res)
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. Output Specification: Print the minimum possible length of the sequence of moves after all replacements are done. Demo Input: ['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n'] Demo Output: ['3\n', '13\n'] Note: In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
```python n = int(input(' ')) s = input(' ') c=0 d=0 while d<n-1: if((s[d]=='U' and s[d+1]=='R') or (s[d]=='R' and s[d+1]=='U')) c = c + 1 i = i + 2 else: i = i + 1 result = n - count print(res) ```
-1
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,681,794,458
2,147,483,647
Python 3
OK
TESTS
48
62
0
arr = input().split() arr = [int(x) for x in arr] arr.sort() distanceArr = [] for i in range(arr[0], arr[2] + 1): distanceArr.append(abs(arr[0] - i) + abs(arr[1] - i) + abs(arr[2] - i)) print(min(distanceArr))
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
```python arr = input().split() arr = [int(x) for x in arr] arr.sort() distanceArr = [] for i in range(arr[0], arr[2] + 1): distanceArr.append(abs(arr[0] - i) + abs(arr[1] - i) + abs(arr[2] - i)) print(min(distanceArr)) ```
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,688,446,321
2,147,483,647
Python 3
OK
TESTS
20
31
0
# Codeforces 1A Theatre Square def tiles(size, length): reqd = size // length rem = size % length return reqd if rem == 0 else reqd + 1 n, m, a = (int(i) for i in input().split()) print(tiles(n, a) * tiles(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 # Codeforces 1A Theatre Square def tiles(size, length): reqd = size // length rem = size % length return reqd if rem == 0 else reqd + 1 n, m, a = (int(i) for i in input().split()) print(tiles(n, a) * tiles(m, a)) ```
3.9845
569
A
Music
PROGRAMMING
1,500
[ "implementation", "math" ]
null
null
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start.
The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105).
Print a single integer — the number of times the song will be restarted.
[ "5 2 2\n", "5 4 7\n", "6 2 3\n" ]
[ "2\n", "1\n", "1\n" ]
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
500
[ { "input": "5 2 2", "output": "2" }, { "input": "5 4 7", "output": "1" }, { "input": "6 2 3", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "2 1 3", "output": "1" }, { "input": "2 1 10000", "output": "1" }, { "input": "12326 6163 2", "output": "1" }, { "input": "10000 2500 4", "output": "1" }, { "input": "100000 99999 4", "output": "1" }, { "input": "12351 1223 6", "output": "2" }, { "input": "100000 1 10000", "output": "2" }, { "input": "10028 13 10000", "output": "1" }, { "input": "100000 99999 2", "output": "1" }, { "input": "100000 99999 3", "output": "1" }, { "input": "100000 1 2", "output": "17" }, { "input": "100000 1 3", "output": "11" }, { "input": "100000 1 4", "output": "9" }, { "input": "100000 1 5", "output": "8" }, { "input": "100000 3125 2", "output": "5" }, { "input": "12628 1804 7", "output": "1" }, { "input": "100000 45 13", "output": "4" }, { "input": "100000 500 3", "output": "5" }, { "input": "356 2 3", "output": "5" }, { "input": "50 2 2", "output": "5" }, { "input": "65465 12 3", "output": "8" }, { "input": "10033 3 8", "output": "4" }, { "input": "100000 3 2", "output": "16" }, { "input": "64 1 8", "output": "2" }, { "input": "10000 9 2", "output": "11" }, { "input": "25 2 2", "output": "4" }, { "input": "129 2 2", "output": "7" }, { "input": "6562 1 3", "output": "9" }, { "input": "100000 1 10", "output": "5" } ]
1,444,284,830
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
import sys for line in sys.stdin: t,s,q=map(int,line.split()) r=float(q-1)/q i = 0 while s<t: s=float(s)/(1-r) i+=1 print (i)
Title: Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start. Input Specification: The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105). Output Specification: Print a single integer — the number of times the song will be restarted. Demo Input: ['5 2 2\n', '5 4 7\n', '6 2 3\n'] Demo Output: ['2\n', '1\n', '1\n'] Note: In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
```python import sys for line in sys.stdin: t,s,q=map(int,line.split()) r=float(q-1)/q i = 0 while s<t: s=float(s)/(1-r) i+=1 print (i) ```
0
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, { "input": "789 101112 131415", "output": "203802" }, { "input": "27485716 99999999 35182", "output": "55041796" }, { "input": "1 293548 5", "output": "12" }, { "input": "12059 259855 5874875", "output": "543828" }, { "input": "46981 105809 585858", "output": "305580" }, { "input": "9889 1221 2442", "output": "7326" }, { "input": "100500 200600 300700", "output": "601800" }, { "input": "318476 318476 318476", "output": "955428" }, { "input": "23985 3353 75633", "output": "54676" }, { "input": "120 1298 2222", "output": "2836" }, { "input": "98437 23487 666672", "output": "243848" }, { "input": "100000000 100000000 100000000", "output": "300000000" }, { "input": "2 5 2", "output": "8" }, { "input": "1 1000 1", "output": "4" }, { "input": "1 100000000 1", "output": "4" } ]
1,659,683,878
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
a,b,c = list(map(int, input().split())) if(a+b < c): dis = (a+b)*2 elif(a+b > c): dis = (a+b+c) else: dis = (a+b+c) print(dis)
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python a,b,c = list(map(int, input().split())) if(a+b < c): dis = (a+b)*2 elif(a+b > c): dis = (a+b+c) else: dis = (a+b+c) print(dis) ```
0
267
A
Subtractions
PROGRAMMING
900
[ "math", "number theory" ]
null
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them?
The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109).
Print the sought number of operations for each pair on a single line.
[ "2\n4 17\n7 987654321\n" ]
[ "8\n141093479\n" ]
none
500
[ { "input": "2\n4 17\n7 987654321", "output": "8\n141093479" }, { "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479" }, { "input": "1\n536870912 32", "output": "16777216" }, { "input": "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999", "output": "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000" }, { "input": "3\n1000000000 1\n1000000000 1\n1 100000000", "output": "1000000000\n1000000000\n100000000" } ]
1,633,726,217
2,147,483,647
Python 3
OK
TESTS
35
62
6,963,200
for x in range(int(input())): a, b = [int(x) for x in input().split()] count = 0 while a != 0 and b != 0: if a > b: factor = (a-b)//b + 1 a -= factor*b count+=factor else: factor = (b-a)//a+1 b -= factor*a count+=factor print(count)
Title: Subtractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them? Input Specification: The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). Output Specification: Print the sought number of operations for each pair on a single line. Demo Input: ['2\n4 17\n7 987654321\n'] Demo Output: ['8\n141093479\n'] Note: none
```python for x in range(int(input())): a, b = [int(x) for x in input().split()] count = 0 while a != 0 and b != 0: if a > b: factor = (a-b)//b + 1 a -= factor*b count+=factor else: factor = (b-a)//a+1 b -= factor*a count+=factor print(count) ```
3
918
B
Radio Station
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
1,000
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;", "output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server" }, { "input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;", "output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm" }, { "input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;", "output": "zygoumbmx 185.32.99.2; #ervbfot" }, { "input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;", "output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y" }, { "input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;", "output": "zbtjzzue 203.115.124.110; #tdwmshz" }, { "input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;", "output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t" }, { "input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;", "output": "command 11.1.1.1; #get" }, { "input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;", "output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn" }, { "input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;", "output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica" }, { "input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;", "output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica" }, { "input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;", "output": "block 255.255.255.255; #server" }, { "input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;", "output": "block 22.222.30.10; #alp" } ]
1,563,450,879
2,147,483,647
Python 3
OK
TESTS
28
124
409,600
n,m=map(int, input().split()) name=[] ip1=[] command=[] ip2=[] for i in range(n): s=input().split() name.append(s[0]) ip1.append(s[1]) for i in range(m): s=input().split() command.append(s[0]) ip2.append(s[1]) for i in range(m): index=ip1.index(ip2[i][0:len(ip2[i])-1]) print("{} {} {}".format(command[i], ip2[i], "#"+name[index]))
Title: Radio Station Time Limit: None seconds Memory Limit: None megabytes Problem Description: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input Specification: The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. Output Specification: Print *m* lines, the commands in the configuration file after Dustin did his task. Demo Input: ['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n'] Demo Output: ['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n'] Note: none
```python n,m=map(int, input().split()) name=[] ip1=[] command=[] ip2=[] for i in range(n): s=input().split() name.append(s[0]) ip1.append(s[1]) for i in range(m): s=input().split() command.append(s[0]) ip2.append(s[1]) for i in range(m): index=ip1.index(ip2[i][0:len(ip2[i])-1]) print("{} {} {}".format(command[i], ip2[i], "#"+name[index])) ```
3
39
B
Company Income Growth
PROGRAMMING
1,300
[ "greedy" ]
B. Company Income Growth
2
64
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth. Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces.
Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
[ "10\n-2 1 1 3 2 3 4 -10 -2 5\n", "3\n-1 -2 -3\n" ]
[ "5\n2002 2005 2006 2007 2010\n", "0\n" ]
none
0
[ { "input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010 " }, { "input": "3\n-1 -2 -3", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "2\n-1 1", "output": "1\n2002 " }, { "input": "2\n-1 1", "output": "1\n2002 " }, { "input": "2\n-2 0", "output": "0" }, { "input": "2\n3 -3", "output": "0" }, { "input": "3\n1 1 1", "output": "1\n2001 " }, { "input": "3\n-2 -2 1", "output": "1\n2003 " }, { "input": "4\n-4 2 3 -1", "output": "0" }, { "input": "5\n-3 -3 -4 2 -2", "output": "0" }, { "input": "100\n-1 -9 0 -2 -7 -3 -1 -1 6 -5 -3 5 10 -5 7 7 4 9 -6 1 0 3 0 1 -9 -9 6 -8 3 7 -9 -4 -5 -6 8 2 2 7 2 2 0 -6 5 3 9 7 -7 -7 -2 6 -3 -4 10 3 3 -4 2 -9 9 9 -6 -1 -7 -3 -6 10 10 -1 -8 -3 8 1 10 9 -9 10 4 -10 -6 9 7 8 5 -3 2 2 2 -7 -6 0 -4 -1 4 -2 -4 -1 2 -8 10 9", "output": "5\n2020 2036 2044 2077 2083 " }, { "input": "100\n5 -1 6 0 2 10 -6 6 -10 0 10 6 -10 3 8 4 2 6 3 -9 1 -1 -8 6 -6 -10 0 -3 -1 -6 -7 -9 -5 -5 5 -10 -3 4 -6 8 -4 2 2 8 2 -7 -4 -4 -9 4 -9 6 -4 -10 -8 -6 2 6 -4 3 3 4 -1 -9 8 9 -6 5 3 9 -4 0 -9 -10 3 -10 2 5 7 0 9 4 5 -3 5 -5 9 -4 6 -7 4 -1 -10 -1 -2 2 -1 4 -10 6", "output": "6\n2021 2042 2060 2062 2068 2089 " }, { "input": "100\n10 9 -10 0 -9 1 10 -6 -3 8 0 5 -7 -9 9 -1 1 4 9 0 4 -7 3 10 -3 -10 -6 4 -3 0 -7 8 -6 -1 5 0 -6 1 5 -7 10 10 -2 -10 -4 -1 -1 2 5 1 6 -7 3 -1 1 10 4 2 4 -3 -10 9 4 5 1 -10 -1 -9 -8 -2 4 -4 -10 -9 -5 -9 -1 -3 -3 -8 -8 -3 6 -3 6 10 -4 -1 -3 8 -9 0 -2 2 1 6 -4 -7 -9 3", "output": "6\n2006 2048 2053 2057 2064 2083 " }, { "input": "100\n-8 -3 -4 2 1 -9 5 4 4 -8 -8 6 -7 -1 9 -6 -1 1 -5 9 6 10 -8 -5 -2 10 7 10 -5 8 -7 5 -4 0 3 9 -9 -5 -4 -2 4 -1 -4 -5 -9 6 2 7 0 -2 2 3 -9 6 -10 6 5 -4 -9 -9 1 -7 -9 -3 -5 -8 4 0 4 10 -8 -6 -8 -9 5 -8 -6 -9 10 5 -6 -7 6 -5 8 3 1 3 7 3 -1 0 5 4 4 7 -7 5 -8 -2", "output": "7\n2005 2047 2052 2067 2075 2083 2089 " }, { "input": "100\n-15 8 -20 -2 -16 3 -19 -15 16 19 -1 -17 -14 9 7 2 20 -16 8 20 10 3 17 -3 2 5 9 15 3 3 -17 12 7 17 -19 -15 -5 16 -10 -4 10 -15 -16 9 -15 15 -16 7 -15 12 -17 7 4 -8 9 -2 -19 14 12 -1 17 -6 19 14 19 -9 -12 3 14 -10 5 7 19 11 5 10 18 2 -6 -12 7 5 -9 20 10 2 -20 6 -10 -16 -6 -5 -15 -2 15 -12 0 -18 2 -5", "output": "0" }, { "input": "100\n11 18 14 -19 -12 -5 -14 -3 13 14 -20 11 -6 12 -2 19 -16 -2 -4 -4 -18 -2 -15 5 -7 -18 11 5 -8 16 17 1 6 8 -20 13 17 -15 -20 7 16 -3 -17 -1 1 -18 2 9 4 2 -18 13 16 -14 -18 -14 16 19 13 4 -14 3 5 -7 5 -17 -14 13 20 16 -13 7 12 15 0 4 16 -16 -6 -15 18 -19 2 8 -4 -8 14 -4 20 -15 -20 14 7 -10 -17 -20 13 -1 -11 -4", "output": "4\n2032 2047 2062 2076 " }, { "input": "100\n3 99 47 -26 96 90 21 -74 -19 -17 80 -43 -24 -82 -39 -40 44 84 87 72 -78 -94 -82 -87 96 71 -29 -90 66 49 -87 19 -31 97 55 -29 -98 16 -23 68 84 -54 74 -71 -60 -32 -72 95 -55 -17 -49 -73 63 39 -31 -91 40 -29 -60 -33 -33 49 93 -56 -81 -18 38 45 -29 63 -37 27 75 13 -100 52 -51 75 -38 -49 28 39 -7 -37 -86 100 -8 28 -89 -57 -17 -52 -98 -92 56 -49 -24 92 28 31", "output": "0" }, { "input": "100\n-36 -88 -23 -71 33 53 21 49 97 -50 -91 24 -83 -100 -77 88 -56 -31 -27 7 -74 -69 -75 -59 78 -66 53 21 -41 72 -31 -93 26 98 58 78 -95 -64 -2 34 74 14 23 -25 -51 -94 -46 100 -44 79 46 -8 79 25 -55 16 35 67 29 58 49 75 -53 80 63 -50 -59 -5 -71 -72 -57 75 -71 6 -5 -44 34 -2 -10 -58 -98 67 -42 22 95 46 -58 88 62 82 85 -74 -94 -5 -64 12 -8 44 -57 87", "output": "0" }, { "input": "100\n-76 -73 -93 85 -30 66 -29 -79 13 -82 -12 90 8 -68 86 15 -5 55 -91 92 80 5 83 19 59 -1 -17 83 52 44 25 -3 83 -51 62 -66 -91 58 20 51 15 -70 -77 22 -92 -4 -70 55 -33 -27 -59 6 94 60 -79 -28 -20 -38 -83 100 -20 100 51 -35 -44 -82 44 -5 88 -6 -26 -79 -16 -2 -61 12 -81 -80 68 -68 -23 96 -77 80 -75 -57 93 97 12 20 -65 -46 -90 81 16 -77 -43 -3 8 -58", "output": "0" }, { "input": "100\n-64 -18 -21 46 28 -100 21 -98 49 -44 -38 52 -85 62 42 -85 19 -27 88 -45 28 -86 -20 15 34 61 17 88 95 21 -40 -2 -12 90 -61 30 7 -13 -74 43 -57 43 -30 51 -19 -51 -22 -2 -76 85 1 -53 -31 -77 96 -61 61 88 -62 88 -6 -59 -70 18 -65 90 91 -27 -86 37 8 -92 -82 -78 -57 -81 17 -53 3 29 -88 -92 -28 49 -2 -41 32 -89 -38 49 22 37 -17 -1 -78 -80 -12 36 -95 30", "output": "1\n2051 " }, { "input": "1\n1", "output": "1\n2001 " }, { "input": "2\n1 2", "output": "2\n2001 2002 " }, { "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": "100\n2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 " }, { "input": "100\n-29 -92 -94 81 -100 1 -29 2 3 97 -37 4 5 -52 6 7 -81 86 8 9 10 98 36 -99 11 -18 12 -46 13 14 15 16 17 18 19 20 21 23 53 22 23 24 6 17 45 25 99 26 -53 -51 48 -11 71 27 -56 28 29 -36 30 31 61 -53 -64 32 33 89 -90 34 35 54 36 -89 13 -89 5 37 38 39 -57 26 55 80 40 63 41 42 43 44 92 45 46 47 -10 -10 -32 48 49 50 -10 -99", "output": "50\n2006 2008 2009 2012 2013 2015 2016 2019 2020 2021 2025 2027 2029 2030 2031 2032 2033 2034 2035 2036 2037 2040 2041 2042 2046 2048 2054 2056 2057 2059 2060 2064 2065 2068 2069 2071 2076 2077 2078 2083 2085 2086 2087 2088 2090 2091 2092 2096 2097 2098 " }, { "input": "100\n1 2 84 -97 3 -59 30 -55 4 -6 80 5 6 7 -8 8 3 -96 88 9 10 -20 -95 11 12 67 5 4 -15 -62 -74 13 14 15 16 17 18 19 20 21 22 -15 23 -35 -17 24 25 -99 26 27 69 2 -92 -96 -77 28 29 -95 -75 30 -36 31 17 -88 10 52 32 33 34 -94 35 -38 -16 36 37 38 31 -58 39 -81 83 46 40 41 42 43 -44 44 4 49 -60 17 64 45 46 47 48 49 -38 50", "output": "50\n2001 2002 2005 2009 2012 2013 2014 2016 2020 2021 2024 2025 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2043 2046 2047 2049 2050 2056 2057 2060 2062 2067 2068 2069 2071 2074 2075 2076 2079 2083 2084 2085 2086 2088 2094 2095 2096 2097 2098 2100 " }, { "input": "100\n1 2 80 30 95 51 -3 -12 3 -11 4 -90 5 6 7 8 -18 52 77 -82 9 10 11 -51 -16 70 12 13 14 15 16 17 58 18 36 19 -86 20 21 40 -53 94 22 23 27 67 24 -90 -38 17 -71 40 25 72 -82 26 27 -4 28 29 30 31 32 67 33 34 90 42 -52 35 36 37 -6 38 39 -11 30 40 41 42 -42 21 -96 43 -50 44 -73 16 45 90 46 47 48 2 -37 -88 49 -27 -43 50", "output": "50\n2001 2002 2009 2011 2013 2014 2015 2016 2021 2022 2023 2027 2028 2029 2030 2031 2032 2034 2036 2038 2039 2043 2044 2047 2053 2056 2057 2059 2060 2061 2062 2063 2065 2066 2070 2071 2072 2074 2075 2078 2079 2080 2084 2086 2089 2091 2092 2093 2097 2100 " }, { "input": "100\n1 2 3 -72 6 4 5 6 7 8 9 10 11 -57 12 13 14 -37 74 15 16 17 3 18 19 20 21 22 -6 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 -24 39 40 41 42 43 44 45 -52 46 -65 47 -82 48 49 50 47 -28 51 52 53 54 55 -30 56 57 58 59 12 60 61 62 63 -14 64 65 66 67 -77 68 69 70 71 72 73 74 -4 -6 -75 75 -26 76 49 77 -86", "output": "77\n2001 2002 2003 2006 2007 2008 2009 2010 2011 2012 2013 2015 2016 2017 2020 2021 2022 2024 2025 2026 2027 2028 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2047 2048 2049 2050 2051 2052 2053 2055 2057 2059 2060 2061 2064 2065 2066 2067 2068 2070 2071 2072 2073 2075 2076 2077 2078 2080 2081 2082 2083 2085 2086 2087 2088 2089 2090 2091 2095 2097 2099 " }, { "input": "100\n10 5 -69 1 -79 -57 -80 87 -38 -54 -91 33 29 81 20 -58 -97 70 2 -13 71 57 -15 98 -18 100 34 -25 -39 75 100 -88 3 95 48 -92 -20 -13 5 4 -19 -99 4 -46 -35 12 -43 -30 -37 -51 77 90 -47 -87 3 -84 -62 -51 69 -38 74 -63 -5 5 6 7 -65 90 -33 -23 8 19 -69 -98 24 28 100 9 -90 -34 -69 72 -15 8 27 -80 6 33 62 -57 -4 10 40 81 -78 58 43 83 57 21", "output": "10\n2004 2019 2033 2040 2064 2065 2066 2071 2078 2092 " }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "10\n2 3 1 3 3 2 1 2 1 2", "output": "2\n2003 2006 " }, { "input": "15\n4 1 4 6 3 2 1 1 3 2 4 4 1 4 1", "output": "4\n2002 2006 2009 2011 " }, { "input": "15\n3 3 3 2 2 2 1 1 1 2 2 2 4 4 4", "output": "2\n2007 2010 " }, { "input": "15\n6 5 2 3 4 1 3 2 4 5 1 2 6 4 4", "output": "2\n2006 2008 " } ]
1,524,487,676
2,147,483,647
Python 3
OK
TESTS
35
156
7,065,600
_, values,i,years = int(input()),[int(i) for i in input().split(" ")],1,[] if 1 in values: years.append(values.index(1)) i=2 while i in values[years[-1]:]: years.append(values[years[-1]:].index(i)+years[-1]) i+=1 print(len(years)) if len(years) !=0: for year in years: print(2001+year,end=" ") print()
Title: Company Income Growth Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth. Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces. Output Specification: Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0. Demo Input: ['10\n-2 1 1 3 2 3 4 -10 -2 5\n', '3\n-1 -2 -3\n'] Demo Output: ['5\n2002 2005 2006 2007 2010\n', '0\n'] Note: none
```python _, values,i,years = int(input()),[int(i) for i in input().split(" ")],1,[] if 1 in values: years.append(values.index(1)) i=2 while i in values[years[-1]:]: years.append(values[years[-1]:].index(i)+years[-1]) i+=1 print(len(years)) if len(years) !=0: for year in years: print(2001+year,end=" ") print() ```
3.908357
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 7", "output": "5" }, { "input": "14 5 5", "output": "6" }, { "input": "16 6 9", "output": "10" }, { "input": "20 13 17", "output": "7" }, { "input": "22 4 8", "output": "9" }, { "input": "23 8 14", "output": "15" }, { "input": "26 18 22", "output": "8" }, { "input": "28 6 1", "output": "2" }, { "input": "29 5 23", "output": "24" }, { "input": "32 27 15", "output": "5" }, { "input": "33 11 5", "output": "6" }, { "input": "37 21 15", "output": "16" }, { "input": "39 34 33", "output": "5" }, { "input": "41 27 11", "output": "12" }, { "input": "42 25 16", "output": "17" }, { "input": "45 7 43", "output": "38" }, { "input": "47 16 17", "output": "18" }, { "input": "49 11 37", "output": "38" }, { "input": "51 38 39", "output": "13" }, { "input": "52 29 7", "output": "8" }, { "input": "56 43 12", "output": "13" }, { "input": "58 57 28", "output": "1" }, { "input": "59 12 39", "output": "40" }, { "input": "62 9 52", "output": "53" }, { "input": "63 29 44", "output": "34" }, { "input": "65 30 22", "output": "23" }, { "input": "66 27 38", "output": "39" }, { "input": "71 33 53", "output": "38" }, { "input": "73 14 12", "output": "13" }, { "input": "73 37 35", "output": "36" }, { "input": "76 69 44", "output": "7" }, { "input": "79 25 20", "output": "21" }, { "input": "81 60 20", "output": "21" }, { "input": "81 79 14", "output": "2" }, { "input": "84 0 42", "output": "43" }, { "input": "88 79 8", "output": "9" }, { "input": "90 76 59", "output": "14" }, { "input": "92 2 22", "output": "23" }, { "input": "94 5 88", "output": "89" }, { "input": "94 62 48", "output": "32" }, { "input": "96 22 72", "output": "73" }, { "input": "100 11 88", "output": "89" }, { "input": "100 81 91", "output": "19" }, { "input": "1 0 0", "output": "1" } ]
1,689,877,742
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
122
0
a,b,c=map(int,input().split()) v=a-b if(v<=b): print(b) else: print(v)
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. Input Specification: The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100). Output Specification: Print the single number — the number of the sought positions. Demo Input: ['3 1 1\n', '5 2 3\n'] Demo Output: ['2\n', '3\n'] Note: The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
```python a,b,c=map(int,input().split()) v=a-b if(v<=b): print(b) else: print(v) ```
0
337
D
Book of Evil
PROGRAMMING
2,000
[ "dfs and similar", "divide and conquer", "dp", "trees" ]
null
null
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains *n* settlements numbered from 1 to *n*. Moving through the swamp is very difficult, so people tramped exactly *n*<=-<=1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to reach any settlement from any other one by traversing one or several paths. The distance between two settlements is the minimum number of paths that have to be crossed to get from one settlement to the other one. Manao knows that the Book of Evil has got a damage range *d*. This means that if the Book of Evil is located in some settlement, its damage (for example, emergence of ghosts and werewolves) affects other settlements at distance *d* or less from the settlement where the Book resides. Manao has heard of *m* settlements affected by the Book of Evil. Their numbers are *p*1,<=*p*2,<=...,<=*p**m*. Note that the Book may be affecting other settlements as well, but this has not been detected yet. Manao wants to determine which settlements may contain the Book. Help him with this difficult task.
The first line contains three space-separated integers *n*, *m* and *d* (1<=≤<=*m*<=≤<=*n*<=≤<=100000; 0<=≤<=*d*<=≤<=*n*<=-<=1). The second line contains *m* distinct space-separated integers *p*1,<=*p*2,<=...,<=*p**m* (1<=≤<=*p**i*<=≤<=*n*). Then *n*<=-<=1 lines follow, each line describes a path made in the area. A path is described by a pair of space-separated integers *a**i* and *b**i* representing the ends of this path.
Print a single number — the number of settlements that may contain the Book of Evil. It is possible that Manao received some controversial information and there is no settlement that may contain the Book. In such case, print 0.
[ "6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6\n" ]
[ "3\n" ]
Sample 1. The damage range of the Book of Evil equals 3 and its effects have been noticed in settlements 1 and 2. Thus, it can be in settlements 3, 4 or 5.
2,000
[ { "input": "6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6", "output": "3" }, { "input": "2 2 1\n2 1\n1 2", "output": "2" }, { "input": "50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 32\n20 45\n24 32\n4 18\n49 39\n13 45\n26 4\n11 33\n14 37\n42 19\n31 45\n38 3\n34 8\n18 29\n35 34\n29 16\n7 46\n19 28\n27 33\n30 9\n33 16\n36 45\n47 1\n41 39\n23 13\n3 39\n5 34\n12 43", "output": "9" }, { "input": "10 1 0\n3\n10 1\n9 4\n4 5\n6 4\n2 4\n7 5\n8 3\n5 3\n1 3", "output": "1" }, { "input": "5 2 1\n1 5\n1 2\n2 3\n3 4\n4 5", "output": "0" }, { "input": "5 2 0\n1 2\n1 2\n2 3\n3 4\n4 5", "output": "0" } ]
1,672,849,933
2,147,483,647
PyPy 3
MEMORY_LIMIT_EXCEEDED
TESTS
0
122
268,390,400
# LUOGU_RID: 98703200 import sys sys.setrecursionlimit(10000000) n, m, d = [int(i) for i in input().split()] exist = [False] * (n + 1) for i in input().split(): exist[int(i)] = True dest = [[] for _ in range(n + 1)] for _ in range(n - 1): a, b = [int(i) for i in input().split()] dest[a].append(b) dest[b].append(a) d_subtree = [-10000000] * (n + 1) def dfs1(x, p): if exist[x]: d_subtree[x] = 0 for to in dest[x]: if to != p: dfs1(to, x) d_subtree[x] = max(d_subtree[x], d_subtree[to] + 1) dfs1(1, -1) d_else = [-10000000] * (n + 1) def dfs2(x, p): max1 = -10000000 max2 = -10000000 if exist[x]: d_else[x] = max(0, d_else[x]) for to in dest[x]: if to == p: continue if d_subtree[to] > max1: max2 = max1 max1 = d_subtree[to] elif d_subtree[to] > max2: max2 = d_subtree[to] for to in dest[x]: if to == p: continue sDist = max2 if d_subtree[to] == max1 else max1 if sDist >= 0: sDist += 2 d_else[to] = max(sDist, d_else[x] + 1) dfs2(to, x) dfs2(1, -1) print(sum([(d_subtree[i] <= d and d_else[i] <= d) for i in range(1, 1 + n)])) # print("d_subtree", d_subtree[1:]) # print("d_else", d_else[1:]) # print([(d_subtree[i] <= d and d_else[i] <= d) for i in range(1, 1 + n)])
Title: Book of Evil Time Limit: None seconds Memory Limit: None megabytes Problem Description: Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains *n* settlements numbered from 1 to *n*. Moving through the swamp is very difficult, so people tramped exactly *n*<=-<=1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to reach any settlement from any other one by traversing one or several paths. The distance between two settlements is the minimum number of paths that have to be crossed to get from one settlement to the other one. Manao knows that the Book of Evil has got a damage range *d*. This means that if the Book of Evil is located in some settlement, its damage (for example, emergence of ghosts and werewolves) affects other settlements at distance *d* or less from the settlement where the Book resides. Manao has heard of *m* settlements affected by the Book of Evil. Their numbers are *p*1,<=*p*2,<=...,<=*p**m*. Note that the Book may be affecting other settlements as well, but this has not been detected yet. Manao wants to determine which settlements may contain the Book. Help him with this difficult task. Input Specification: The first line contains three space-separated integers *n*, *m* and *d* (1<=≤<=*m*<=≤<=*n*<=≤<=100000; 0<=≤<=*d*<=≤<=*n*<=-<=1). The second line contains *m* distinct space-separated integers *p*1,<=*p*2,<=...,<=*p**m* (1<=≤<=*p**i*<=≤<=*n*). Then *n*<=-<=1 lines follow, each line describes a path made in the area. A path is described by a pair of space-separated integers *a**i* and *b**i* representing the ends of this path. Output Specification: Print a single number — the number of settlements that may contain the Book of Evil. It is possible that Manao received some controversial information and there is no settlement that may contain the Book. In such case, print 0. Demo Input: ['6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6\n'] Demo Output: ['3\n'] Note: Sample 1. The damage range of the Book of Evil equals 3 and its effects have been noticed in settlements 1 and 2. Thus, it can be in settlements 3, 4 or 5.
```python # LUOGU_RID: 98703200 import sys sys.setrecursionlimit(10000000) n, m, d = [int(i) for i in input().split()] exist = [False] * (n + 1) for i in input().split(): exist[int(i)] = True dest = [[] for _ in range(n + 1)] for _ in range(n - 1): a, b = [int(i) for i in input().split()] dest[a].append(b) dest[b].append(a) d_subtree = [-10000000] * (n + 1) def dfs1(x, p): if exist[x]: d_subtree[x] = 0 for to in dest[x]: if to != p: dfs1(to, x) d_subtree[x] = max(d_subtree[x], d_subtree[to] + 1) dfs1(1, -1) d_else = [-10000000] * (n + 1) def dfs2(x, p): max1 = -10000000 max2 = -10000000 if exist[x]: d_else[x] = max(0, d_else[x]) for to in dest[x]: if to == p: continue if d_subtree[to] > max1: max2 = max1 max1 = d_subtree[to] elif d_subtree[to] > max2: max2 = d_subtree[to] for to in dest[x]: if to == p: continue sDist = max2 if d_subtree[to] == max1 else max1 if sDist >= 0: sDist += 2 d_else[to] = max(sDist, d_else[x] + 1) dfs2(to, x) dfs2(1, -1) print(sum([(d_subtree[i] <= d and d_else[i] <= d) for i in range(1, 1 + n)])) # print("d_subtree", d_subtree[1:]) # print("d_else", d_else[1:]) # print([(d_subtree[i] <= d and d_else[i] <= d) for i in range(1, 1 + n)]) ```
0
322
A
Ciel and Dancing
PROGRAMMING
1,000
[ "greedy" ]
null
null
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: - either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); - or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room.
In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*.
[ "2 1\n", "2 2\n" ]
[ "2\n1 1\n2 1\n", "3\n1 1\n1 2\n2 2\n" ]
In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song). And in test case 2, we have 2 boys with 2 girls, the answer is 3.
500
[ { "input": "2 1", "output": "2\n1 1\n2 1" }, { "input": "2 2", "output": "3\n1 1\n1 2\n2 2" }, { "input": "1 1", "output": "1\n1 1" }, { "input": "2 3", "output": "4\n1 1\n1 2\n1 3\n2 3" }, { "input": "4 4", "output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4" }, { "input": "1 12", "output": "12\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12" }, { "input": "12 1", "output": "12\n1 1\n12 1\n11 1\n10 1\n9 1\n8 1\n7 1\n6 1\n5 1\n4 1\n3 1\n2 1" }, { "input": "100 100", "output": "199\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "24 6", "output": "29\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n24 6\n23 6\n22 6\n21 6\n20 6\n19 6\n18 6\n17 6\n16 6\n15 6\n14 6\n13 6\n12 6\n11 6\n10 6\n9 6\n8 6\n7 6\n6 6\n5 6\n4 6\n3 6\n2 6" }, { "input": "7 59", "output": "65\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n7 59\n6 59\n5 59\n4 59\n3 59\n2 59" }, { "input": "26 75", "output": "100\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n26 75\n25 75\n24 75\n23 75\n22 75\n21 75\n20 75\n19 75\n18 75\n17..." }, { "input": "32 87", "output": "118\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "42 51", "output": "92\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n42 51\n41 51\n40 51\n39 51\n38 51\n37 51\n36 51\n35 51\n34 51\n33 51\n32 51\n31 51\n30 51\n29 51\n28 51\n27 51\n26 51\n25 51\n24 51\n23 51\n22 51\n21 51\n20 51\n19 51\n18 51\n17 51\n16 51\n15 51\n14 51\n13 51\n..." }, { "input": "4 63", "output": "66\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n4 63\n3 63\n2 63" }, { "input": "10 79", "output": "88\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n10 79\n9 79\n8 79\n7 79\n6 79\n5 79\n4 79\n..." }, { "input": "20 95", "output": "114\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "35 55", "output": "89\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n35 55\n34 55\n33 55\n32 55\n31 55\n30 55\n29 55\n28 55\n27 55\n26 55\n25 55\n24 55\n23 55\n22 55\n21 55\n20 55\n19 55\n18 55\n17 55\n16 55\n15 55\n14 55\n13 55\n12 55\n11 55\n10 55\n9 55..." }, { "input": "45 71", "output": "115\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n45 71\n44 71\n43 71\n42 71\n41 71\n40 71\n39 71\n38 71\n37 71\n36 71\n35 71\n34 71\n33 71..." }, { "input": "7 83", "output": "89\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n7 83\n6 83\n5 83\n..." }, { "input": "32 100", "output": "131\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "42 17", "output": "58\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n42 17\n41 17\n40 17\n39 17\n38 17\n37 17\n36 17\n35 17\n34 17\n33 17\n32 17\n31 17\n30 17\n29 17\n28 17\n27 17\n26 17\n25 17\n24 17\n23 17\n22 17\n21 17\n20 17\n19 17\n18 17\n17 17\n16 17\n15 17\n14 17\n13 17\n12 17\n11 17\n10 17\n9 17\n8 17\n7 17\n6 17\n5 17\n4 17\n3 17\n2 17" }, { "input": "1 77", "output": "77\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77" }, { "input": "19 93", "output": "111\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "25 5", "output": "29\n1 1\n1 2\n1 3\n1 4\n1 5\n25 5\n24 5\n23 5\n22 5\n21 5\n20 5\n19 5\n18 5\n17 5\n16 5\n15 5\n14 5\n13 5\n12 5\n11 5\n10 5\n9 5\n8 5\n7 5\n6 5\n5 5\n4 5\n3 5\n2 5" }, { "input": "35 21", "output": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n35 21\n34 21\n33 21\n32 21\n31 21\n30 21\n29 21\n28 21\n27 21\n26 21\n25 21\n24 21\n23 21\n22 21\n21 21\n20 21\n19 21\n18 21\n17 21\n16 21\n15 21\n14 21\n13 21\n12 21\n11 21\n10 21\n9 21\n8 21\n7 21\n6 21\n5 21\n4 21\n3 21\n2 21" }, { "input": "99 99", "output": "197\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "99 100", "output": "198\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." }, { "input": "100 99", "output": "198\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n..." } ]
1,626,766,833
2,147,483,647
PyPy 3
OK
TESTS
28
248
20,172,800
b,g=map(int,input().split());g-=1 print(b+g) for i in range(1,b+1):print(i,1) for i in range(2,g+2):print(b,i)
Title: Ciel and Dancing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: - either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); - or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. Output Specification: In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. Demo Input: ['2 1\n', '2 2\n'] Demo Output: ['2\n1 1\n2 1\n', '3\n1 1\n1 2\n2 2\n'] Note: In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song). And in test case 2, we have 2 boys with 2 girls, the answer is 3.
```python b,g=map(int,input().split());g-=1 print(b+g) for i in range(1,b+1):print(i,1) for i in range(2,g+2):print(b,i) ```
3
961
A
Tetris
PROGRAMMING
900
[ "implementation" ]
null
null
You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $n$ columns have at least one square in them, the bottom row is being removed. You will receive $1$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive.
The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares. The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear.
Print one integer — the amount of points you will receive.
[ "3 9\n1 1 2 2 2 3 1 2 3\n" ]
[ "2\n" ]
In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$). After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing one row it will look like $[1~ 2~ 0]$. So the answer will be equal to $2$.
0
[ { "input": "3 9\n1 1 2 2 2 3 1 2 3", "output": "2" }, { "input": "1 7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "3 5\n1 1 1 2 3", "output": "1" }, { "input": "4 6\n4 4 4 4 4 4", "output": "0" }, { "input": "4 6\n2 3 4 4 4 4", "output": "0" }, { "input": "3 12\n1 1 1 1 2 2 2 2 3 3 3 3", "output": "4" }, { "input": "8 8\n2 2 3 4 5 6 7 8", "output": "0" }, { "input": "100 1\n50", "output": "0" }, { "input": "2 1\n2", "output": "0" }, { "input": "2 1\n1", "output": "0" }, { "input": "2 4\n1 2 1 1", "output": "1" }, { "input": "3 4\n3 2 2 2", "output": "0" }, { "input": "2 2\n2 2", "output": "0" }, { "input": "2 5\n2 1 1 2 1", "output": "2" }, { "input": "15 3\n13 14 15", "output": "0" }, { "input": "4 9\n1 2 3 1 2 3 1 2 3", "output": "0" }, { "input": "100 3\n1 2 3", "output": "0" }, { "input": "1000 10\n999 999 998 34 454 546 343 35 34 1000", "output": "0" }, { "input": "4 2\n1 2", "output": "0" } ]
1,637,379,064
2,147,483,647
Python 3
OK
TESTS
29
46
0
n,m=[int(x) for x in input().split()] a=[int(x) for x in input().split()] lst=[0]*(n+1) for i in a: lst[i]+=1 res=max(lst) for i in range(1,n+1): if lst[i]<res: res=lst[i] print(res)
Title: Tetris Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $n$ columns have at least one square in them, the bottom row is being removed. You will receive $1$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive. Input Specification: The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares. The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. Output Specification: Print one integer — the amount of points you will receive. Demo Input: ['3 9\n1 1 2 2 2 3 1 2 3\n'] Demo Output: ['2\n'] Note: In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$). After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing one row it will look like $[1~ 2~ 0]$. So the answer will be equal to $2$.
```python n,m=[int(x) for x in input().split()] a=[int(x) for x in input().split()] lst=[0]*(n+1) for i in a: lst[i]+=1 res=max(lst) for i in range(1,n+1): if lst[i]<res: res=lst[i] print(res) ```
3
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307", "output": "22258199.5000000000" }, { "input": "2 1000000000\n0 1000000000", "output": "500000000.0000000000" }, { "input": "2 555\n200 300", "output": "255.0000000000" }, { "input": "1 1\n1", "output": "1.0000000000" }, { "input": "1 1\n0", "output": "1.0000000000" }, { "input": "1 1000000000\n0", "output": "1000000000.0000000000" }, { "input": "1 1000000000\n1000000000", "output": "1000000000.0000000000" }, { "input": "1 999999999\n499999999", "output": "500000000.0000000000" }, { "input": "4 700\n0 250 475 700", "output": "125.0000000000" }, { "input": "4 700\n0 225 450 700", "output": "125.0000000000" }, { "input": "5 1000\n0 250 500 750 1000", "output": "125.0000000000" }, { "input": "5 2000\n1001 1001 1001 1001 1001", "output": "1001.0000000000" }, { "input": "1 999\n501", "output": "501.0000000000" }, { "input": "2 1000\n400 600", "output": "400.0000000000" }, { "input": "4 15\n1 3 9 11", "output": "4.0000000000" }, { "input": "1 5\n2", "output": "3.0000000000" } ]
1,695,110,074
2,147,483,647
Python 3
OK
TESTS
32
46
0
n,l = map(int,input().split()) l1 = list(map(int,input().split())) l1.sort() diff = 0 for i in range(n-1): a = float( (l1[i+1] - l1[i])/2 ) diff = max(a ,diff) diff = max((l-l1[-1]) , diff , l1[0] - 0) diff= float(diff) format(diff, '.6f') print(diff)
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? Input Specification: The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. Output Specification: Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. Demo Input: ['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n'] Demo Output: ['2.5000000000\n', '2.0000000000\n'] Note: Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
```python n,l = map(int,input().split()) l1 = list(map(int,input().split())) l1.sort() diff = 0 for i in range(n-1): a = float( (l1[i+1] - l1[i])/2 ) diff = max(a ,diff) diff = max((l-l1[-1]) , diff , l1[0] - 0) diff= float(diff) format(diff, '.6f') print(diff) ```
3
387
B
George and Round
PROGRAMMING
1,200
[ "brute force", "greedy", "two pointers" ]
null
null
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Print a single integer — the answer to the problem.
[ "3 5\n1 2 3\n1 2 2 3 3\n", "3 5\n1 2 3\n1 1 1 1 1\n", "3 1\n2 3 4\n1\n" ]
[ "0\n", "2\n", "3\n" ]
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
1,000
[ { "input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0" }, { "input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2" }, { "input": "3 1\n2 3 4\n1", "output": "3" }, { "input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98", "output": "24" } ]
1,598,001,831
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
155
25,292,800
n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) x=max(max(a),max(b)) c=[0]*x d=[0]*x for i in range(n): c[a[i]-1]+=1 for i in range(m): d[b[i]-1]+=1 ans=0 for i in range(x): if c[i]>d[i]: ans+=c[i]-d[i] print(ans)
Title: George and Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n'] Demo Output: ['0\n', '2\n', '3\n'] Note: In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
```python n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) x=max(max(a),max(b)) c=[0]*x d=[0]*x for i in range(n): c[a[i]-1]+=1 for i in range(m): d[b[i]-1]+=1 ans=0 for i in range(x): if c[i]>d[i]: ans+=c[i]-d[i] print(ans) ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,652,193,909
2,147,483,647
Python 3
OK
TESTS
30
92
0
word = str(input()) upperCount = 0 lowerCount = 0 for item in word: if item.isupper() == True: upperCount += 1 else: lowerCount += 1 if lowerCount >= upperCount: print(word.lower()) else: print(word.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 word = str(input()) upperCount = 0 lowerCount = 0 for item in word: if item.isupper() == True: upperCount += 1 else: lowerCount += 1 if lowerCount >= upperCount: print(word.lower()) else: print(word.upper()) ```
3.977
0
none
none
none
0
[ "none" ]
null
null
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players. The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
[ "4\n75 150 75 50\n", "3\n100 150 250\n" ]
[ "Yes\n", "No\n" ]
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
0
[ { "input": "4\n75 150 75 50", "output": "Yes" }, { "input": "3\n100 150 250", "output": "No" }, { "input": "7\n34 34 68 34 34 68 34", "output": "Yes" }, { "input": "10\n72 96 12 18 81 20 6 2 54 1", "output": "No" }, { "input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058", "output": "No" }, { "input": "2\n1 1", "output": "Yes" }, { "input": "2\n72 72", "output": "Yes" }, { "input": "2\n49 42", "output": "No" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "Yes" }, { "input": "6\n162000 96000 648000 1000 864000 432000", "output": "Yes" }, { "input": "8\n600000 100000 100000 100000 900000 600000 900000 600000", "output": "Yes" }, { "input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072", "output": "Yes" }, { "input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246", "output": "Yes" }, { "input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009", "output": "No" }, { "input": "2\n5 6", "output": "No" }, { "input": "3\n536870912 387420489 257407169", "output": "No" }, { "input": "4\n2 2 5 2", "output": "No" }, { "input": "2\n33554432 59049", "output": "Yes" }, { "input": "3\n536870912 387420489 387420489", "output": "Yes" }, { "input": "2\n1 5", "output": "No" }, { "input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71", "output": "No" }, { "input": "2\n1 30", "output": "No" }, { "input": "3\n335544320 71744535 71744535", "output": "Yes" }, { "input": "5\n1000000000 999999999 999999998 999999997 999999996", "output": "No" }, { "input": "2\n25 5", "output": "No" }, { "input": "4\n75 150 75 5", "output": "No" }, { "input": "3\n536870912 387420489 362797056", "output": "Yes" }, { "input": "3\n536870912 387420489 89", "output": "No" }, { "input": "4\n547 2606459 222763549 143466789", "output": "No" }, { "input": "3\n129140163 33554432 1", "output": "Yes" }, { "input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489", "output": "No" }, { "input": "3\n5 5 1", "output": "No" }, { "input": "5\n3 7 29 36760123 823996703", "output": "No" } ]
1,573,100,040
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
23
373
7,475,200
n = int(input()) numbers = list(map(int, input().split())) MAX = 32000 bs = [True] * MAX primes = [] def sieve(): bs[0] = False bs[1] = False for i in range(2, MAX): if bs[i]: for j in range(i * i, MAX, i): bs[j] = False primes.append(i) def num_pfs(number): num_pfs = 0 for p in primes: if p * p > number: break while number % p == 0: if p > 3: num_pfs += 1 number //= p if number > 1: if number > 3: num_pfs += 1 return num_pfs sieve() pfs = num_pfs(numbers[0]) possible = True for i in range(1, len(numbers)): if num_pfs(numbers[i]) != pfs: possible = False break if possible: print("Yes") else: print("No")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input Specification: First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players. The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. Output Specification: Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Demo Input: ['4\n75 150 75 50\n', '3\n100 150 250\n'] Demo Output: ['Yes\n', 'No\n'] Note: In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
```python n = int(input()) numbers = list(map(int, input().split())) MAX = 32000 bs = [True] * MAX primes = [] def sieve(): bs[0] = False bs[1] = False for i in range(2, MAX): if bs[i]: for j in range(i * i, MAX, i): bs[j] = False primes.append(i) def num_pfs(number): num_pfs = 0 for p in primes: if p * p > number: break while number % p == 0: if p > 3: num_pfs += 1 number //= p if number > 1: if number > 3: num_pfs += 1 return num_pfs sieve() pfs = num_pfs(numbers[0]) possible = True for i in range(1, len(numbers)): if num_pfs(numbers[i]) != pfs: possible = False break if possible: print("Yes") else: print("No") ```
0
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,418,653,551
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
k=0 i=int(input()) while i>0: n=int(input()) k+=n i-=1 if k>0 or k==0 and n>0: print('first') if k<0 or k==0 and n<0: 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 k=0 i=int(input()) while i>0: n=int(input()) k+=n i-=1 if k>0 or k==0 and n>0: print('first') if k<0 or k==0 and n<0: print('second') ```
0
592
C
The Big Race
PROGRAMMING
1,800
[ "math" ]
null
null
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today. Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*. Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today?
The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=&gt;<=0 holds) is called irreducible, if there is no such integer *d*<=&gt;<=1, that both *p* and *q* are divisible by *d*.
[ "10 3 2\n", "7 1 2\n" ]
[ "3/10\n", "3/7\n" ]
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
1,500
[ { "input": "10 3 2", "output": "3/10" }, { "input": "7 1 2", "output": "3/7" }, { "input": "1 1 1", "output": "1/1" }, { "input": "5814 31 7", "output": "94/2907" }, { "input": "94268 813 766", "output": "765/94268" }, { "input": "262610 5583 4717", "output": "2358/131305" }, { "input": "3898439 96326 71937", "output": "71936/3898439" }, { "input": "257593781689876390 32561717 4411677", "output": "7914548537/257593781689876390" }, { "input": "111319886766128339 7862842484895022 3003994959686829", "output": "3003994959686828/111319886766128339" }, { "input": "413850294331656955 570110918058849723 409853735661743839", "output": "409853735661743838/413850294331656955" }, { "input": "3000000000000000000 2999999999999999873 2999999999999999977", "output": "23437499999999999/23437500000000000" }, { "input": "9 6 1", "output": "1/9" }, { "input": "32 9 2", "output": "3/32" }, { "input": "976 5 6", "output": "41/244" }, { "input": "5814 31 7", "output": "94/2907" }, { "input": "94268 714 345", "output": "689/94268" }, { "input": "262610 5583 4717", "output": "2358/131305" }, { "input": "3898439 96326 71937", "output": "71936/3898439" }, { "input": "54682301 778668 253103", "output": "253102/54682301" }, { "input": "329245015 1173508 8918834", "output": "1173507/329245015" }, { "input": "321076647734423976 7 7", "output": "1/1" }, { "input": "455227494055672047 92 28", "output": "19792499741550983/455227494055672047" }, { "input": "595779167455745259 6954 8697", "output": "205511958419723/595779167455745259" }, { "input": "1000000000000000000 1000000000 2000000000", "output": "1/2" }, { "input": "462643382718281828 462643382718281507 462643382718281701", "output": "33045955908448679/33045955908448702" }, { "input": "4000000000000000000 9999999999999997 99999999999999999", "output": "2499999999999999/1000000000000000000" }, { "input": "4003000100004000000 9999999099999999 99999999999999999", "output": "4999999549999999/2001500050002000000" }, { "input": "4903000100004000000 58997960959949999 99933992929999999", "output": "29498980479974999/2451500050002000000" }, { "input": "257593781689876390 32561717 4411677", "output": "7914548537/257593781689876390" }, { "input": "111319886766128339 7862842484895022 3003994959686829", "output": "3003994959686828/111319886766128339" }, { "input": "413850294331656955 570110918058849723 409853735661743839", "output": "409853735661743838/413850294331656955" }, { "input": "232 17 83", "output": "2/29" }, { "input": "5496272 63 200", "output": "13765/2748136" }, { "input": "180 174 53", "output": "13/45" }, { "input": "1954 190 537", "output": "189/1954" }, { "input": "146752429 510 514", "output": "571199/146752429" }, { "input": "579312860 55 70", "output": "10344881/144828215" }, { "input": "1 9 9", "output": "1/1" }, { "input": "95 19 19", "output": "1/1" }, { "input": "404 63 441", "output": "31/202" }, { "input": "5566 4798 4798", "output": "1/1" }, { "input": "118289676 570846883 570846883", "output": "1/1" }, { "input": "763 358 358", "output": "1/1" }, { "input": "85356138 7223 482120804", "output": "3611/42678069" }, { "input": "674664088 435395270 5", "output": "9/674664088" }, { "input": "762200126044291557 370330636048898430 6", "output": "17/762200126044291557" }, { "input": "917148533938841535 47 344459175789842163", "output": "28/183429706787768307" }, { "input": "360212127113008697 877228952036215545 5259", "output": "5258/360212127113008697" }, { "input": "683705963104411677 89876390 116741460012229240", "output": "539258339/683705963104411677" }, { "input": "573003994959686829 275856334120822851 1319886766128339", "output": "3959660298385016/573003994959686829" }, { "input": "409853735661743839 413850294331656955 413850294331656955", "output": "1/1" }, { "input": "19 1 19", "output": "1/19" }, { "input": "576 18 32", "output": "1/16" }, { "input": "9540 10 954", "output": "1/477" }, { "input": "101997840 6 16999640", "output": "1/8499820" }, { "input": "955944 1278 748", "output": "1/639" }, { "input": "482120804 66748 7223", "output": "1/66748" }, { "input": "370330636048898430 61721772674816405 6", "output": "1/61721772674816405" }, { "input": "344459175789842163 7328918633826429 47", "output": "1/7328918633826429" }, { "input": "877228952036215545 166805277055755 5259", "output": "1/55601759018585" }, { "input": "116741460012229240 1298911316 89876390", "output": "1/649455658" }, { "input": "275856334120822851 209 1319886766128339", "output": "1/1319886766128339" }, { "input": "413850294331656955 1 413850294331656955", "output": "1/413850294331656955" }, { "input": "54682301 778668 253103", "output": "253102/54682301" }, { "input": "329245015 3931027 6443236", "output": "357366/29931365" }, { "input": "321076647734423976 7 8", "output": "1672274206950125/13378193655600999" }, { "input": "455227494055672047 71 60", "output": "6411654845854559/455227494055672047" }, { "input": "595779167455745259 9741 9331", "output": "61162012885196/595779167455745259" }, { "input": "6470 80 160", "output": "327/647" }, { "input": "686325 828 1656", "output": "114511/228775" }, { "input": "4535304 2129 4258", "output": "755973/1511768" }, { "input": "40525189 6365 12730", "output": "20265394/40525189" }, { "input": "675297075 25986 51972", "output": "112553659/225099025" }, { "input": "5681598412 75376 226128", "output": "1893897375/5681598412" }, { "input": "384118571739435733 619773000 1859319000", "output": "128039524053435733/384118571739435733" }, { "input": "391554751752251913 625743359 1877230077", "output": "130518250652782079/391554751752251913" }, { "input": "390728504279201198 625082797 1250165594", "output": "195364252413988195/390728504279201198" }, { "input": "389902265396085075 624421544 1248843088", "output": "64983710976697837/129967421798695025" }, { "input": "734812071040507372 857211800 2571635400", "output": "61234339274051543/183703017760126843" }, { "input": "1 1 2", "output": "0/1" }, { "input": "3 1 4", "output": "0/1" }, { "input": "8 2 3", "output": "3/8" }, { "input": "64 32 16", "output": "1/2" }, { "input": "1 1 1000000000", "output": "0/1" }, { "input": "1000000000 1 1", "output": "1/1" }, { "input": "1000000000 1000000000 1000000000", "output": "1/1" }, { "input": "1000000000 2 4", "output": "1/2" }, { "input": "1000000000 123 456", "output": "6579023/1000000000" }, { "input": "1000000000 123123 654", "output": "24851/1000000000" }, { "input": "123456 123 456", "output": "215/30864" }, { "input": "123456 1234567 123", "output": "61/61728" }, { "input": "314159265 271 8281", "output": "37939/314159265" }, { "input": "11071994 4231 1324", "output": "2647/11071994" }, { "input": "961748927 961748941 982451653", "output": "1/1" }, { "input": "15485221 1259 90863", "output": "1258/15485221" }, { "input": "5000000000000000000 4999999999999999837 4999999999999999963", "output": "1249999999999999959/1250000000000000000" }, { "input": "4000000000000000000 3999999999999999691 3999999999999999887", "output": "399999999999999969/400000000000000000" }, { "input": "999999999999999999 999999999999999709 999999999999999737", "output": "333333333333333236/333333333333333333" }, { "input": "799999999999999999 799999999999999969 799999999999999991", "output": "799999999999999968/799999999999999999" }, { "input": "812312312312312222 812312312312311897 812312312312312029", "output": "406156156156155948/406156156156156111" }, { "input": "500000000000000000 499999999999999927 499999999999999931", "output": "249999999999999963/250000000000000000" }, { "input": "555555555555555555 555555555555555083 555555555555555229", "output": "50505050505050462/50505050505050505" }, { "input": "199419941994199419 199419941994199369 199419941994199391", "output": "66473313998066456/66473313998066473" }, { "input": "145685485411238588 145685485411238483 145685485411238573", "output": "72842742705619241/72842742705619294" }, { "input": "314159265358979323 314159265358979167 314159265358979213", "output": "314159265358979166/314159265358979323" }, { "input": "10 1000000000000000000 1000000000000000001", "output": "1/1" }, { "input": "5 100000000000000000 99999999999999999", "output": "1/1" }, { "input": "5 1000000000000 1000000000001", "output": "1/1" }, { "input": "5 1000000000000000000 1000000000000000001", "output": "1/1" }, { "input": "2 1000000000000000000 1000000000000000001", "output": "1/1" }, { "input": "2 10 11", "output": "1/1" }, { "input": "10 123456789123456789 723456789123456781", "output": "1/1" }, { "input": "12345678910 123456789101112131 123456789101112132", "output": "1/1" }, { "input": "5 499999999999999999 499999999999999998", "output": "1/1" } ]
1,446,314,579
5,579
Python 3
WRONG_ANSWER
PRETESTS
2
46
0
def lcm(a,b): m = a*b while a != 0 and b != 0: if a > b: a %= b else: b %= a return m // (a+b) t,w,b = map(int,input().split()) if (t % 3 == 0): print('1/',end ='') print(t/3) else: print('3/',end='') print(t)
Title: The Big Race Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today. Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*. Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today? Input Specification: The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. Output Specification: Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=&gt;<=0 holds) is called irreducible, if there is no such integer *d*<=&gt;<=1, that both *p* and *q* are divisible by *d*. Demo Input: ['10 3 2\n', '7 1 2\n'] Demo Output: ['3/10\n', '3/7\n'] Note: In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
```python def lcm(a,b): m = a*b while a != 0 and b != 0: if a > b: a %= b else: b %= a return m // (a+b) t,w,b = map(int,input().split()) if (t % 3 == 0): print('1/',end ='') print(t/3) else: print('3/',end='') print(t) ```
0