context
stringlengths 88
7.54k
| groundtruth
stringlengths 9
28.8k
| groundtruth_language
stringclasses 3
values | type
stringclasses 2
values | code_test_cases
listlengths 1
565
⌀ | dataset
stringclasses 6
values | code_language
stringclasses 1
value | difficulty
float64 0
1
⌀ | mid
stringlengths 32
32
|
---|---|---|---|---|---|---|---|---|
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.
The books are given by indices of their genres. The genres are numbered from 1 to m.
Input
The first line contains two positive integers n and m (2 ≤ n ≤ 2·105, 2 ≤ m ≤ 10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence a1, a2, ..., an, where ai (1 ≤ ai ≤ m) equals the genre of the i-th book.
It is guaranteed that for each genre there is at least one book of that genre.
Output
Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109.
Examples
Input
4 3
2 1 3 1
Output
5
Input
7 4
4 2 3 1 2 4 3
Output
18
Note
The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books,
2. the first and third books,
3. the first and fourth books,
4. the second and third books,
5. the third and fourth books.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
t = 0
for i in range(m):
cnt = a.count(i + 1)
t += cnt * (n - cnt)
n -= cnt
print(t)
| python | code_algorithm | [
{
"input": "7 4\n4 2 3 1 2 4 3\n",
"output": "18\n"
},
{
"input": "4 3\n2 1 3 1\n",
"output": "5\n"
},
{
"input": "100 10\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6\n",
"output": "4428\n"
},
{
"input": "3 2\n1 2 2\n",
"output": "2\n"
},
{
"input": "12 3\n1 2 3 1 2 3 1 2 3 1 2 3\n",
"output": "48\n"
},
{
"input": "100 3\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3\n",
"output": "3296\n"
},
{
"input": "100 5\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5 5 4 2 5\n",
"output": "3953\n"
},
{
"input": "9 2\n1 1 1 1 2 1 1 1 1\n",
"output": "8\n"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10\n",
"output": "45\n"
},
{
"input": "2 2\n1 2\n",
"output": "1\n"
}
] | code_contests | python | 1 | 173cb75d60084a7e4745591d70e49607 |
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City?
Input
The only line of the input contains a single integer n (2 ≤ n ≤ 2·1018) — the power in which you need to raise number 5.
Output
Output the last two digits of 5n without spaces between them.
Examples
Input
2
Output
25
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n=int(input())
if(n==0):
print(1)
elif(n==1):
print(5)
else:
print(25) | python | code_algorithm | [
{
"input": "2\n",
"output": "25\n"
},
{
"input": "7\n",
"output": "25\n"
},
{
"input": "2000000000000000000\n",
"output": "25\n"
},
{
"input": "1000000000000000000\n",
"output": "25\n"
},
{
"input": "987654321012345678\n",
"output": "25\n"
}
] | code_contests | python | 1 | a5a6df6ce18ad564cfa1eaab0467c83b |
Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!
Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numbered from 1 to n from left to right, and the i-th piece has a colour si, denoted by a lowercase English letter. Nadeko will repaint at most m of the pieces to give each of them an arbitrary new colour (still denoted by a lowercase English letter). After this work, she finds out all subsegments of the garland containing pieces of only colour c — Brother Koyomi's favourite one, and takes the length of the longest among them to be the Koyomity of the garland.
For instance, let's say the garland is represented by "kooomo", and Brother Koyomi's favourite colour is "o". Among all subsegments containing pieces of "o" only, "ooo" is the longest, with a length of 3. Thus the Koyomity of this garland equals 3.
But problem arises as Nadeko is unsure about Brother Koyomi's favourite colour, and has swaying ideas on the amount of work to do. She has q plans on this, each of which can be expressed as a pair of an integer mi and a lowercase letter ci, meanings of which are explained above. You are to find out the maximum Koyomity achievable after repainting the garland according to each plan.
Input
The first line of input contains a positive integer n (1 ≤ n ≤ 1 500) — the length of the garland.
The second line contains n lowercase English letters s1s2... sn as a string — the initial colours of paper pieces on the garland.
The third line contains a positive integer q (1 ≤ q ≤ 200 000) — the number of plans Nadeko has.
The next q lines describe one plan each: the i-th among them contains an integer mi (1 ≤ mi ≤ n) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter ci — Koyomi's possible favourite colour.
Output
Output q lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it.
Examples
Input
6
koyomi
3
1 o
4 o
4 m
Output
3
6
5
Input
15
yamatonadeshiko
10
1 a
2 a
3 a
4 a
5 a
1 b
2 b
3 b
4 b
5 b
Output
3
4
5
7
8
1
2
3
4
5
Input
10
aaaaaaaaaa
2
10 b
10 z
Output
10
10
Note
In the first sample, there are three plans:
* In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable;
* In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6;
* In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | """ Python 3 compatibility tools. """
from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
def is_it_local():
script_dir = str(os.getcwd()).split('/')
username = "dipta007"
return username in script_dir
def READ(fileName):
if is_it_local():
sys.stdin = open(f'./{fileName}', 'r')
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
if not is_it_local():
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
def input1(type=int):
return type(input())
def input2(type=int):
[a, b] = list(map(type, input().split()))
return a, b
def input3(type=int):
[a, b, c] = list(map(type, input().split()))
return a, b, c
def input_array(type=int):
return list(map(type, input().split()))
def input_string():
s = input()
return list(s)
if is_it_local():
def debug(*args):
st = ""
for arg in args:
st += f"{arg} "
print(st)
else:
def debug(*args):
pass
##############################################################
ltr = [[] for _ in range(26)]
memo = {}
def main():
n = input1()
st = input_string()
for l in range(97, 97+26):
ltr[l-97].append(0)
ch = chr(l)
cum = 0
for i in range(n):
if st[i] == ch:
cum += 1
ltr[l-97].append(cum)
q = input1()
for i in range(q):
[m, c] = list(input().split())
m = int(m)
if c in memo and m in memo[c]:
print(memo[c][m])
continue
res = m
low = 1
z = 0
l = ord(c) - 97
for high in range(0, n+1):
tot = high - low + 1
now = ltr[l][high] - ltr[l][low-1]
need = tot - now
debug(high, low, tot, now, need)
while need > m:
low += 1
tot = high - low + 1
now = ltr[l][high] - ltr[l][low-1]
need = tot - now
res = max(res, high - low + 1)
if c not in memo:
memo[c] = {}
memo[c][m] = res
print(res)
pass
if __name__ == '__main__':
# READ('in.txt')
main() | python | code_algorithm | [
{
"input": "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n",
"output": "3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n"
},
{
"input": "6\nkoyomi\n3\n1 o\n4 o\n4 m\n",
"output": "3\n6\n5\n"
},
{
"input": "10\naaaaaaaaaa\n2\n10 b\n10 z\n",
"output": "10\n10\n"
},
{
"input": "20\naaaaaaaaaaaaaaaaaaaa\n1\n11 a\n",
"output": "20\n"
},
{
"input": "4\ncbcc\n12\n4 b\n4 c\n1 b\n2 a\n3 b\n2 c\n4 a\n1 a\n2 b\n3 a\n1 c\n3 c\n",
"output": "4\n4\n2\n2\n4\n4\n4\n1\n3\n3\n4\n4\n"
},
{
"input": "100\ndddddccccdddddaaaaabbbbbbbbbbbbbaaacdcabbacccacccccbdbbadddbbddddbdaaccacdddbbbaddddbbbbdcbbbdddddda\n50\n54 b\n48 d\n45 b\n52 c\n52 a\n48 a\n54 b\n45 a\n47 d\n50 d\n53 a\n34 a\n51 b\n48 d\n47 d\n47 a\n48 d\n53 b\n52 d\n54 d\n46 a\n38 a\n52 b\n49 a\n49 b\n46 c\n54 a\n45 b\n35 c\n55 c\n51 c\n46 d\n54 d\n50 a\n33 c\n46 a\n50 b\n50 a\n54 a\n32 b\n55 b\n49 c\n53 d\n49 a\n46 b\n48 c\n47 b\n47 b\n47 a\n46 b\n",
"output": "85\n72\n76\n69\n68\n63\n85\n60\n71\n74\n69\n46\n82\n72\n71\n62\n72\n84\n76\n78\n61\n50\n83\n64\n80\n60\n70\n76\n49\n72\n68\n70\n78\n66\n47\n61\n81\n66\n70\n53\n86\n63\n77\n64\n77\n62\n78\n78\n62\n77\n"
},
{
"input": "5\naaaaa\n1\n1 b\n",
"output": "1\n"
},
{
"input": "4\nddbb\n16\n3 c\n3 b\n1 a\n1 b\n4 d\n4 a\n3 d\n2 a\n2 d\n4 c\n3 a\n2 c\n4 b\n1 c\n2 b\n1 d\n",
"output": "3\n4\n1\n3\n4\n4\n4\n2\n4\n4\n3\n2\n4\n1\n4\n3\n"
},
{
"input": "4\nabcc\n24\n1 c\n4 d\n3 c\n1 d\n1 c\n1 b\n3 b\n2 c\n3 d\n3 d\n4 c\n2 a\n4 d\n1 a\n1 b\n4 a\n4 d\n3 b\n4 b\n3 c\n3 a\n2 d\n1 a\n2 b\n",
"output": "3\n4\n4\n1\n3\n2\n4\n4\n3\n3\n4\n3\n4\n2\n2\n4\n4\n4\n4\n4\n4\n2\n2\n3\n"
},
{
"input": "1\nc\n4\n1 x\n1 a\n1 e\n1 t\n",
"output": "1\n1\n1\n1\n"
},
{
"input": "40\ncbbcbcccccacccccbbacbaabccbbabbaaaaacccc\n10\n40 a\n28 c\n25 c\n21 a\n18 c\n27 a\n9 c\n37 c\n15 a\n18 b\n",
"output": "40\n40\n40\n31\n35\n37\n23\n40\n24\n27\n"
},
{
"input": "200\nddeecdbbbeeeeebbbbbaaaaaaaaaaaaaaaaaaaaaaabbcaacccbeeeeddddddddddddccccccdffeeeeecccccbbbbaaaaedfffffaadeeeeeeeedddddaaaaaaaaaaaaaabbbbbcaadddeefffbbbbcccccccccccbbbbbbeeeeeeeffffffdffffffffffffaaaaab\n10\n43 f\n118 d\n165 f\n72 f\n48 f\n2 a\n61 e\n94 d\n109 f\n16 a\n",
"output": "64\n144\n193\n98\n69\n25\n79\n117\n137\n41\n"
}
] | code_contests | python | 0.5 | 5945a8ee6a9d4abaa492707b52bceb7b |
You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest.
The track's map is represented by a rectangle n × m in size divided into squares. Each square is marked with a lowercase Latin letter (which means the type of the plot), with the exception of the starting square (it is marked with a capital Latin letters S) and the terminating square (it is marked with a capital Latin letter T). The time of movement from one square to another is equal to 1 minute. The time of movement within the cell can be neglected. We can move from the cell only to side-adjacent ones, but it is forbidden to go beyond the map edges. Also the following restriction is imposed on the path: it is not allowed to visit more than k different types of squares (squares of one type can be visited an infinite number of times). Squares marked with S and T have no type, so they are not counted. But S must be visited exactly once — at the very beginning, and T must be visited exactly once — at the very end.
Your task is to find the path from the square S to the square T that takes minimum time. Among all shortest paths you should choose the lexicographically minimal one. When comparing paths you should lexicographically represent them as a sequence of characters, that is, of plot types.
Input
The first input line contains three integers n, m and k (1 ≤ n, m ≤ 50, n·m ≥ 2, 1 ≤ k ≤ 4). Then n lines contain the map. Each line has the length of exactly m characters and consists of lowercase Latin letters and characters S and T. It is guaranteed that the map contains exactly one character S and exactly one character T.
Pretest 12 is one of the maximal tests for this problem.
Output
If there is a path that satisfies the condition, print it as a sequence of letters — the plot types. Otherwise, print "-1" (without quotes). You shouldn't print the character S in the beginning and T in the end.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
5 3 2
Sba
ccc
aac
ccc
abT
Output
bcccc
Input
3 4 1
Sxyy
yxxx
yyyT
Output
xxxx
Input
1 3 3
TyS
Output
y
Input
1 4 1
SxyT
Output
-1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import sys
from array import array # noqa: F401
from itertools import combinations
from collections import deque
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, k = map(int, input().split())
chars = (
['}' * (m + 2)]
+ ['}' + ''.join('{' if c == 'S' else '|' if c == 'T' else c for c in input().rstrip()) + '}' for _ in range(n)]
+ ['}' * (m + 2)]
)
cbit = [[1 << (ord(c) - 97) for c in chars[i]] for i in range(n + 2)]
si, sj, ti, tj = 0, 0, 0, 0
for i in range(1, n + 1):
for j in range(1, m + 1):
if chars[i][j] == '{':
si, sj = i, j
cbit[i][j] = 0
if chars[i][j] == '|':
ti, tj = i, j
ans = inf = '*' * (n * m)
for comb in combinations([1 << i for i in range(26)], r=k):
enabled = sum(comb)
dp = [[inf] * (m + 2) for _ in range(n + 2)]
dp[ti][tj] = ''
dq = deque([(ti, tj, '')])
while dq:
i, j, s = dq.popleft()
if dp[i][j] < s:
continue
for di, dj in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)):
if (cbit[di][dj] & enabled) != cbit[di][dj]:
continue
pre = chars[di][dj] if cbit[di][dj] else ''
l = 1 if cbit[di][dj] else 0
if (len(dp[di][dj]) > len(s) + l or len(dp[di][dj]) == len(s) + l and dp[di][dj] > pre + s):
dp[di][dj] = pre + s
if l:
dq.append((di, dj, pre + s))
if len(ans) > len(dp[si][sj]) or len(ans) == len(dp[si][sj]) and ans > dp[si][sj]:
ans = dp[si][sj]
print(ans if ans != inf else -1)
| python | code_algorithm | [
{
"input": "5 3 2\nSba\nccc\naac\nccc\nabT\n",
"output": "bcccc\n"
},
{
"input": "3 4 1\nSxyy\nyxxx\nyyyT\n",
"output": "xxxx\n"
},
{
"input": "1 3 3\nTyS\n",
"output": "y\n"
},
{
"input": "1 4 1\nSxyT\n",
"output": "-1\n"
},
{
"input": "20 10 3\nebebccacdb\neeebccddeT\neadebecaac\nadeeeaccbc\nbaccccdaed\ndeabceabba\ndadbecbaaa\neacbbcedcb\naeeScdbbab\nbabaecaead\nbacdbebeae\naacbadbeec\nacddceecca\nacaeaebaba\ncdddeaaeae\neabddadade\nddddaeaeed\nbccbaacadd\ndccccbabdc\necdaebeccc\n",
"output": "bbbcccaccaac\n"
},
{
"input": "1 30 2\nbmjcfldkloleiqqiTnmdjpaSckkijf\n",
"output": "-1\n"
},
{
"input": "15 15 3\ncbbdccabdcbacbd\nbcabdcacadacdbc\ncbcddbbcdbddcad\nddcabdbbdcabbdc\naabadcccTcabdbb\ncbacaaacaabdbbd\ndbdcbSdabaadbdb\ndbbaddcdddaadbb\nbbddcdcbaccbbaa\nadadadbdbbddccc\ncddbbdaddcbbdcc\nbbaadcdbbcaacca\nadbdcdbbcbddbcd\ncdadbcccddcdbda\ncbcdaabdcabccbc\n",
"output": "aaca\n"
},
{
"input": "10 8 2\nbdcdcbfa\ndecffcce\ndTffdacb\neeedcdbb\nfdbbbcba\nddabfcda\nabdbSeed\nbdcdcffa\ncadbaffa\nfcccddad\n",
"output": "bbbbee\n"
},
{
"input": "20 20 2\nddadfcdeTaeccbedeaec\nacafdfdeaffdeabdcefe\nabbcbefcdbbbcdebafef\nfdafdcccbcdeeaedeffc\ndfdaabdefdafabaabcef\nfebdcabacaaaabfacbbe\nabfcaacadfdbfdbaaefd\ndacceeccddccaccdbbce\ncacebecabedbddfbfdad\ndacbfcabbebfddcedffd\ncfcdfacfadcfbcebebaa\nddfbebafaccbebeefbac\nebfaebacbbebdfcbcbea\ndfbaebcfccacfeaccaad\nedeedeceebcbfdbcdbbe\nafaacccfbdecebfdabed\nddbdcedacedadeccaeec\necbSeacbdcccbcedafef\ncfdbeeffbeeafccfdddb\ncefdbdfbabccfdaaadbf\n",
"output": "-1\n"
},
{
"input": "2 1 4\nS\nT\n",
"output": "\n"
},
{
"input": "3 5 2\nSbcaT\nacbab\nacccb\n",
"output": "aacccaa\n"
},
{
"input": "3 4 1\nSbbT\naaaa\nabba\n",
"output": "bb\n"
},
{
"input": "5 3 4\naaT\nacc\nbbb\nbbc\ncSb\n",
"output": "bbbc\n"
},
{
"input": "1 50 3\nSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaTaaaaaaaaaaa\n",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
},
{
"input": "3 3 1\naaa\naaa\nTSa\n",
"output": "\n"
},
{
"input": "6 6 3\npkhipk\nmlfmak\naqmbae\ndlbfSj\ndpbjcr\naTbqbm\n",
"output": "cbqb\n"
},
{
"input": "3 4 1\nSbbb\naaaT\nabbc\n",
"output": "aaa\n"
},
{
"input": "5 5 1\ncaTbc\ndccac\ndacda\naacaS\ncdcab\n",
"output": "-1\n"
},
{
"input": "1 40 1\nfaSfgfTcfadcdfagfbccbffbeaaebagbfcfcgdfd\n",
"output": "-1\n"
},
{
"input": "1 3 3\nSaT\n",
"output": "a\n"
},
{
"input": "1 10 2\nbaaSaaTacb\n",
"output": "aa\n"
},
{
"input": "20 20 2\nbaaaaaaaaaaaaaaaaaaa\nbfffffffacfffffffffa\nbgggggggaccgggggggga\nbhhhhhhhaccchhhhhhha\nbiiiiiiiacccciiiiiia\nbjjjjjjjacccccjjjjja\nbkkkkkkkacccccckkkka\nblllllllacccccccllla\nbbbbbbbbSccccccccmma\nbddddddddddcccccccna\nbodddddddcccccccccca\nbppddddddddTaaaaaaaa\nbqqqdddddddbqqqqqqqa\nbrrrrddddddbrrrrrrra\nbsssssdddddbsssssssa\nbttttttddddbttttttta\nbuuuuuuudddbuuuuuuua\nbvvvvvvvvddbvvvvvvva\nbwwwwwwwwwdbwwwwwwwa\nbbbbbbbbbbbbbbbbbbbb\n",
"output": "ccccc\n"
},
{
"input": "10 10 2\nbaaaaaaaaa\nbffacffffa\nbggaccggga\nbbbSccchha\nbdddddccia\nbjddccccca\nbkkdddTaaa\nblllddblla\nbmmmmdbmma\nbbbbbbbbbb\n",
"output": "ccccc\n"
},
{
"input": "15 3 4\nllv\nttT\nhbo\nogc\nkfe\ngli\nfbx\nkfp\nspm\ncxc\nndw\nSoa\npfh\nedr\nxmv\n",
"output": "-1\n"
},
{
"input": "3 4 2\nSbbb\naabT\nabbc\n",
"output": "aab\n"
},
{
"input": "5 10 4\naaaaaaaaaa\naaaaaTaaaa\naaaaaaaSaa\naaaaaaaaaa\naaaaaaaaaa\n",
"output": "aa\n"
},
{
"input": "10 20 3\nbaaaaaaaaaaaaaaaaaaa\nbfffffffacfffffffffa\nbgggggggaccgggggggga\nbbbbbbbbSccchhhhhhha\nbiiiiidddddcciiiiiia\nbjjjjjjddcccccjjjjja\nbkkkkkkkdddTaaaaaaaa\nbllllllllddbllllllla\nbmmmmmmmmmdbmmmmmmma\nbbbbbbbbbbbbbbbbbbbb\n",
"output": "ccccc\n"
},
{
"input": "1 2 4\nST\n",
"output": "\n"
},
{
"input": "20 10 4\nbaaaaaaaaa\nbffacffffa\nbggaccggga\nbhhaccchha\nbiiaccccia\nbjjaccccca\nbkkakkkkka\nbllallllla\nbbbSmmmmma\nbnnnnnnnna\nbooooooooa\nbpppppTaaa\nbqqqqqbqqa\nbrrrrrbrra\nbdddddbssa\nbtddddbtta\nbuudddbuua\nbvvvddbvva\nbwwwwdbwwa\nbbbbbbbbbb\n",
"output": "mmmno\n"
},
{
"input": "15 10 4\nsejwprqjku\npnjsiopxft\nrsplgvwixq\nendglkchxl\nftihbbexgh\nsxtxbbavge\njcdkusfnmr\nskgsqvflia\nkcxmcxjpae\namaiwcfile\nnjgjSunmwd\nldxvahgreu\necmrajbjuT\nnaioqigols\npbwrmxkltj\n",
"output": "aajbju\n"
},
{
"input": "4 5 3\nabaaa\nbabaT\nSabba\naaaaa\n",
"output": "aaba\n"
},
{
"input": "1 2 1\nST\n",
"output": "\n"
},
{
"input": "2 1 1\nS\nT\n",
"output": "\n"
},
{
"input": "1 20 3\nacbccbbddbffScTadffd\n",
"output": "c\n"
}
] | code_contests | python | 0 | 066e7e8bfeaf543e639457de33d708a1 |
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.
You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.
How many operations will you need to perform until the next operation does not have any points to delete?
Input
Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.
The number of the points is between 1 and 106.
Output
Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.
Examples
Input
aabb
Output
2
Input
aabcaa
Output
1
Note
In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.
In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | name = input()
blocks = []
now = name[0]
counter = 1
for x in range(1, len(name)):
if name[x] != now:
blocks.append((now, counter))
now = name[x]
counter = 1
else:
counter += 1
blocks.append((now, counter))
counter = 0
temp = []
while len(blocks) > 1:
counter += 1
temp = []
(x, y) = blocks[0]
if y > 1:
temp.append((x, y - 1))
for s in range(1, len(blocks) - 1):
(x, y) = blocks[s]
if len(temp) > 0:
(tempx, tempy) = temp[-1]
if y > 2:
if x != tempx:
temp.append((x, y - 2))
else:
temp[-1] = (x, tempy + y - 2)
else:
if y > 2:
temp.append((x, y - 2))
(x, y) = blocks[-1]
if len(temp) > 0:
(tempx, tempy) = temp[-1]
if y > 1:
if x != tempx:
temp.append((x, y - 1))
else:
temp[-1] = (x, tempy + y - 1)
else:
if y > 1:
temp.append((x, y - 1))
blocks = temp
print(counter)
| python | code_algorithm | [
{
"input": "aabb\n",
"output": "2\n"
},
{
"input": "aabcaa\n",
"output": "1\n"
},
{
"input": "bbbbbbbbaaaaaaaaaaaccccccaaaaaaaaaaaaaaccccccccaaaaaaaaabbbbbbccbbbaaaaaabccccccaaaacaaacccccccccccb\n",
"output": "10\n"
},
{
"input": "ccccccccccccccccccccccccccccccccaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccccccc\n",
"output": "7\n"
},
{
"input": "aaaaabbbbbaaaaabbbbaaabbbbbbbaaabbbbbabbbbbbbaabbbbbbbbbbbbaaaaabbbbbbbbbbbbbbbbbbbbbbbbaaaaaabbbbbb\n",
"output": "5\n"
},
{
"input": "bddbeddebbeaccdeeeceaebbdaabecbcaeaaddbbeadebbbbebaddbdcdecaeebaceaeeabbbccccaaebbadcaaaebcedccecced\n",
"output": "2\n"
},
{
"input": "dbcbacdcacacdccddbbbabbcdcccacbaccbadacdbdbccdccacbcddcbcdbacdccddcdadaadabcdabcbddddcbaaacccacacbbc\n",
"output": "2\n"
},
{
"input": "abaabaaaabaabbaabaabaabbaabbaabaaaabbaabbaabaabaabaabbabaabbababbababbabaababbaaabbbbaabbabbaabbaaba\n",
"output": "3\n"
},
{
"input": "cccbcccabcaaaacabcacacccabbacccaccabbbcaaccaaabcccaabcbbcbcabccbccbbacbacabccabcbbbaaaccaaaaccaaccaa\n",
"output": "4\n"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaabbbbbbbbaaaaaaaaabbbbbaaaaaaaaaaabbbbbbaaabbbbaaabbbbbbaaa\n",
"output": "12\n"
},
{
"input": "a\n",
"output": "0\n"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbddddddddddddddddaaaaaaaaaaaaaccccccccbbbbbbbaaaaaaaaaabbbbbbbbaaaaaaaaaacccccc\n",
"output": "11\n"
},
{
"input": "cccccccccccccccccccccccccccaaaaaccccaaabbbbbbbbbbbbbbbbbbbbbbbbcbbbbbbbbbbbbbbbbbaaaaaaabbbbbbbbbaaa\n",
"output": "27\n"
},
{
"input": "aaabbb\n",
"output": "3\n"
},
{
"input": "abcaccabbacbcabaabaacabbbaabcbbbbacccaaabaacabbababbbbbcbcbbaaaabcaacbcccbabcaacaabbcbbcbbbcaabccacc\n",
"output": "2\n"
},
{
"input": "ddddddbdddddcccccccbbccccccddcccccccccbbbbbbbbbbddddddddddddddaaaeeeeedddddddddddddddcccccccbbbbbbbb\n",
"output": "9\n"
},
{
"input": "aaaaaaccccccccccccccaaaacccccccccccaaaaaacaaaaaaaabbbbaacccccccccccccccaaaaaaaaccccccbbbbbbbbccccccc\n",
"output": "6\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaaaaaaaaaaaaaaa\n",
"output": "15\n"
},
{
"input": "bbeeeeaaaaccccbbbbeeeeeeeeeeaaaaddddddddddddddddddbbbbbbbdddeeeeeeeeeeaaaaaaaaeeeeeaaaaadbbbbbbbeadd\n",
"output": "8\n"
},
{
"input": "ccbacccbcbabcbbcaacbcacccaabbababacbaabacababcaacbaacbaccccacccaababbbccacacacacababbabbbbbbbcbabaaa\n",
"output": "5\n"
},
{
"input": "aaaaaaacccccccccdddddaaaaaaaaccaaaaaaaaaaaccccccccceebbbbbbbbbdddddddddcccccccbbbbbbbbbeeeedddddeeee\n",
"output": "5\n"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbddddddaaaaaaaaaaaaaaaaaaaaaaaaaaaaaccccccccccccccccc\n",
"output": "17\n"
},
{
"input": "eeeeeeeeebbbbbbbbbbbbbbeeeeeeeeddcccccccccbbbbbbbbbbbbeeeeeddbbbbbbbbbbeeeeeebbaaaaddeeebbbbbbbacccc\n",
"output": "9\n"
},
{
"input": "aaaaaaaaabbbbbaaaabaaaaaaaaaaaaaaaaabaaaaaabbbbbbbaaabbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "12\n"
},
{
"input": "abababababab\n",
"output": "1\n"
},
{
"input": "ba\n",
"output": "1\n"
},
{
"input": "bcddbbdaebbaeaceaaebaacacbeecdbaeccaccbddedaceeeeecccabcabcbddbadaebcecdeaddcccacaeacddadbbeabeecadc\n",
"output": "3\n"
},
{
"input": "abc\n",
"output": "1\n"
},
{
"input": "abbcccbba\n",
"output": "1\n"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaccccccccccccccddddddddddd\n",
"output": "28\n"
},
{
"input": "bbbbbbcccccccccccccccccccbbbbaaaaaaaaaccccccbbbbaaaaaaaaaaabbbbbaccccccccccccccccccccbbbbaaaaaabbbbb\n",
"output": "7\n"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbeeeeeeeeeeeeeeeeeeeeeeeeeeeebbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "27\n"
},
{
"input": "ebbcadacbaacdedeaaaaccbaceccbbbcbaceadcbdeaebcbbbacaebaaaceebcaaaeabdeaaddabcccceecaebdbacdadccaedce\n",
"output": "3\n"
},
{
"input": "aabbabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaccccaaaabbbbbbaaaaacccccccccccccbbbbbbbbbbcccccccccbbaaaaaaaaaaa\n",
"output": "7\n"
},
{
"input": "abaaababbbbbbabababbaabbabbbaababaaabaabbbaaaabaabaaabababbaaaabbbbbbaaabbbbababbaababaabaaaabbabbab\n",
"output": "4\n"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbddddddddddddddddddddddddddddddddddddddcccccccccccccccccccccccccccccccccccc\n",
"output": "26\n"
},
{
"input": "acaaacaaacaacabcaaabbbabcbccbccbcccbbacbcccababccabcbbcbcbbabccabacccabccbbbbbabcbbccacaacbbbccbbcab\n",
"output": "4\n"
},
{
"input": "cbbabaacccacaaacacbabcbbacacbbbcaccacbcbbbabbaccaaacbbccbaaaabbcbcccacbababbbbcaabcbacacbbccaabbaaac\n",
"output": "2\n"
},
{
"input": "ddaaaaaaaaaaccccddddddddddeeeeaaaeedddddaaaaaaeebedddddeeeeeeeeeebbbbbbbbbbbbbbaaaaaabbbbbbbeeeeeebb\n",
"output": "8\n"
},
{
"input": "bbbbbbddddddddddddddddddddcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n",
"output": "14\n"
},
{
"input": "aaaaaaabbbbbbbbbddddddddddeeeeeeeebbbbbeeebbbbccccccceeeeeeeaaaaaaaaabbbbbbdddddbbbbbbeeeeeeaaeeeaaa\n",
"output": "5\n"
},
{
"input": "abbabbaaabababaababaaaabababbbbaabaaaaaaaaaabbbbababababababababbabaaabbaaaaabaaaabaaaaababaabaabaab\n",
"output": "2\n"
},
{
"input": "aaabbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaabbbaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbaaaaaabbbbbbbbbbbbbaaaaa\n",
"output": "7\n"
},
{
"input": "aaaaaaacccccccccccccccccccbbaaaaaaaaabcccaaaaaaaaaabbccccaaaaaaaaaaccccaabbcccbbbbbbbbbbaaaaaaaaaaaa\n",
"output": "12\n"
},
{
"input": "aaaaaaaaaaa\n",
"output": "0\n"
},
{
"input": "ab\n",
"output": "1\n"
},
{
"input": "aaabbbbbbaaa\n",
"output": "3\n"
}
] | code_contests | python | 0 | afccf4f9a19a4643f7cb2b46841a94a8 |
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to <image>.
In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.
Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).
Input
The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard.
The second line of the input contains <image> integer numbers <image> (1 ≤ pi ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.
Output
Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.
Examples
Input
6
1 2 6
Output
2
Input
10
1 2 3 4 5
Output
10
Note
In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.
In the second example the possible strategy is to move <image> in 4 moves, then <image> in 3 moves, <image> in 2 moves and <image> in 1 move.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import re
import math
import decimal
import bisect
def read():
return input().strip()
n = int(read())
ps = [0 for i in range(1, n+1)]
nadd = 10
for x in sorted([int(_) for _ in read().split()]):
ps[x-1] = nadd
nadd += 10
nadd = 15
for i, p in enumerate(ps):
if p == 0:
ps[i] = nadd
nadd += 10
# print(ps)
swapped = True
swapsA = 0
workps = ps[:]
while swapped:
swapped = False
for i in range(n-1):
if workps[i] > workps[i+1]:
tmp = workps[i]
workps[i] = workps[i+1]
workps[i+1] = tmp
swapsA += 1
swapped = True
# print(ps, swapsA)
for i, p in enumerate(ps):
if p % 10 == 5:
ps[i] -= 10
swapped = True
swapsB = 0
workps = ps[:]
while swapped:
swapped = False
for i in range(n-1):
if workps[i] > workps[i+1]:
tmp = workps[i]
workps[i] = workps[i+1]
workps[i+1] = tmp
swapsB += 1
swapped = True
# print(ps, swapsB)
print(min(swapsA, swapsB))
| python | code_algorithm | [
{
"input": "10\n1 2 3 4 5\n",
"output": "10\n"
},
{
"input": "6\n1 2 6\n",
"output": "2\n"
},
{
"input": "10\n9 8 7 6 5\n",
"output": "7\n"
},
{
"input": "100\n41 13 29 11 25 15 6 23 28 50 48 17 3 9 44 24 5 19 34 22 33 32 20 16 35 37 4 10 46 2 39 40 47 49 36 42 1 30 43 21 14 7 18 45 31 8 12 26 27 38\n",
"output": "1225\n"
},
{
"input": "10\n10 9 8 1 5\n",
"output": "5\n"
},
{
"input": "6\n3 5 6\n",
"output": "2\n"
},
{
"input": "6\n1 4 5\n",
"output": "1\n"
},
{
"input": "100\n84 10 26 79 58 93 67 85 7 2 99 4 47 45 75 22 32 82 65 53 63 49 42 52 12 69 86 46 25 76 40 15 13 78 8 81 62 28 60 21 27 80 98 56 3 36 54 16 50 43\n",
"output": "104\n"
},
{
"input": "10\n5 6 7 8 9\n",
"output": "7\n"
},
{
"input": "96\n12 58 70 19 65 61 41 46 15 92 64 72 9 26 53 37 2 3 1 40 10 8 94 66 50 34 36 96 47 78 7 57 5 6 17 69 28 88 89 49 55 81 35 22 25 79 86 59\n",
"output": "152\n"
},
{
"input": "2\n2\n",
"output": "0\n"
},
{
"input": "10\n1 7 8 9 10\n",
"output": "7\n"
},
{
"input": "12\n1 7 8 9 10 12\n",
"output": "7\n"
},
{
"input": "24\n10 21 15 3 11 4 18 24 16 22 14 9\n",
"output": "11\n"
},
{
"input": "10\n6 7 8 9 10\n",
"output": "10\n"
},
{
"input": "50\n27 42 41 4 10 45 44 26 49 50 17 28 2 36 18 39 23 12 21 24 19 29 22 40 37\n",
"output": "59\n"
},
{
"input": "20\n1 2 3 4 5 6 7 8 9 10\n",
"output": "45\n"
},
{
"input": "6\n3 4 5\n",
"output": "2\n"
},
{
"input": "80\n41 70 18 53 32 79 51 49 21 27 47 65 50 15 62 60 5 40 14 25 64 9 19 58 38 76 66 52 17 34 13 2 80 43 3 42 33 36 6 72\n",
"output": "47\n"
},
{
"input": "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100\n",
"output": "0\n"
},
{
"input": "10\n1 4 6 8 10\n",
"output": "1\n"
},
{
"input": "10\n2 3 4 5 6\n",
"output": "7\n"
},
{
"input": "100\n9 63 62 88 3 67 54 33 79 51 71 80 37 46 43 57 69 17 34 6 18 40 59 83 76 86 8 55 90 89 45 42 28 98 30 38 77 91 73 58 23 61 41 65 64 93 14 44 16 24\n",
"output": "160\n"
},
{
"input": "100\n93 54 57 61 68 66 70 96 64 82 80 75 69 77 76 94 67 86 90 73 74 58 100 83 92 89 56 99 88 59 95 72 81 51 85 71 97 60 91 63 65 98 79 84 53 62 87 55 52 78\n",
"output": "1225\n"
},
{
"input": "6\n1 5 6\n",
"output": "2\n"
},
{
"input": "10\n1 6 7 8 9\n",
"output": "5\n"
},
{
"input": "20\n3 4 6 7 8 10 11 13 14 17\n",
"output": "15\n"
}
] | code_contests | python | 0.5 | 4d37cb6d21cd4f6293fa683d1bedf58d |
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d).
Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of coins that is necessary to obtain the value b_j using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value b_j, the answer to the j-th query is -1.
The queries are independent (the answer on the query doesn't affect Polycarp's coins).
Input
The first line of the input contains two integers n and q (1 ≤ n, q ≤ 2 ⋅ 10^5) — the number of coins and the number of queries.
The second line of the input contains n integers a_1, a_2, ..., a_n — values of coins (1 ≤ a_i ≤ 2 ⋅ 10^9). It is guaranteed that all a_i are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d).
The next q lines contain one integer each. The j-th line contains one integer b_j — the value of the j-th query (1 ≤ b_j ≤ 10^9).
Output
Print q integers ans_j. The j-th integer must be equal to the answer on the j-th query. If Polycarp can't obtain the value b_j the answer to the j-th query is -1.
Example
Input
5 4
2 4 8 2 4
8
5
14
10
Output
1
-1
3
2
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | # @oj: codeforces
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-10-14 16:44
# @url:https://codeforc.es/contest/1003/problem/D
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio
BUFSIZE = 8192
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
## 注意嵌套括号!!!!!!
## 先有思路,再写代码,别着急!!!
## 先有朴素解法,不要有思维定式,试着换思路解决
## 精度 print("%.10f" % ans)
def main():
n,q=map(int,input().split())
a=list(map(int,input().split()))
d=collections.Counter(a)
keys=sorted(d.keys(),reverse=True)
# print (keys,d)
for i in range(q):
ans=0
b=int(input())
for k in keys:
cnt=b//k
ans+=min(cnt,d[k])
b-=min(cnt,d[k])*k
# if cnt<=d[k]:
# ans+=cnt
# b-=cnt*k
# else:
# ans+=d[k]
# b-=d[k]*k
if b>0:
print (-1)
else:
print (ans)
if __name__ == "__main__":
main() | python | code_algorithm | [
{
"input": "5 4\n2 4 8 2 4\n8\n5\n14\n10\n",
"output": "1\n-1\n3\n2\n"
},
{
"input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n",
"output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\n-1\n-1\n"
},
{
"input": "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n",
"output": "-1\n-1\n-1\n1\n-1\n-1\n-1\n-1\n-1\n-1\n"
},
{
"input": "1 10\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n",
"output": "-1\n1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n"
},
{
"input": "1 10\n1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n",
"output": "1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n"
},
{
"input": "3 3\n1 1 1\n1\n2\n3\n",
"output": "1\n2\n3\n"
},
{
"input": "4 1\n2 4 16 32\n14\n",
"output": "-1\n"
}
] | code_contests | python | 0.4 | 7193468c361076f34d815dacacb28c00 |
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).
For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.
The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good.
Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to n - 1, but not the whole string). You need to calculate the minimum number of characters to be deleted from string s so that it becomes good.
Input
The first line contains one integer t (1 ≤ t ≤ 100) – the number of test cases. Each test case is represented by two lines.
The first line of i-th test case contains one integer n (1 ≤ n ≤ 100) – the length of string s.
The second line of i-th test case contains string s, consisting of only characters > and <.
Output
For each test case print one line.
For i-th test case print the minimum number of characters to be deleted from string s so that it becomes good.
Example
Input
3
2
<>
3
><<
1
>
Output
1
0
0
Note
In the first test case we can delete any character in string <>.
In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < → < < → <.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | t = int(input())
tests = []
for i in range(t):
length = int(input())
tests.append(input())
def solve(s):
streak1 = 0
streak2 = 0
for i in range(len(s)):
if s[i] == "<":
streak1 +=1
else:
break
for i in range(len(s)):
if s[-i-1] == ">":
streak2 +=1
else:
break
return min(streak1, streak2)
res = list(map(lambda x: str(solve(x)), tests))
print("\n".join(res)) | python | code_algorithm | [
{
"input": "3\n2\n<>\n3\n><<\n1\n>\n",
"output": "0\n0\n0\n"
},
{
"input": "1\n9\n>>>>>>>><\n",
"output": "0\n"
},
{
"input": "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n",
"output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"
},
{
"input": "14\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n<\n",
"output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"
},
{
"input": "3\n2\n<>\n3\n><<\n1\n>\n",
"output": "1\n0\n0\n"
}
] | code_contests | python | 0 | b52b25f748519ae107d8650ae97f27cc |
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swords. Note that the values x, y and z are unknown for you.
The next morning the director of the theater discovers the loss. He counts all swords — exactly a_i swords of the i-th type are left untouched.
The director has no clue about the initial number of swords of each type in the basement, the number of people who have broken into the basement and how many swords each of them have taken.
For example, if n=3, a = [3, 12, 6] then one of the possible situations is x=12, y=5 and z=3. Then the first three people took swords of the first type and the other two people took swords of the third type. Note that you don't know values x, y and z beforehand but know values of n and a.
Thus he seeks for your help. Determine the minimum number of people y, which could have broken into the theater basement, and the number of swords z each of them has taken.
Input
The first line of the input contains one integer n (2 ≤ n ≤ 2 ⋅ 10^{5}) — the number of types of swords.
The second line of the input contains the sequence a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^{9}), where a_i equals to the number of swords of the i-th type, which have remained in the basement after the theft. It is guaranteed that there exists at least one such pair of indices (j, k) that a_j ≠ a_k.
Output
Print two integers y and z — the minimum number of people which could have broken into the basement and the number of swords each of them has taken.
Examples
Input
3
3 12 6
Output
5 3
Input
2
2 9
Output
1 7
Input
7
2 1000000000 4 6 8 4 2
Output
2999999987 2
Input
6
13 52 0 13 26 52
Output
12 13
Note
In the first example the minimum value of y equals to 5, i.e. the minimum number of people who could have broken into the basement, is 5. Each of them has taken 3 swords: three of them have taken 3 swords of the first type, and two others have taken 3 swords of the third type.
In the second example the minimum value of y is 1, i.e. the minimum number of people who could have broken into the basement, equals to 1. He has taken 7 swords of the first type.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n= int(input())
s = list(map(int,input().split()))
s.sort()
maxm = s[n-1]
ans = 0
def computeGCD(x, y):
while(y):
x, y = y, x % y
return x
a = maxm-s[0]
for i in range(1,n-1):
a = computeGCD(a,maxm-s[i])
for i in range(0,n-1):
ans += maxm - s[i]
print(ans//a,a)
| python | code_algorithm | [
{
"input": "2\n2 9\n",
"output": "1 7\n"
},
{
"input": "3\n3 12 6\n",
"output": "5 3\n"
},
{
"input": "7\n2 1000000000 4 6 8 4 2\n",
"output": "2999999987 2\n"
},
{
"input": "6\n13 52 0 13 26 52\n",
"output": "12 13\n"
},
{
"input": "10\n100000000 200000000 300000000 20 500000000 600000000 700000000 800000000 900000000 1000000000\n",
"output": "244999999 20\n"
},
{
"input": "10\n1 1000000000 1 1 1 1 1 1 1 1\n",
"output": "9 999999999\n"
},
{
"input": "5\n0 0 1 0 0\n",
"output": "4 1\n"
},
{
"input": "10\n1000000000 1 2 3 4 5 6 7 8 9\n",
"output": "8999999955 1\n"
},
{
"input": "3\n1000000000 1 1000000000\n",
"output": "1 999999999\n"
}
] | code_contests | python | 1 | 08a50eab51107db49012aaaf35c92a34 |
Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick.
Each tool can be sold for exactly one emerald. How many emeralds can Polycarp earn, if he has a sticks and b diamonds?
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.
The only line of each test case contains two integers a and b (0 ≤ a, b ≤ 10^9) — the number of sticks and the number of diamonds, respectively.
Output
For each test case print one integer — the maximum number of emeralds Polycarp can earn.
Example
Input
4
4 4
1000000000 0
7 15
8 7
Output
2
0
7
5
Note
In the first test case Polycarp can earn two emeralds as follows: craft one sword and one shovel.
In the second test case Polycarp does not have any diamonds, so he cannot craft anything.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import math
t=int(input())
for i in range(t):
a,b=map(int,input().split())
m=min(a,b,(a+b)/3)
print(math.floor(m))
| python | code_algorithm | [
{
"input": "4\n4 4\n1000000000 0\n7 15\n8 7\n",
"output": "2\n0\n7\n5\n"
},
{
"input": "1\n656 656\n",
"output": "437\n"
},
{
"input": "1\n666 666\n",
"output": "444\n"
},
{
"input": "2\n7 4\n1 5\n",
"output": "3\n1\n"
},
{
"input": "1\n33993 5\n",
"output": "5\n"
},
{
"input": "1\n1656 5\n",
"output": "5\n"
},
{
"input": "1\n1319 1777\n",
"output": "1032\n"
},
{
"input": "1\n667 666\n",
"output": "444\n"
}
] | code_contests | python | 0.9 | b8b09c2039ef818ff11b86db3bf1012e |
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.
<image>
For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8 + 3 + 6 + 7 = 24, sum of its row numbers equals 9 + 5 + 3 + 2 = 19, and 24 > 19.
Input
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.
Output
Print the single number — the number of the winning squares.
Examples
Input
1
1
Output
0
Input
2
1 2
3 4
Output
2
Input
4
5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3
Output
6
Note
In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning:
5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
r = lambda : list(map(int, input().split()))
arr = []
for i in range(n):
a = r()
arr.append(a)
row = [sum(i) for i in arr]
col = []
for i in range(n):
c = 0
for j in range(n): c+=arr[j][i]
col.append(c)
ans = 0
for i in range(n):
for j in range(n):
if row[i] < col[j]: ans+=1
print(ans)
| python | code_algorithm | [
{
"input": "1\n1\n",
"output": "0\n"
},
{
"input": "2\n1 2\n3 4\n",
"output": "2\n"
},
{
"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n",
"output": "6\n"
},
{
"input": "9\n53 80 94 41 58 49 88 24 42\n85 11 32 64 40 56 63 95 73\n17 85 60 41 13 71 54 67 87\n38 14 21 81 66 59 52 33 86\n29 34 46 18 19 80 10 44 51\n4 27 65 75 77 21 15 49 50\n35 68 86 98 98 62 69 52 71\n43 28 56 91 89 21 14 57 79\n27 27 29 26 15 76 21 70 78\n",
"output": "40\n"
},
{
"input": "4\n89 79 14 89\n73 24 58 89\n62 88 69 65\n58 92 18 83\n",
"output": "10\n"
},
{
"input": "4\n1 2 3 4\n8 7 6 5\n9 10 11 12\n16 15 14 13\n",
"output": "8\n"
},
{
"input": "1\n31\n",
"output": "0\n"
},
{
"input": "1\n53\n",
"output": "0\n"
},
{
"input": "5\n42 74 45 85 14\n68 94 11 3 89\n68 67 97 62 66\n65 76 96 18 84\n61 98 28 94 74\n",
"output": "12\n"
},
{
"input": "1\n92\n",
"output": "0\n"
},
{
"input": "9\n33 80 34 56 56 33 27 74 57\n14 69 78 44 56 70 26 73 47\n13 42 17 33 78 83 94 70 37\n96 78 92 6 16 68 8 31 46\n67 97 21 10 44 64 15 77 28\n34 44 83 96 63 52 29 27 79\n23 23 57 54 35 16 5 64 36\n29 71 36 78 47 81 72 97 36\n24 83 70 58 36 82 42 44 26\n",
"output": "41\n"
},
{
"input": "5\n61 45 70 19 48\n52 29 98 21 74\n21 66 12 6 55\n62 75 66 62 57\n94 74 9 86 24\n",
"output": "13\n"
},
{
"input": "2\n7 3\n9 5\n",
"output": "2\n"
},
{
"input": "5\n99 77 32 20 49\n93 81 63 7 58\n37 1 17 35 53\n18 94 38 80 23\n91 50 42 61 63\n",
"output": "12\n"
},
{
"input": "7\n62 73 50 63 66 92 2\n27 13 83 84 88 81 47\n60 41 25 2 68 32 60\n7 94 18 98 41 25 72\n69 37 4 10 82 49 91\n76 26 67 27 30 49 18\n44 78 6 1 41 94 80\n",
"output": "26\n"
},
{
"input": "2\n1 1\n1 1\n",
"output": "0\n"
},
{
"input": "3\n1 2 3\n1 1 1\n1 1 1\n",
"output": "4\n"
},
{
"input": "5\n23 70 5 36 69\n83 18 19 98 40\n84 91 18 51 35\n17 18 35 47 59\n29 72 35 87 27\n",
"output": "13\n"
},
{
"input": "3\n1 2 3\n4 5 6\n7 8 9\n",
"output": "4\n"
},
{
"input": "12\n8 42 23 20 39 5 23 86 26 65 93 82\n48 35 12 4 59 19 19 28 38 81 97 99\n93 24 31 44 97 50 44 99 50 7 10 64\n79 43 65 29 84 43 46 41 89 16 6 1\n34 90 33 1 7 12 46 84 67 30 1 58\n58 21 100 66 56 22 7 24 72 73 86 37\n2 17 85 6 2 73 85 44 43 79 34 65\n3 53 29 76 87 2 27 19 11 42 71 38\n69 82 73 52 44 23 92 10 13 72 59 16\n73 32 37 93 21 94 43 39 27 53 14 15\n86 16 90 91 14 50 73 61 77 36 93 90\n22 56 30 52 81 70 12 92 75 27 38 12\n",
"output": "77\n"
},
{
"input": "5\n1 98 22 9 39\n10 9 44 49 66\n79 17 23 8 47\n59 69 72 47 14\n94 91 98 19 54\n",
"output": "13\n"
},
{
"input": "5\n4 91 100 8 48\n78 56 61 49 83\n12 21 95 77 78\n40 20 91 79 25\n32 88 94 28 55\n",
"output": "10\n"
},
{
"input": "7\n80 81 45 81 72 19 65\n31 24 15 52 47 1 14\n81 35 42 24 96 59 46\n16 2 59 56 60 98 76\n20 95 10 68 68 56 93\n60 16 68 77 89 52 43\n11 22 43 36 99 2 11\n",
"output": "21\n"
},
{
"input": "3\n4 3 2\n2 2 2\n2 2 2\n",
"output": "4\n"
},
{
"input": "5\n77 44 22 21 20\n84 3 35 86 35\n97 50 1 44 92\n4 88 56 20 3\n32 56 26 17 80\n",
"output": "13\n"
},
{
"input": "9\n40 70 98 28 44 78 15 73 20\n25 74 46 3 27 59 33 96 19\n100 47 99 68 68 67 66 87 31\n26 39 8 91 58 20 91 69 81\n77 43 90 60 17 91 78 85 68\n41 46 47 50 96 18 69 81 26\n10 58 2 36 54 64 69 10 65\n6 86 26 7 88 20 43 92 59\n61 76 13 23 49 28 22 79 8\n",
"output": "44\n"
},
{
"input": "3\n1 2 3\n3 1 2\n2 3 1\n",
"output": "0\n"
},
{
"input": "3\n41 94 58\n73 61 8\n34 88 89\n",
"output": "5\n"
},
{
"input": "8\n44 74 25 81 32 33 55 58\n36 13 28 28 20 65 87 58\n8 35 52 59 34 15 33 16\n2 22 42 29 11 66 30 72\n33 47 8 61 31 64 59 63\n79 36 38 42 12 21 92 36\n56 47 44 6 6 1 37 2\n79 88 79 53 50 69 94 39\n",
"output": "31\n"
},
{
"input": "2\n73 99\n13 100\n",
"output": "2\n"
},
{
"input": "4\n81 100 38 54\n8 64 39 59\n6 12 53 65\n79 50 99 71\n",
"output": "8\n"
},
{
"input": "9\n57 70 94 69 77 59 88 63 83\n6 79 46 5 9 43 20 39 48\n46 35 58 22 17 3 81 82 34\n77 10 40 53 71 84 14 58 56\n6 92 77 81 13 20 77 29 40\n59 53 3 97 21 97 22 11 64\n52 91 82 20 6 3 99 17 44\n79 25 43 69 85 55 95 61 31\n89 24 50 84 54 93 54 60 87\n",
"output": "46\n"
}
] | code_contests | python | 0.9 | 88077015b9c347c80a1bc37000f6869d |
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves.
One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0).
You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n).
Input
The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces.
The input limitations for getting 20 points are:
* 1 ≤ n ≤ 300
The input limitations for getting 50 points are:
* 1 ≤ n ≤ 2000
The input limitations for getting 100 points are:
* 1 ≤ n ≤ 105
Output
Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero.
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.
Examples
Input
4
1 0 1 2
Output
1
1
3
Input
8
1 2 3 4 5 6 7 8
Output
1
3
6
10
16
24
40
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
a = [int(t) for t in input().split()]
c = 0
for i in range(n - 1):
if a[i] > 0:
c += a[i]
print(c)
j = 0
while 2 ** j + i < n:
j += 1
a[2 ** (j - 1) + i] += a[i]
a[i] = 0
else:
print(c) | python | code_algorithm | [
{
"input": "8\n1 2 3 4 5 6 7 8\n",
"output": "1\n3\n6\n10\n16\n24\n40\n"
},
{
"input": "4\n1 0 1 2\n",
"output": "1\n1\n3\n"
},
{
"input": "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 24 58 11 85 73 18 4 45 90 99 42 85 26 71 58 49 76 32 88 13 40 98 57 95 20 36 70 66 75 12 54 96\n",
"output": "72\n138\n220\n266\n310\n332\n395\n487\n558\n623\n628\n658\n703\n787\n816\n889\n898\n988\n1013\n1032\n1058\n1073\n1085\n1114\n1147\n1166\n1251\n1343\n1434\n1500\n1583\n1622\n1722\n1775\n1795\n1894\n1905\n1986\n2012\n2053\n2089\n2140\n2161\n2233\n2261\n2361\n2395\n2398\n2431\n2579\n2615\n2719\n2818\n2851\n2867\n2941\n3064\n3182\n3309\n3486\n3603\n3740\n3881\n3969\n4250\n4549\n4775\n5037\n5231\n5465\n5627\n5929\n6460\n7029\n7478\n8085\n9075\n10211\n12070\n"
},
{
"input": "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 24 58 11 85 73 18 4 45 90 99 42 85 26 71 58 49 76 32 88 13 40 98 57 95 20 36 70 66 75 12 54 96\n",
"output": "72\n138\n220\n266\n310\n332\n395\n487\n558\n623\n628\n658\n703\n787\n816\n889\n898\n988\n1013\n1032\n1058\n1073\n1085\n1114\n1147\n1166\n1251\n1343\n1434\n1500\n1583\n1622\n1722\n1775\n1795\n1894\n1905\n1986\n2012\n2053\n2089\n2140\n2161\n2233\n2261\n2361\n2395\n2398\n2431\n2579\n2615\n2719\n2818\n2851\n2867\n2941\n3064\n3182\n3309\n3486\n3603\n3740\n3881\n3969\n4250\n4549\n4775\n5037\n5231\n5465\n5627\n5929\n6460\n7029\n7478\n8085\n9075\n10211\n12070\n"
},
{
"input": "30\n8 17 20 15 18 15 20 10 5 13 5 4 15 9 11 14 18 15 7 16 18 9 17 7 10 9 5 13 17 16\n",
"output": "8\n25\n45\n60\n78\n93\n113\n123\n128\n141\n146\n150\n165\n174\n185\n199\n225\n257\n284\n315\n351\n375\n423\n454\n495\n549\n634\n713\n907\n"
},
{
"input": "5\n4 1 4 7 6\n",
"output": "4\n5\n9\n17\n"
},
{
"input": "9\n13 13 7 11 3 9 3 5 5\n",
"output": "13\n26\n33\n44\n47\n69\n79\n117\n"
},
{
"input": "120\n242 524 420 973 816 432 247 666 134 849 145 366 608 930 613 315 863 628 97 109 65 704 741 314 736 17 872 971 559 648 223 771 171 327 782 837 303 393 292 339 730 834 794 868 540 251 789 893 23 305 116 220 699 863 580 992 861 393 98 253 544 171 336 207 348 496 316 285 286 727 613 616 304 811 592 916 91 554 962 950 475 473 806 510 986 254 290 351 143 710 573 949 256 216 235 246 533 177 12 764 543 689 490 386 849 694 386 693 134 416 293 589 171 76 527 324 782 661 943 134\n",
"output": "242\n766\n1186\n2159\n2975\n3407\n3654\n4320\n4454\n5303\n5448\n5814\n6422\n7352\n7965\n8280\n9143\n9771\n9868\n9977\n10042\n10746\n11487\n11801\n12537\n12554\n13426\n14397\n14956\n15604\n15827\n16598\n16769\n17096\n17878\n18715\n19018\n19411\n19703\n20042\n20772\n21606\n22400\n23268\n23808\n24059\n24848\n25741\n25764\n26069\n26185\n26405\n27104\n27967\n28547\n29539\n30400\n30793\n30891\n31144\n31688\n31859\n32195\n32402\n32992\n34012\n34748\n36006\n37108\n38267\n39127\n40409\n40847\n42507\n43244\n44526\n45225\n46709\n48284\n49549\n50887\n51988\n52891\n53510\n54561\n55519\n56550\n57215\n58955\n60075\n61618\n63791\n65150\n66185\n66979\n68203\n69497\n71021\n72551\n75410\n77358\n79599\n81241\n83248\n87005\n91313\n94773\n99789\n102521\n105707\n109158\n113129\n119712\n127026\n133562\n142600\n156395\n171618\n199596\n"
}
] | code_contests | python | 0.2 | 043f64ecc6672429ce73691532d7cb26 |
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds t.
Input
The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
The numbers in the lines are separated by single spaces.
Output
In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Examples
Input
5
0 1
1 0
0 1
1 1
0 1
Output
3
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | k = int(input())
lo=ro=rc=lc=0
for _ in range(k):
n , m = map(int,input().split())
if(n==0):
lo+=1
else:
lc=lc+1
if(m==0):
ro+=1
else :
rc=rc+1
print(min(lo,lc)+min(ro,rc))
| python | code_algorithm | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1\n",
"output": "3\n"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0\n",
"output": "7\n"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1\n",
"output": "6\n"
},
{
"input": "2\n0 0\n0 0\n",
"output": "0\n"
},
{
"input": "3\n0 1\n1 1\n1 1\n",
"output": "1\n"
},
{
"input": "5\n1 0\n1 0\n1 0\n0 1\n0 1\n",
"output": "4\n"
},
{
"input": "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n",
"output": "0\n"
}
] | code_contests | python | 0.9 | 2bacf8b7f1c4b3d874f27f3c8caf42e7 |
There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step.
You're given the initial arrangement of the psychos in the line. Calculate how many steps are needed to the moment of time such, that nobody kills his neighbor after that moment. Look notes to understand the statement more precise.
Input
The first line of input contains integer n denoting the number of psychos, (1 ≤ n ≤ 105). In the second line there will be a list of n space separated distinct integers each in range 1 to n, inclusive — ids of the psychos in the line from left to right.
Output
Print the number of steps, so that the line remains the same afterward.
Examples
Input
10
10 9 7 8 6 5 3 4 2 1
Output
2
Input
6
1 2 3 4 5 6
Output
0
Note
In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1] → [10 8 4] → [10]. So, there are two steps.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, t = int(input()), list(map(int, input().split()))
p, s, r = [0] * n, [0] * n, t[0]
for i in range(n - 1):
j = i + 1
x = t[j]
if x > r: r = x
else:
while t[i] < x: s[j], i = max(s[j], s[i]), p[i]
p[j] = i
s[j] += 1
print(max(s))
# Made By Mostafa_Khaled | python | code_algorithm | [
{
"input": "6\n1 2 3 4 5 6\n",
"output": "0\n"
},
{
"input": "10\n10 9 7 8 6 5 3 4 2 1\n",
"output": "2\n"
},
{
"input": "2\n1 2\n",
"output": "0\n"
},
{
"input": "100\n61 96 25 10 50 71 38 77 76 75 59 100 89 66 6 99 2 13 3 23 91 93 22 92 4 86 90 44 39 31 9 47 28 95 18 54 1 73 94 78 60 20 42 84 97 83 16 81 67 64 74 46 82 5 88 80 14 48 53 79 30 11 62 21 41 70 63 58 51 56 57 17 87 72 27 85 68 49 52 8 12 98 43 37 35 69 55 32 26 40 29 65 19 24 34 33 15 45 36 7\n",
"output": "8\n"
},
{
"input": "1\n1\n",
"output": "0\n"
},
{
"input": "6\n6 5 4 3 2 1\n",
"output": "1\n"
},
{
"input": "15\n15 9 5 10 7 11 14 6 2 3 12 1 8 13 4\n",
"output": "4\n"
},
{
"input": "2\n2 1\n",
"output": "1\n"
},
{
"input": "10\n10 7 4 2 5 8 9 6 3 1\n",
"output": "4\n"
}
] | code_contests | python | 0.4 | d16648603970d0f4c311bc0ec410e99c |
A chessboard n × m in size is given. During the zero minute we repaint all the black squares to the 0 color. During the i-th minute we repaint to the i color the initially black squares that have exactly four corner-adjacent squares painted i - 1 (all such squares are repainted simultaneously). This process continues ad infinitum. You have to figure out how many squares we repainted exactly x times.
The upper left square of the board has to be assumed to be always black. Two squares are called corner-adjacent, if they have exactly one common point.
Input
The first line contains integers n and m (1 ≤ n, m ≤ 5000). The second line contains integer x (1 ≤ x ≤ 109).
Output
Print how many squares will be painted exactly x times.
Examples
Input
3 3
1
Output
4
Input
3 3
2
Output
1
Input
1 1
1
Output
1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import itertools
import math
n, m = [int(k) for k in input().split()]
x = int(input())
if n-2*(x-1) < 1 or m-2*(x-1) < 1:
print(0)
elif n-2*(x-1) == 1 or m-2*(x-1) == 1:
print((n+m-4*(x-1))//2)
else: print(n+m-2 - 4*(x-1))
| python | code_algorithm | [
{
"input": "1 1\n1\n",
"output": "1\n"
},
{
"input": "3 3\n2\n",
"output": "1\n"
},
{
"input": "3 3\n1\n",
"output": "4\n"
},
{
"input": "2016 4549\n433\n",
"output": "4835\n"
},
{
"input": "5000 1\n3\n",
"output": "0\n"
},
{
"input": "4035 369\n26\n",
"output": "4302\n"
},
{
"input": "1595 2881\n710\n",
"output": "1638\n"
},
{
"input": "3762 3914\n1073\n",
"output": "3386\n"
},
{
"input": "4583 2774\n1206\n",
"output": "2535\n"
},
{
"input": "10 10\n1\n",
"output": "18\n"
},
{
"input": "1812 240\n9\n",
"output": "2018\n"
},
{
"input": "991 2301\n291\n",
"output": "2130\n"
},
{
"input": "3154 527\n112\n",
"output": "3235\n"
},
{
"input": "1353 2988\n589\n",
"output": "1987\n"
},
{
"input": "4999 1\n7\n",
"output": "0\n"
},
{
"input": "3432 4788\n1203\n",
"output": "3410\n"
},
{
"input": "3990 1800\n171\n",
"output": "5108\n"
},
{
"input": "5000 5000\n1000000000\n",
"output": "0\n"
},
{
"input": "182 2314\n54\n",
"output": "2282\n"
},
{
"input": "3042 1798\n93\n",
"output": "4470\n"
},
{
"input": "4892 712\n340\n",
"output": "4246\n"
},
{
"input": "2089 955\n476\n",
"output": "1142\n"
},
{
"input": "419 4046\n174\n",
"output": "3771\n"
},
{
"input": "2714 607\n189\n",
"output": "2567\n"
},
{
"input": "4847 2143\n827\n",
"output": "3684\n"
},
{
"input": "3287 2915\n538\n",
"output": "4052\n"
},
{
"input": "3458 2220\n526\n",
"output": "3576\n"
},
{
"input": "873 744\n42\n",
"output": "1451\n"
},
{
"input": "4643 3755\n1381\n",
"output": "2876\n"
},
{
"input": "3552 3036\n199\n",
"output": "5794\n"
},
{
"input": "1 4999\n2309\n",
"output": "0\n"
},
{
"input": "1662 926\n452\n",
"output": "782\n"
},
{
"input": "1444 2646\n660\n",
"output": "1452\n"
},
{
"input": "9 10\n1\n",
"output": "17\n"
},
{
"input": "188 3759\n53\n",
"output": "3737\n"
},
{
"input": "2470 4895\n421\n",
"output": "5683\n"
},
{
"input": "7 7\n777\n",
"output": "0\n"
},
{
"input": "4339 2062\n462\n",
"output": "4555\n"
},
{
"input": "1043 49\n10\n",
"output": "1054\n"
},
{
"input": "2813 3911\n560\n",
"output": "4486\n"
},
{
"input": "293 2183\n60\n",
"output": "2238\n"
},
{
"input": "10 10\n3\n",
"output": "10\n"
},
{
"input": "3663 2904\n1149\n",
"output": "1973\n"
},
{
"input": "10 10\n2\n",
"output": "14\n"
},
{
"input": "4202 3834\n1478\n",
"output": "2126\n"
},
{
"input": "126 4125\n52\n",
"output": "4045\n"
},
{
"input": "2504 973\n201\n",
"output": "2675\n"
},
{
"input": "10 10\n5\n",
"output": "2\n"
},
{
"input": "3122 1850\n201\n",
"output": "4170\n"
},
{
"input": "3595 448\n110\n",
"output": "3605\n"
},
{
"input": "1 1\n200\n",
"output": "0\n"
},
{
"input": "10 10\n4\n",
"output": "6\n"
},
{
"input": "3899 2141\n428\n",
"output": "4330\n"
},
{
"input": "4273 4835\n159\n",
"output": "8474\n"
},
{
"input": "3385 4978\n192\n",
"output": "7597\n"
},
{
"input": "1922 109\n41\n",
"output": "1869\n"
},
{
"input": "10 9\n4\n",
"output": "5\n"
},
{
"input": "1755 2051\n1\n",
"output": "3804\n"
},
{
"input": "2793 4840\n901\n",
"output": "4031\n"
},
{
"input": "3250 2992\n127\n",
"output": "5736\n"
},
{
"input": "2828 4208\n912\n",
"output": "3390\n"
},
{
"input": "1 5000\n3\n",
"output": "0\n"
},
{
"input": "8 8\n8\n",
"output": "0\n"
},
{
"input": "1 4999\n1000000\n",
"output": "0\n"
},
{
"input": "892 3996\n288\n",
"output": "3738\n"
},
{
"input": "837 4874\n208\n",
"output": "4881\n"
},
{
"input": "9 9\n3\n",
"output": "8\n"
},
{
"input": "2738 718\n308\n",
"output": "2226\n"
},
{
"input": "4275 240\n16\n",
"output": "4453\n"
},
{
"input": "4694 685\n208\n",
"output": "4549\n"
}
] | code_contests | python | 0 | 2a0d736e185c39854f07d5f7f1b16d91 |
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 vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk 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
The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi).
Consider all the parts are numbered from 1 to n.
Output
Output the minimum total energy the child should spend to remove all n parts of the toy.
Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
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.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def main():
n,m = LI()
a = LI()
aa = [LI_() for _ in range(m)]
r = 0
for b,c in aa:
r += min(a[b], a[c])
return r
print(main())
| python | code_algorithm | [
{
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"output": "400\n"
},
{
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"output": "40\n"
},
{
"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\n",
"output": "160\n"
},
{
"input": "1 0\n23333\n",
"output": "0\n"
},
{
"input": "3 3\n1 1 1\n1 2\n2 3\n3 1\n",
"output": "3\n"
},
{
"input": "5 4\n1 2 2 2 2\n1 2\n1 3\n1 4\n1 5\n",
"output": "4\n"
},
{
"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\n",
"output": "188\n"
}
] | code_contests | python | 0.2 | 07d8462047c243442e07264c93533486 |
You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.
Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.
A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.
Input
The only line contains four positive integers cnt1, cnt2, x, y (1 ≤ cnt1, cnt2 < 109; cnt1 + cnt2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 1 2 3
Output
5
Input
1 3 2 3
Output
4
Note
In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | c1,c2,x,y=map(int,input().split())
def fn(val):
f=[val//x,val//y]
both=val//(x*y)
f=[i-both for i in f]
oth=val-f[0]-f[1]-both
cnt=[c1-f[1],c2-f[0]]
if cnt[0]<0:cnt[0]=0
if cnt[1] < 0: cnt[1] = 0
return (sum(cnt)<=oth)
l=0;r=int(1e18)
while r-l>1:
m=(r+l)//2
if fn(m):
r=m
else:l=m
print(r) | python | code_algorithm | [
{
"input": "3 1 2 3\n",
"output": "5\n"
},
{
"input": "1 3 2 3\n",
"output": "4\n"
},
{
"input": "1 999999999 29983 29989\n",
"output": "1000033345\n"
},
{
"input": "9999999 10000 29983 29989\n",
"output": "10009999\n"
},
{
"input": "808351 17767 433 509\n",
"output": "826121\n"
},
{
"input": "197 2 6361 18223\n",
"output": "199\n"
},
{
"input": "5099 2895 16273 29473\n",
"output": "7994\n"
},
{
"input": "500000000 500000000 2 3\n",
"output": "1199999999\n"
},
{
"input": "1000 9999999 29983 29989\n",
"output": "10000999\n"
},
{
"input": "1277613 596606 10427 29387\n",
"output": "1874219\n"
},
{
"input": "26941620 135675892 4093 28979\n",
"output": "162617513\n"
},
{
"input": "39 154 1033 18947\n",
"output": "193\n"
},
{
"input": "126 51 26249 29443\n",
"output": "177\n"
},
{
"input": "14797 3593 13147 13933\n",
"output": "18390\n"
},
{
"input": "2 1 2 3\n",
"output": "3\n"
},
{
"input": "500000000 500000000 29983 29989\n",
"output": "1000000001\n"
},
{
"input": "1513389 40825 5641 10009\n",
"output": "1554214\n"
},
{
"input": "1 999999999 2 3\n",
"output": "1499999998\n"
},
{
"input": "14 179 19699 29303\n",
"output": "193\n"
},
{
"input": "8851 901 20897 26183\n",
"output": "9752\n"
},
{
"input": "159606 875491 43 19121\n",
"output": "1035098\n"
},
{
"input": "1 2 29983 29989\n",
"output": "3\n"
},
{
"input": "11006 976 6287 9007\n",
"output": "11982\n"
},
{
"input": "1 2 2 3\n",
"output": "3\n"
},
{
"input": "110 40 1567 7681\n",
"output": "150\n"
},
{
"input": "325832598 637961741 2 3\n",
"output": "1156553206\n"
},
{
"input": "9156260 174697920 8171 29863\n",
"output": "183854180\n"
},
{
"input": "150064728 173287472 439 503\n",
"output": "323353664\n"
},
{
"input": "139694297 21147406 8819 28499\n",
"output": "160841703\n"
},
{
"input": "819712074 101394406 6173 7307\n",
"output": "921106500\n"
},
{
"input": "500000000 500000000 29959 29983\n",
"output": "1000000001\n"
},
{
"input": "191370899 1962652 3517 24023\n",
"output": "193333553\n"
},
{
"input": "999999998 2 2 3\n",
"output": "1999999995\n"
},
{
"input": "10876 8828 12487 16607\n",
"output": "19704\n"
},
{
"input": "683651932 161878530 2 5\n",
"output": "1367303863\n"
},
{
"input": "782 5750 7079 23957\n",
"output": "6532\n"
},
{
"input": "1 1 2 3\n",
"output": "2\n"
},
{
"input": "999999999 1 2 3\n",
"output": "1999999997\n"
},
{
"input": "916200 69682 2 3\n",
"output": "1832399\n"
},
{
"input": "67462086 313228052 15131 29027\n",
"output": "380690138\n"
},
{
"input": "78618222 88031575 28289 29023\n",
"output": "166649797\n"
},
{
"input": "1749165 72848 9743 20023\n",
"output": "1822013\n"
},
{
"input": "16860 2201 6427 23327\n",
"output": "19061\n"
},
{
"input": "999999998 1 2 3\n",
"output": "1999999995\n"
},
{
"input": "999999999 1 29983 29989\n",
"output": "1000033352\n"
},
{
"input": "954386 580262 4993 15629\n",
"output": "1534648\n"
},
{
"input": "1 1 29983 29989\n",
"output": "2\n"
},
{
"input": "4969 694 293 2347\n",
"output": "5663\n"
},
{
"input": "4901 563 1997 15053\n",
"output": "5464\n"
}
] | code_contests | python | 0 | 2115b4932a146c78cf16e22bcce77ce9 |
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input
Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 105, - 105 ≤ x, y, x', y' ≤ 105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Examples
Input
2 0 0 0 4
Output
1
Input
1 1 1 4 4
Output
3
Input
4 5 6 5 6
Output
0
Note
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<image>
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import math #.sqrt
def ceil (a, b):
return -(-a // b)
def answer(r, x, y, xp, yp):
d = math.sqrt((xp-x)**2 + (yp-y)**2)
num_rs = ceil(d, 2*r)
return int(num_rs)
def main():
r, x, y, xp, yp = [int(i) for i in input().split()]
print(answer(r, x, y, xp, yp))
return
main() | python | code_algorithm | [
{
"input": "1 1 1 4 4\n",
"output": "3\n"
},
{
"input": "2 0 0 0 4\n",
"output": "1\n"
},
{
"input": "4 5 6 5 6\n",
"output": "0\n"
},
{
"input": "1 100000 100000 100000 -100000\n",
"output": "100000\n"
},
{
"input": "46456 -2621 -23623 -98302 -99305\n",
"output": "2\n"
},
{
"input": "9 20 0 40 0\n",
"output": "2\n"
},
{
"input": "100000 -100000 -100000 100000 100000\n",
"output": "2\n"
},
{
"input": "5 6 3 7 2\n",
"output": "1\n"
},
{
"input": "97741 23818 78751 97583 26933\n",
"output": "1\n"
},
{
"input": "99125 26876 -21414 14176 17443\n",
"output": "1\n"
},
{
"input": "56767 -29030 51625 79823 -56297\n",
"output": "2\n"
},
{
"input": "125 455 450 439 721\n",
"output": "2\n"
},
{
"input": "1 -3 3 2 6\n",
"output": "3\n"
},
{
"input": "8066 7339 19155 -90534 -60666\n",
"output": "8\n"
},
{
"input": "10 20 0 41 0\n",
"output": "2\n"
},
{
"input": "1 3 4 2 5\n",
"output": "1\n"
},
{
"input": "67377 -80131 -90254 -57320 14102\n",
"output": "1\n"
},
{
"input": "4 100000 -100000 100000 -99999\n",
"output": "1\n"
},
{
"input": "25 -64 -6 -56 64\n",
"output": "2\n"
},
{
"input": "100 100000 -100000 100000 -99999\n",
"output": "1\n"
},
{
"input": "25 96 13 7 2\n",
"output": "2\n"
},
{
"input": "24 130 14786 3147 2140\n",
"output": "271\n"
},
{
"input": "8 0 0 0 32\n",
"output": "2\n"
},
{
"input": "5 -1 -6 -5 1\n",
"output": "1\n"
},
{
"input": "2 7 20 13 -5\n",
"output": "7\n"
},
{
"input": "10 20 0 40 0\n",
"output": "1\n"
},
{
"input": "100000 100000 1 -100000 0\n",
"output": "2\n"
},
{
"input": "98260 13729 74998 23701 9253\n",
"output": "1\n"
},
{
"input": "125 -363 176 93 330\n",
"output": "2\n"
},
{
"input": "19312 19470 82059 58064 62231\n",
"output": "2\n"
},
{
"input": "67398 -68747 -79056 -34193 29400\n",
"output": "1\n"
},
{
"input": "1 14 30 30 14\n",
"output": "12\n"
},
{
"input": "1 100000 -100000 100000 -100000\n",
"output": "0\n"
},
{
"input": "249 -54242 -30537 -45023 -89682\n",
"output": "121\n"
},
{
"input": "91099 37184 -71137 75650 -3655\n",
"output": "1\n"
},
{
"input": "1 1 1 1 4\n",
"output": "2\n"
},
{
"input": "4 100000 -100000 100000 -100000\n",
"output": "0\n"
}
] | code_contests | python | 0.5 | c4710dd176f3139447812234ab2bf8de |
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 → 2 → 4 → 5.
In one second, you can perform one of the two following operations:
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 → 2 → ... → n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 ≤ n ≤ 105) and k (1 ≤ k ≤ 105) — the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 ≤ mi ≤ n), and then mi numbers ai1, ai2, ..., aimi — the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
Note
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, m = [int(x) for x in input().split()]
a = []
for i in range(m):
a.append([int(x) for x in input().split()][1:])
b = []
curt = 0
for i in a:
j = 0
b.append([])
while (j < len(i)) and (i[j] == (j + 1)):
j += 1
if j != 0:
b[-1] = [j]
b[-1] += [1] * (len(i) - j)
curt += len(b[-1])
fin = curt - 1
#print(b)
for i in b:
fin += len(i) - 1
print(fin)
| python | code_algorithm | [
{
"input": "3 2\n2 1 2\n1 3\n",
"output": "1\n"
},
{
"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6\n",
"output": "10\n"
},
{
"input": "100 3\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\n26 10 11 15 18 23 29 31 33 36 38 44 49 54 56 60 62 65 75 78 82 83 84 95 96 97 98\n29 12 13 14 16 17 20 22 25 26 32 45 50 53 57 67 68 70 72 73 74 77 79 81 87 90 91 92 93 100\n",
"output": "180\n"
},
{
"input": "3 2\n1 2\n2 1 3\n",
"output": "3\n"
},
{
"input": "13 8\n1 5\n2 8 10\n1 13\n4 1 2 3 11\n1 7\n2 6 12\n1 4\n1 9\n",
"output": "13\n"
},
{
"input": "1 1\n1 1\n",
"output": "0\n"
},
{
"input": "100 19\n6 62 72 83 91 94 97\n3 61 84 99\n1 63\n5 46 53 56 69 78\n5 41 43 49 74 89\n5 55 57 79 85 87\n3 47 59 98\n3 64 76 82\n3 48 66 75\n2 60 88\n2 67 77\n4 40 51 73 95\n41 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 44 71 81\n4 58 65 90 93\n1 100\n5 39 45 52 80 86\n2 50 68\n1 92\n4 42 54 70 96\n",
"output": "106\n"
},
{
"input": "20 6\n3 8 9 13\n3 4 14 20\n2 15 17\n3 2 5 11\n5 7 10 12 18 19\n4 1 3 6 16\n",
"output": "33\n"
},
{
"input": "5 3\n1 4\n3 1 2 3\n1 5\n",
"output": "2\n"
},
{
"input": "50 50\n1 2\n1 5\n1 28\n1 46\n1 42\n1 24\n1 3\n1 37\n1 33\n1 50\n1 23\n1 40\n1 43\n1 26\n1 49\n1 34\n1 8\n1 45\n1 15\n1 1\n1 22\n1 18\n1 27\n1 25\n1 13\n1 39\n1 38\n1 10\n1 44\n1 6\n1 17\n1 47\n1 7\n1 35\n1 20\n1 36\n1 31\n1 21\n1 32\n1 29\n1 4\n1 12\n1 19\n1 16\n1 11\n1 41\n1 9\n1 14\n1 30\n1 48\n",
"output": "49\n"
},
{
"input": "50 10\n6 17 21 31 42 45 49\n6 11 12 15 22 26 38\n3 9 29 36\n3 10 23 43\n5 14 19 28 46 48\n2 30 39\n6 13 20 24 33 37 47\n8 1 2 3 4 5 6 7 8\n7 16 18 25 27 34 40 44\n4 32 35 41 50\n",
"output": "75\n"
},
{
"input": "8 5\n2 1 2\n2 3 4\n1 5\n2 6 7\n1 8\n",
"output": "8\n"
},
{
"input": "21 13\n1 18\n2 8 13\n1 21\n1 17\n2 7 9\n1 20\n1 19\n1 4\n1 16\n2 5 6\n3 12 14 15\n3 1 2 3\n2 10 11\n",
"output": "24\n"
},
{
"input": "10 10\n1 5\n1 4\n1 10\n1 3\n1 7\n1 1\n1 8\n1 6\n1 9\n1 2\n",
"output": "9\n"
}
] | code_contests | python | 0 | 79bf7f500f21798b22d8d1485fcd0f54 |
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is x, and Kevin submitted correctly at minute m but made w wrong submissions, then his score on that problem is <image>. His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
Input
The first line of the input contains five space-separated integers m1, m2, m3, m4, m5, where mi (0 ≤ mi ≤ 119) is the time of Kevin's last submission for problem i. His last submission is always correct and gets accepted.
The second line contains five space-separated integers w1, w2, w3, w4, w5, where wi (0 ≤ wi ≤ 10) is Kevin's number of wrong submissions on problem i.
The last line contains two space-separated integers hs and hu (0 ≤ hs, hu ≤ 20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
Output
Print a single integer, the value of Kevin's final score.
Examples
Input
20 40 60 80 100
0 1 2 3 4
1 0
Output
4900
Input
119 119 119 119 119
0 0 0 0 0
10 0
Output
4930
Note
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <image> of the points on each problem. So his score from solving problems is <image>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | t=list(map(int,input().split()))
w=list(map(int,input().split()))
q,z=map(int,input().split())
c=0
v=0
for i in range(500,3000,500):
x=(1-(t[v]/250))*i-50*w[v]
a=max(0.3*i,x)
c=c+a
v=v+1
f=q*100-z*50
dp=c+f
print(int(dp))
| python | code_algorithm | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"output": "4900\n"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0\n",
"output": "4930\n"
},
{
"input": "36 102 73 101 19\n5 9 2 2 6\n4 13\n",
"output": "4292\n"
},
{
"input": "119 0 0 0 0\n2 0 0 0 0\n5 5\n",
"output": "7412\n"
},
{
"input": "0 0 119 0 0\n0 0 2 0 0\n5 5\n",
"output": "6936\n"
},
{
"input": "0 0 0 0 0\n10 10 10 10 10\n0 20\n",
"output": "4150\n"
},
{
"input": "0 46 86 72 40\n1 5 5 5 9\n6 5\n",
"output": "4924\n"
},
{
"input": "45 45 75 36 76\n6 2 2 0 0\n8 17\n",
"output": "5222\n"
},
{
"input": "119 119 119 119 119\n10 10 10 10 10\n0 20\n",
"output": "1310\n"
},
{
"input": "79 112 37 36 116\n2 8 4 7 5\n4 12\n",
"output": "3872\n"
},
{
"input": "0 0 0 119 0\n0 0 0 2 0\n5 5\n",
"output": "6698\n"
},
{
"input": "78 96 6 97 62\n7 7 9 2 9\n10 3\n",
"output": "4868\n"
},
{
"input": "95 28 3 31 115\n1 9 0 7 3\n10 13\n",
"output": "5132\n"
},
{
"input": "0 0 0 119 0\n0 0 0 10 0\n5 5\n",
"output": "6350\n"
},
{
"input": "0 119 0 0 0\n0 10 0 0 0\n5 5\n",
"output": "7050\n"
},
{
"input": "0 0 119 0 0\n0 0 10 0 0\n0 0\n",
"output": "6450\n"
},
{
"input": "10 53 101 62 1\n8 0 9 7 9\n0 11\n",
"output": "4032\n"
},
{
"input": "55 66 75 44 47\n6 0 6 6 10\n19 0\n",
"output": "6414\n"
},
{
"input": "47 11 88 5 110\n6 10 4 2 3\n10 6\n",
"output": "5188\n"
},
{
"input": "94 18 24 91 105\n2 0 7 10 3\n1 4\n",
"output": "4118\n"
},
{
"input": "119 0 0 0 0\n0 0 0 0 0\n4 9\n",
"output": "7212\n"
},
{
"input": "119 0 0 0 0\n10 0 0 0 0\n5 5\n",
"output": "7400\n"
},
{
"input": "45 17 116 58 3\n8 8 7 6 4\n3 19\n",
"output": "3992\n"
},
{
"input": "5 44 61 103 92\n9 0 10 4 8\n15 7\n",
"output": "4914\n"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0\n",
"output": "7500\n"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9\n",
"output": "5088\n"
},
{
"input": "102 83 26 6 11\n3 4 1 8 3\n17 14\n",
"output": "6704\n"
},
{
"input": "19 12 0 113 77\n3 0 10 9 2\n8 6\n",
"output": "5040\n"
},
{
"input": "57 51 76 45 96\n1 0 4 3 6\n12 15\n",
"output": "5156\n"
},
{
"input": "70 84 31 57 2\n7 0 0 2 7\n12 5\n",
"output": "6652\n"
},
{
"input": "53 34 53 107 81\n4 3 1 10 8\n7 7\n",
"output": "4324\n"
},
{
"input": "0 0 0 0 119\n0 0 0 0 10\n5 5\n",
"output": "6060\n"
},
{
"input": "0 119 0 0 0\n0 2 0 0 0\n5 5\n",
"output": "7174\n"
},
{
"input": "103 110 101 97 70\n4 2 1 0 5\n7 5\n",
"output": "4678\n"
},
{
"input": "109 83 5 114 104\n6 0 3 9 5\n5 2\n",
"output": "4386\n"
},
{
"input": "98 15 116 43 55\n4 3 0 9 3\n10 7\n",
"output": "5400\n"
},
{
"input": "66 109 22 22 62\n3 1 5 4 5\n10 5\n",
"output": "5854\n"
},
{
"input": "7 54 39 102 31\n6 0 2 10 1\n18 3\n",
"output": "6610\n"
},
{
"input": "86 10 66 80 55\n0 2 5 10 5\n15 6\n",
"output": "5802\n"
},
{
"input": "0 26 99 108 35\n0 4 3 0 10\n9 5\n",
"output": "5388\n"
},
{
"input": "47 16 44 78 111\n7 9 8 0 2\n1 19\n",
"output": "3288\n"
},
{
"input": "64 17 86 59 45\n8 0 10 2 2\n4 4\n",
"output": "5144\n"
},
{
"input": "0 0 0 0 119\n0 0 0 0 2\n5 5\n",
"output": "6460\n"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8\n",
"output": "4522\n"
},
{
"input": "96 104 9 94 84\n6 10 7 8 3\n14 11\n",
"output": "4754\n"
},
{
"input": "16 112 50 114 68\n1 4 8 4 9\n19 11\n",
"output": "5178\n"
},
{
"input": "115 53 96 62 110\n7 8 1 7 9\n7 16\n",
"output": "3416\n"
},
{
"input": "114 4 45 78 113\n0 4 8 10 2\n10 12\n",
"output": "4432\n"
},
{
"input": "89 24 51 49 84\n5 6 2 2 9\n2 14\n",
"output": "4066\n"
},
{
"input": "113 107 59 50 56\n3 7 10 6 3\n10 12\n",
"output": "4586\n"
},
{
"input": "71 42 60 20 7\n7 1 1 10 6\n1 7\n",
"output": "5242\n"
},
{
"input": "40 115 93 107 113\n5 7 2 6 8\n6 17\n",
"output": "2876\n"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n20 0\n",
"output": "9500\n"
},
{
"input": "56 56 96 105 107\n4 9 10 4 8\n2 1\n",
"output": "3104\n"
},
{
"input": "98 118 117 86 4\n2 10 9 7 5\n11 15\n",
"output": "4476\n"
},
{
"input": "97 17 43 84 58\n2 8 3 8 6\n10 7\n",
"output": "5028\n"
},
{
"input": "113 37 4 84 66\n2 0 10 3 0\n20 19\n",
"output": "6070\n"
}
] | code_contests | python | 0.2 | 1e17c893d4f6d907e30bbf040edd65a9 |
Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.
Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j. As Vasya is fond of different useless statistic he asks you to compute the sum of all values ρi, j among all pairs 1 ≤ i < j ≤ n.
Input
The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of stations.
The second line contains n - 1 integer ai (i + 1 ≤ ai ≤ n), the i-th of them means that at the i-th station one may buy tickets to each station from i + 1 to ai inclusive.
Output
Print the sum of ρi, j among all pairs of 1 ≤ i < j ≤ n.
Examples
Input
4
4 4 4
Output
6
Input
5
2 3 5 5
Output
17
Note
In the first sample it's possible to get from any station to any other (with greater index) using only one ticket. The total number of pairs is 6, so the answer is also 6.
Consider the second sample:
* ρ1, 2 = 1
* ρ1, 3 = 2
* ρ1, 4 = 3
* ρ1, 5 = 3
* ρ2, 3 = 1
* ρ2, 4 = 2
* ρ2, 5 = 2
* ρ3, 4 = 1
* ρ3, 5 = 1
* ρ4, 5 = 1
Thus the answer equals 1 + 2 + 3 + 3 + 1 + 2 + 2 + 1 + 1 + 1 = 17.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n=int(input())
a=list(map(int, input().split()))
a=[ai-1 for ai in a]
a[n:n] = [n - 1]
dp=[0]*n
ans=0
i=n-2
nmax=2**17
tree=[[0,0]]*2*nmax;
#Build Segment tree
j=0
while j<n:
tree[nmax + j] = [a[j], j]
j=j+1
j=nmax-1
while j>0:
tree[j]=max(tree[j*2],tree[j*2+1])
j=j-1
#get max of a interval [left, right]
def get(left, right):
ans=[-1,-1]
left=left+nmax
right=right+nmax+1
while left<right:
if (left & 1):
ans = max(ans, tree[left])
left = left + 1
if (right & 1):
right = right - 1
ans = max(ans, tree[right])
left = left // 2
right = right // 2
return ans[1]
while i>=0:
m = get(i + 1, a[i]);
dp[i] = dp[m] - (a[i] - m) + n - i - 1
ans += dp[i]
i=i-1
print(ans) | python | code_algorithm | [
{
"input": "4\n4 4 4\n",
"output": "6\n"
},
{
"input": "5\n2 3 5 5\n",
"output": "17\n"
},
{
"input": "7\n7 3 4 6 6 7\n",
"output": "35\n"
},
{
"input": "4\n3 3 4\n",
"output": "8\n"
},
{
"input": "6\n3 3 6 6 6\n",
"output": "21\n"
},
{
"input": "5\n4 4 4 5\n",
"output": "13\n"
},
{
"input": "9\n2 9 7 6 9 7 8 9\n",
"output": "52\n"
},
{
"input": "3\n3 3\n",
"output": "3\n"
},
{
"input": "8\n3 7 7 8 8 7 8\n",
"output": "37\n"
},
{
"input": "10\n2 10 8 7 8 8 10 9 10\n",
"output": "63\n"
},
{
"input": "2\n2\n",
"output": "1\n"
}
] | code_contests | python | 0 | 87ab33121856ba7e691a1a03a11e9661 |
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
Input
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
Output
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
Examples
Input
3 2
2 3 4
Output
3
Input
5 4
3 1 8 9 7
Output
5
Note
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
* In the first day Anastasia collects 8 pebbles of the third type.
* In the second day she collects 8 pebbles of the fourth type.
* In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type.
* In the fourth day she collects 7 pebbles of the fifth type.
* In the fifth day she collects 1 pebble of the second type.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import math
n,k = map(int,input().split())
stones = list(map(int, input().split()))
days = 0
for i in range(n):
days += math.ceil(stones[i]/k)
print(math.ceil(days/2)) | python | code_algorithm | [
{
"input": "5 4\n3 1 8 9 7\n",
"output": "5\n"
},
{
"input": "3 2\n2 3 4\n",
"output": "3\n"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1\n",
"output": "5\n"
},
{
"input": "3 57\n78 165 54\n",
"output": "3\n"
},
{
"input": "1 1\n10000\n",
"output": "5000\n"
},
{
"input": "2 2\n2 2\n",
"output": "1\n"
},
{
"input": "9 13\n132 87 200 62 168 51 185 192 118\n",
"output": "48\n"
},
{
"input": "5 72\n74 10 146 189 184\n",
"output": "6\n"
},
{
"input": "1 22\n1\n",
"output": "1\n"
}
] | code_contests | python | 0.7 | d79bcedf33695f73e4e6bd5b20c3b8ce |
The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil.
The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal.
Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a <image> of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team.
Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum.
It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself.
The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p).
A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team.
It is guaranteed that every hero is able to destroy any megaboss alone.
Input
The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself.
In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal.
In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c.
Output
Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team).
When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking.
Examples
Input
3
Troll likes Dracul
Dracul likes Anka
Snowy likes Hexadecimal
210 200 180
Output
30 3
Input
2
Anka likes Chapay
Chapay likes Anka
10000 50 50
Output
1950 2
Note
A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | # -*- coding: utf-8 -*-
"""
Created on Fri Nov 1 14:28:37 2019
@author: PC-4
"""
from itertools import combinations, product
Teams = [[1, 1, 5],
[1, 2, 4],
[1, 3, 3],
[2, 2, 3]]
Names = {}
Names["Anka"] = 0
Names["Chapay"] = 1
Names["Cleo"] = 2
Names["Dracul"] = 3
Names["Hexadecimal"] = 4
Names["Snowy"] = 5
Names["Troll"] = 6
graph = [[0] * 7 for _ in range(7)]
N = int(input())
for _ in range(N):
p, q = input().split(" likes ")
p = Names[p]
q = Names[q]
graph[p][q] = 1
a, b, c = sorted(map(int, input().split()))
E_diff_star = float('inf')
team_all = []
for t1, t2, t3 in Teams:
E = [a//t1, b//t2, c//t3]
E_diff = max(E) - min(E)
if E_diff < E_diff_star:
E_diff_star = E_diff
team_all = [[t1, t2, t3]]
elif E_diff == E_diff_star:
team_all.append([t1, t2, t3])
liking = 0
for team in team_all:
for te2 in combinations(set(range(7)), team[2]):
te2 = set(te2)
left = set(range(7)) - te2
L2 = sum(graph[p][q] for p, q in product(te2, te2))
for te1 in combinations(left, team[1]):
te1 = set(te1)
te0 = left - te1
L1 = sum(graph[p][q] for p, q in product(te1, te1))
L0 = sum(graph[p][q] for p, q in product(te0, te0))
L = L2 + L1 + L0
if L > liking:
liking = L
print(E_diff_star, liking)
| python | code_algorithm | [
{
"input": "3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180\n",
"output": "30 3\n"
},
{
"input": "2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50\n",
"output": "1950 2\n"
},
{
"input": "0\n2000000000 2000000000 1\n",
"output": "666666665 0\n"
},
{
"input": "22\nCleo likes Snowy\nCleo likes Troll\nChapay likes Dracul\nSnowy likes Troll\nDracul likes Chapay\nDracul likes Snowy\nChapay likes Cleo\nSnowy likes Chapay\nDracul likes Troll\nAnka likes Hexadecimal\nSnowy likes Anka\nHexadecimal likes Cleo\nHexadecimal likes Troll\nDracul likes Anka\nCleo likes Hexadecimal\nHexadecimal likes Dracul\nChapay likes Troll\nChapay likes Hexadecimal\nAnka likes Snowy\nTroll likes Hexadecimal\nSnowy likes Hexadecimal\nAnka likes Chapay\n458053183 602148195 994999698\n",
"output": "102639975 9\n"
},
{
"input": "5\nTroll likes Chapay\nAnka likes Snowy\nAnka likes Dracul\nChapay likes Anka\nSnowy likes Troll\n709201888 431802832 597079932\n",
"output": "82638550 3\n"
},
{
"input": "18\nCleo likes Snowy\nSnowy likes Hexadecimal\nCleo likes Hexadecimal\nTroll likes Dracul\nHexadecimal likes Snowy\nDracul likes Troll\nChapay likes Anka\nChapay likes Cleo\nTroll likes Chapay\nHexadecimal likes Chapay\nAnka likes Snowy\nTroll likes Snowy\nDracul likes Snowy\nDracul likes Chapay\nChapay likes Troll\nCleo likes Troll\nHexadecimal likes Cleo\nAnka likes Chapay\n864225278 509037060 402199775\n",
"output": "86975205 9\n"
},
{
"input": "0\n1 2000000000 2000000000\n",
"output": "666666665 0\n"
},
{
"input": "12\nAnka likes Dracul\nDracul likes Troll\nCleo likes Troll\nSnowy likes Hexadecimal\nHexadecimal likes Chapay\nCleo likes Dracul\nCleo likes Chapay\nHexadecimal likes Anka\nSnowy likes Cleo\nHexadecimal likes Snowy\nCleo likes Snowy\nChapay likes Snowy\n584329075 428752235 675234087\n",
"output": "77788420 6\n"
},
{
"input": "12\nCleo likes Hexadecimal\nChapay likes Anka\nHexadecimal likes Cleo\nAnka likes Snowy\nAnka likes Cleo\nDracul likes Snowy\nAnka likes Troll\nSnowy likes Anka\nCleo likes Anka\nHexadecimal likes Troll\nHexadecimal likes Chapay\nSnowy likes Troll\n1000000000 1 2000000000\n",
"output": "499999999 7\n"
},
{
"input": "0\n100 300 600\n",
"output": "50 0\n"
},
{
"input": "6\nTroll likes Chapay\nHexadecimal likes Snowy\nCleo likes Dracul\nCleo likes Anka\nChapay likes Anka\nAnka likes Chapay\n758376921 432619768 578580897\n",
"output": "72980564 5\n"
},
{
"input": "11\nSnowy likes Dracul\nAnka likes Dracul\nChapay likes Snowy\nHexadecimal likes Troll\nAnka likes Cleo\nChapay likes Dracul\nAnka likes Chapay\nSnowy likes Troll\nAnka likes Hexadecimal\nCleo likes Chapay\nTroll likes Cleo\n100 100 100\n",
"output": "17 5\n"
},
{
"input": "18\nSnowy likes Troll\nChapay likes Hexadecimal\nCleo likes Snowy\nDracul likes Snowy\nSnowy likes Chapay\nTroll likes Cleo\nSnowy likes Anka\nDracul likes Hexadecimal\nHexadecimal likes Anka\nAnka likes Hexadecimal\nAnka likes Chapay\nTroll likes Anka\nAnka likes Snowy\nAnka likes Troll\nSnowy likes Cleo\nHexadecimal likes Troll\nHexadecimal likes Dracul\nCleo likes Anka\n20000 1000 20000\n",
"output": "5666 8\n"
},
{
"input": "0\n1 1 10000\n",
"output": "1999 0\n"
},
{
"input": "12\nSnowy likes Chapay\nCleo likes Dracul\nHexadecimal likes Snowy\nHexadecimal likes Anka\nDracul likes Chapay\nCleo likes Troll\nDracul likes Snowy\nSnowy likes Dracul\nTroll likes Chapay\nDracul likes Anka\nChapay likes Hexadecimal\nTroll likes Dracul\n436364663 856574374 347564737\n",
"output": "111742423 6\n"
},
{
"input": "8\nAnka likes Chapay\nDracul likes Snowy\nSnowy likes Cleo\nCleo likes Anka\nCleo likes Troll\nHexadecimal likes Troll\nTroll likes Cleo\nSnowy likes Dracul\n325432666 254352394 547360304\n",
"output": "55277237 6\n"
},
{
"input": "17\nHexadecimal likes Chapay\nChapay likes Snowy\nChapay likes Troll\nAnka likes Hexadecimal\nCleo likes Troll\nSnowy likes Cleo\nCleo likes Anka\nCleo likes Hexadecimal\nAnka likes Snowy\nChapay likes Hexadecimal\nAnka likes Cleo\nDracul likes Snowy\nChapay likes Anka\nTroll likes Hexadecimal\nTroll likes Anka\nAnka likes Dracul\nHexadecimal likes Anka\n828886798 548024213 166661324\n",
"output": "107350782 9\n"
},
{
"input": "8\nSnowy likes Anka\nHexadecimal likes Snowy\nTroll likes Dracul\nHexadecimal likes Troll\nSnowy likes Troll\nAnka likes Snowy\nSnowy likes Chapay\nAnka likes Chapay\n70 70 70\n",
"output": "12 5\n"
},
{
"input": "0\n477107314 230715335 261545417\n",
"output": "43678104 0\n"
},
{
"input": "3\nChapay likes Hexadecimal\nAnka likes Cleo\nTroll likes Snowy\n15 15000 90\n",
"output": "2985 2\n"
},
{
"input": "14\nChapay likes Cleo\nCleo likes Anka\nDracul likes Snowy\nSnowy likes Cleo\nChapay likes Anka\nSnowy likes Anka\nChapay likes Troll\nTroll likes Anka\nAnka likes Snowy\nChapay likes Dracul\nDracul likes Anka\nHexadecimal likes Chapay\nSnowy likes Dracul\nCleo likes Dracul\n15 15 15\n",
"output": "2 6\n"
},
{
"input": "4\nAnka likes Cleo\nSnowy likes Cleo\nAnka likes Hexadecimal\nCleo likes Snowy\n1 1 1\n",
"output": "0 3\n"
},
{
"input": "18\nAnka likes Troll\nDracul likes Chapay\nHexadecimal likes Dracul\nChapay likes Dracul\nAnka likes Hexadecimal\nSnowy likes Cleo\nDracul likes Anka\nSnowy likes Anka\nSnowy likes Hexadecimal\nDracul likes Troll\nDracul likes Snowy\nHexadecimal likes Anka\nChapay likes Hexadecimal\nSnowy likes Dracul\nCleo likes Snowy\nChapay likes Cleo\nAnka likes Dracul\nTroll likes Anka\n838821770 712931449 361810998\n",
"output": "124167182 8\n"
},
{
"input": "1\nHexadecimal likes Chapay\n848189141 631955593 79523012\n",
"output": "203206701 1\n"
},
{
"input": "17\nCleo likes Dracul\nTroll likes Cleo\nAnka likes Chapay\nAnka likes Troll\nChapay likes Snowy\nTroll likes Snowy\nChapay likes Dracul\nHexadecimal likes Snowy\nDracul likes Snowy\nTroll likes Hexadecimal\nHexadecimal likes Anka\nCleo likes Snowy\nHexadecimal likes Dracul\nSnowy likes Chapay\nSnowy likes Hexadecimal\nSnowy likes Dracul\nDracul likes Troll\n112909524 619275170 403563648\n",
"output": "88872300 9\n"
},
{
"input": "0\n1200000000 1200000000 1200000000\n",
"output": "200000000 0\n"
},
{
"input": "6\nChapay likes Troll\nTroll likes Cleo\nCleo likes Troll\nChapay likes Snowy\nAnka likes Snowy\nTroll likes Dracul\n987499608 272739716 133573597\n",
"output": "113301305 5\n"
},
{
"input": "12\nCleo likes Hexadecimal\nTroll likes Cleo\nAnka likes Cleo\nHexadecimal likes Troll\nAnka likes Snowy\nHexadecimal likes Anka\nTroll likes Hexadecimal\nTroll likes Anka\nDracul likes Cleo\nCleo likes Troll\nDracul likes Troll\nChapay likes Anka\n762445890 377707484 324080158\n",
"output": "92108551 6\n"
},
{
"input": "0\n2000000000 2000000000 2000000000\n",
"output": "333333334 0\n"
},
{
"input": "16\nChapay likes Snowy\nHexadecimal likes Anka\nChapay likes Troll\nDracul likes Cleo\nTroll likes Hexadecimal\nHexadecimal likes Dracul\nChapay likes Cleo\nSnowy likes Cleo\nSnowy likes Anka\nTroll likes Chapay\nSnowy likes Hexadecimal\nTroll likes Snowy\nCleo likes Hexadecimal\nAnka likes Snowy\nSnowy likes Chapay\nAnka likes Dracul\n843382501 58524777 503038818\n",
"output": "192994632 8\n"
},
{
"input": "5\nChapay likes Cleo\nAnka likes Hexadecimal\nAnka likes Chapay\nCleo likes Troll\nAnka likes Cleo\n299076810 225593528 36830738\n",
"output": "62861532 3\n"
},
{
"input": "13\nCleo likes Hexadecimal\nCleo likes Snowy\nHexadecimal likes Anka\nAnka likes Snowy\nTroll likes Snowy\nChapay likes Hexadecimal\nHexadecimal likes Snowy\nSnowy likes Chapay\nTroll likes Cleo\nAnka likes Hexadecimal\nHexadecimal likes Cleo\nChapay likes Dracul\nSnowy likes Dracul\n1000000000 2000000000 1000000000\n",
"output": "166666666 6\n"
},
{
"input": "2\nTroll likes Cleo\nAnka likes Cleo\n14344913 559182022 405430772\n",
"output": "172049094 2\n"
},
{
"input": "21\nChapay likes Dracul\nSnowy likes Chapay\nSnowy likes Troll\nCleo likes Chapay\nCleo likes Troll\nChapay likes Cleo\nSnowy likes Anka\nDracul likes Anka\nTroll likes Snowy\nSnowy likes Cleo\nChapay likes Hexadecimal\nCleo likes Anka\nCleo likes Snowy\nHexadecimal likes Cleo\nHexadecimal likes Snowy\nHexadecimal likes Anka\nHexadecimal likes Troll\nAnka likes Snowy\nDracul likes Troll\nChapay likes Anka\nSnowy likes Hexadecimal\n482557397 502108264 750230216\n",
"output": "9775434 8\n"
},
{
"input": "13\nAnka likes Cleo\nCleo likes Troll\nChapay likes Cleo\nSnowy likes Troll\nChapay likes Anka\nChapay likes Snowy\nSnowy likes Chapay\nAnka likes Snowy\nSnowy likes Dracul\nCleo likes Hexadecimal\nDracul likes Chapay\nAnka likes Hexadecimal\nSnowy likes Cleo\n554338888 280967932 682619964\n",
"output": "96188303 7\n"
},
{
"input": "18\nHexadecimal likes Chapay\nTroll likes Dracul\nTroll likes Snowy\nCleo likes Dracul\nChapay likes Snowy\nDracul likes Chapay\nCleo likes Snowy\nDracul likes Hexadecimal\nTroll likes Anka\nAnka likes Troll\nHexadecimal likes Dracul\nChapay likes Hexadecimal\nCleo likes Chapay\nAnka likes Hexadecimal\nSnowy likes Dracul\nChapay likes Troll\nAnka likes Snowy\nDracul likes Cleo\n240256138 922743697 38909902\n",
"output": "191776022 10\n"
},
{
"input": "5\nTroll likes Dracul\nAnka likes Chapay\nCleo likes Anka\nChapay likes Cleo\nSnowy likes Hexadecimal\n222 400 400\n",
"output": "89 5\n"
},
{
"input": "2\nSnowy likes Hexadecimal\nTroll likes Dracul\n2000000000 2000000000 2000000000\n",
"output": "333333334 2\n"
},
{
"input": "6\nAnka likes Troll\nTroll likes Chapay\nTroll likes Hexadecimal\nHexadecimal likes Cleo\nSnowy likes Hexadecimal\nChapay likes Troll\n740076959 230477703 987799796\n",
"output": "98788895 5\n"
}
] | code_contests | python | 0.3 | 13f1e81a11ccd1ab31de3ec406cb5846 |
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 v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 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.
2. Right after that he starts to type it.
3. 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
The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 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
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Examples
Input
5 1 2 1 2
Output
First
Input
3 3 1 1 1
Output
Second
Input
4 5 3 1 5
Output
Friendship
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.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | s, v1, v2, t1, t2 = list(map(int, input().split()))
a = 2*t1 + s*v1
b = 2*t2 + s*v2
if a > b:
print("Second")
elif a < b:
print("First")
else:
print("Friendship")
| python | code_algorithm | [
{
"input": "4 5 3 1 5\n",
"output": "Friendship\n"
},
{
"input": "5 1 2 1 2\n",
"output": "First\n"
},
{
"input": "3 3 1 1 1\n",
"output": "Second\n"
},
{
"input": "2 313 856 964 421\n",
"output": "Friendship\n"
},
{
"input": "61 464 623 89 548\n",
"output": "First\n"
},
{
"input": "37 261 207 1 1000\n",
"output": "Friendship\n"
},
{
"input": "4 202 512 995 375\n",
"output": "Friendship\n"
},
{
"input": "3 3 1 6 9\n",
"output": "Friendship\n"
},
{
"input": "213 480 811 134 745\n",
"output": "First\n"
},
{
"input": "1 10 2 6 10\n",
"output": "Friendship\n"
},
{
"input": "6 5 7 10 4\n",
"output": "Friendship\n"
},
{
"input": "2 7 6 2 3\n",
"output": "Friendship\n"
},
{
"input": "29 344 406 900 1\n",
"output": "Friendship\n"
},
{
"input": "1 2 8 8 5\n",
"output": "Friendship\n"
},
{
"input": "1 1 1 1 1\n",
"output": "Friendship\n"
},
{
"input": "424 41 41 909 909\n",
"output": "Friendship\n"
},
{
"input": "641 31 29 161 802\n",
"output": "Friendship\n"
},
{
"input": "12 462 8 311 327\n",
"output": "Second\n"
},
{
"input": "15 14 32 65 28\n",
"output": "First\n"
},
{
"input": "1 2 8 9 8\n",
"output": "First\n"
},
{
"input": "9 5 7 8 7\n",
"output": "First\n"
},
{
"input": "637 324 69 612 998\n",
"output": "Second\n"
},
{
"input": "884 913 263 641 265\n",
"output": "Second\n"
},
{
"input": "2 9 8 8 9\n",
"output": "Friendship\n"
},
{
"input": "13 849 819 723 918\n",
"output": "Friendship\n"
},
{
"input": "894 197 325 232 902\n",
"output": "First\n"
},
{
"input": "485 117 368 567 609\n",
"output": "First\n"
},
{
"input": "69 1 2 1 2\n",
"output": "First\n"
},
{
"input": "436 306 266 493 580\n",
"output": "Second\n"
},
{
"input": "8 8 1 1 1\n",
"output": "Second\n"
},
{
"input": "2 3 9 8 2\n",
"output": "Friendship\n"
},
{
"input": "1000 1000 1000 1000 1000\n",
"output": "Friendship\n"
}
] | code_contests | python | 0.8 | 98601dceb0028d8d0c970e94416c1398 |
Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below carefully and follow it and not the similar rules in real programming languages.
There is a very powerful system of pointers on &K* — you can add an asterisk to the right of the existing type X — that will result in new type X * . That is called pointer-definition operation. Also, there is the operation that does the opposite — to any type of X, which is a pointer, you can add an ampersand — that will result in a type &X, to which refers X. That is called a dereference operation.
The &K* language has only two basic data types — void and errtype. Also, the language has operators typedef and typeof.
* The operator "typedef A B" defines a new data type B, which is equivalent to A. A can have asterisks and ampersands, and B cannot have them. For example, the operator typedef void** ptptvoid will create a new type ptptvoid, that can be used as void**.
* The operator "typeof A" returns type of A, brought to void, that is, returns the type void**...*, equivalent to it with the necessary number of asterisks (the number can possibly be zero). That is, having defined the ptptvoid type, as shown above, the typeof ptptvoid operator will return void**.
An attempt of dereferencing of the void type will lead to an error: to a special data type errtype. For errtype the following equation holds true: errtype* = &errtype = errtype. An attempt to use the data type that hasn't been defined before that will also lead to the errtype.
Using typedef, we can define one type several times. Of all the definitions only the last one is valid. However, all the types that have been defined earlier using this type do not change.
Let us also note that the dereference operation has the lower priority that the pointer operation, in other words &T * is always equal to T.
Note, that the operators are executed consecutively one by one. If we have two operators "typedef &void a" and "typedef a* b", then at first a becomes errtype, and after that b becomes errtype* = errtype, but not &void* = void (see sample 2).
Vasya does not yet fully understand this powerful technology, that's why he asked you to help him. Write a program that analyzes these operators.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of operators. Then follow n lines with operators. Each operator is of one of two types: either "typedef A B", or "typeof A". In the first case the B type differs from void and errtype types, and besides, doesn't have any asterisks and ampersands.
All the data type names are non-empty lines of no more than 20 lowercase Latin letters. The number of asterisks and ampersands separately in one type in any operator does not exceed 10, however if we bring some types to void with several asterisks, their number may exceed 10.
Output
For every typeof operator print on the single line the answer to that operator — the type that the given operator returned.
Examples
Input
5
typedef void* ptv
typeof ptv
typedef &&ptv node
typeof node
typeof &ptv
Output
void*
errtype
void
Input
17
typedef void* b
typedef b* c
typeof b
typeof c
typedef &b b
typeof b
typeof c
typedef &&b* c
typeof c
typedef &b* c
typeof c
typedef &void b
typeof b
typedef b******* c
typeof c
typedef &&b* c
typeof c
Output
void*
void**
void
void**
errtype
void
errtype
errtype
errtype
Note
Let's look at the second sample.
After the first two queries typedef the b type is equivalent to void*, and с — to void**.
The next query typedef redefines b — it is now equal to &b = &void* = void. At that, the с type doesn't change.
After that the с type is defined as &&b* = &&void* = &void = errtype. It doesn't influence the b type, that's why the next typedef defines c as &void* = void.
Then the b type is again redefined as &void = errtype.
Please note that the c type in the next query is defined exactly as errtype******* = errtype, and not &void******* = void******. The same happens in the last typedef.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | types = {'void':'void', 'errtype':'errtype'}
def getRealType(type_expr):
expr_type = type_expr.strip('&*')
full_type_name = type_expr.replace(expr_type, types.get(expr_type, "errtype"))
base_type = full_type_name.strip('&*')
if base_type == "void":
addr_count = full_type_name.count('*')
deref_count = full_type_name.count('&')
if deref_count > addr_count:
return "errtype"
return base_type + "*" * (addr_count - deref_count)
else:
return "errtype"
def setTypeAlias(type_expr, alias_name):
types[alias_name] = getRealType(type_expr)
n = int(input())
for _ in range(n):
operator = input().split()
command = operator[0]
if command == "typedef":
setTypeAlias(operator[1], operator[2])
else:
print(getRealType(operator[1]))
# Made By Mostafa_Khaled | python | code_algorithm | [
{
"input": "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&b* c\ntypeof c\n",
"output": "void*\nvoid**\nerrtype\nvoid**\nerrtype\nerrtype\nerrtype\nerrtype\nerrtype\n"
},
{
"input": "5\ntypedef void* ptv\ntypeof ptv\ntypedef &&ptv node\ntypeof node\ntypeof &ptv\n",
"output": "void*\nerrtype\nerrtype\n"
},
{
"input": "10\ntypedef errtype** ucywcaykzh\ntypeof &ucywcaykzh*********\ntypedef &&&&&&void********* ucywcaykzh\ntypeof &&&ucywcaykzh******\ntypedef &errtype vfqmtssewklwhiukrz\ntypeof &&vfqmtssewklwhiukrz********\ntypedef &errtype********** xvhxopvh\ntypeof &xvhxopvh\ntypedef &void****** kieypzcclmsvce\ntypeof &&&&&kieypzcclmsvce**\n",
"output": "errtype\nvoid******\nerrtype\nerrtype\nvoid**\n"
},
{
"input": "2\ntypedef void errtypea\ntypeof errtypea\n",
"output": "void\n"
},
{
"input": "15\ntypedef &void pt\ntypeof pt\ntypeof pt*\ntypedef pt**** err\ntypeof err\ntypeof &err\ntypeof err*\ntypedef &void*** pt\ntypeof err\ntypeof &err\ntypeof err*\ntypeof pt\ntypeof pt*\ntypeof &&pt*\ntypeof &&&pt\n",
"output": "errtype\nerrtype\nerrtype\nerrtype\nerrtype\nerrtype\nerrtype\nerrtype\nvoid**\nvoid***\nvoid*\nerrtype\n"
},
{
"input": "10\ntypedef &void**** youdyfpinzk\ntypeof &youdyfpinzk***\ntypedef &&&&youdyfpinzk****** nfbsgpjzhxzskmxc\ntypeof nfbsgpjzhxzskmxc***\ntypedef &&&void*** puerqioirikxej\ntypeof &puerqioirikxej********\ntypedef &puerqioirikxej******** xzgzsamjdufuyxz\ntypeof &xzgzsamjdufuyxz******\ntypedef &&&&xzgzsamjdufuyxz******* hbyqffrbitdgott\ntypeof hbyqffrbitdgott*****\n",
"output": "void*****\nvoid********\nvoid*******\nvoid************\nvoid***************\n"
},
{
"input": "10\ntypeof void\ntypedef void voiddd\ntypeof &&&&&voiddd*********\ntypeof &&&&&voidddd*********\ntypedef aaaa bbbb\ntypeof bbbb\ntypeof aaaa\ntypedef void** aaaa\ntypeof aaaa\ntypeof bbbb\n",
"output": "void\nvoid****\nerrtype\nerrtype\nerrtype\nvoid**\nerrtype\n"
},
{
"input": "10\ntypedef void**** iizqen\ntypeof iizqen****\ntypedef &void**** gdq\ntypeof &&gdq*********\ntypedef &&errtype******** lhndwyohjckrcew\ntypeof &lhndwyohjckrcew*\ntypedef &&&&void********** ccuoxbgeui\ntypeof ccuoxbgeui\ntypedef &&&&gdq******** gdq\ntypeof gdq******\n",
"output": "void********\nvoid**********\nerrtype\nvoid******\nvoid*************\n"
},
{
"input": "5\ntypedef void* ptv\ntypeof ptv\ntypedef &&ptv node\ntypeof node\ntypeof &ptv\n",
"output": "void*\nerrtype\nvoid\n"
},
{
"input": "10\ntypedef &errtype********* xekls\ntypeof &xekls*\ntypedef xekls*** xekls\ntypeof &xekls********\ntypedef &void*** xekls\ntypeof &xekls\ntypedef &errtype******* dwkmly\ntypeof &&dwkmly******\ntypedef void******* zkpahsnsumbnnzi\ntypeof zkpahsnsumbnnzi*\n",
"output": "errtype\nerrtype\nvoid*\nerrtype\nvoid********\n"
},
{
"input": "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&b* c\ntypeof c\n",
"output": "void*\nvoid**\nvoid\nvoid**\nerrtype\nvoid\nerrtype\nerrtype\nerrtype\n"
},
{
"input": "10\ntypedef &&&&void******* xqldryeid\ntypeof &xqldryeid*\ntypedef &void****** frgqt\ntypeof &&frgqt*********\ntypedef &void******* xqldryeid\ntypeof xqldryeid*\ntypedef errtype* xqldryeid\ntypeof &xqldryeid****\ntypedef &&&&&xqldryeid***** cuyhdvkkfyjzjmdkgcf\ntypeof cuyhdvkkfyjzjmdkgcf********\n",
"output": "void***\nvoid************\nvoid*******\nerrtype\nerrtype\n"
},
{
"input": "10\ntypedef &errtype*** oomxdcottaxn\ntypeof &oomxdcottaxn*********\ntypedef oomxdcottaxn**** bqbigpn\ntypeof &&bqbigpn**********\ntypedef &&&void******** ilrltx\ntypeof &&ilrltx**********\ntypedef void*** yo\ntypeof yo**********\ntypedef oomxdcottaxn*** bqbigpn\ntypeof &bqbigpn****\n",
"output": "errtype\nerrtype\nvoid*************\nvoid*************\nerrtype\n"
},
{
"input": "10\ntypedef yo******* qxqkvdlvbymjvfsr\ntypeof &&&qxqkvdlvbymjvfsr****\ntypedef qxqkvdlvbymjvfsr* tezeyz\ntypeof tezeyz**********\ntypedef &qxqkvdlvbymjvfsr********** anho\ntypeof &&&anho********\ntypedef &tezeyz* oxdbjclieutuocavuq\ntypeof oxdbjclieutuocavuq***\ntypedef void* yo\ntypeof yo***\n",
"output": "errtype\nerrtype\nerrtype\nerrtype\nvoid****\n"
},
{
"input": "10\ntypedef &&&&&void* mbmrmohbydctgukqbueu\ntypeof &mbmrmohbydctgukqbueu*******\ntypedef &&mbmrmohbydctgukqbueu******* xollxoxrhif\ntypeof xollxoxrhif********\ntypedef &&&&void** zijybfnyxmodoahvvikd\ntypeof zijybfnyxmodoahvvikd****\ntypedef &void**** to\ntypeof &to*******\ntypedef &void******* yhhoqgpnysxvft\ntypeof &&&yhhoqgpnysxvft*******\n",
"output": "errtype\nerrtype\nerrtype\nvoid*********\nvoid**********\n"
},
{
"input": "10\ntypedef &ymeyyknmj****** ymeyyknmj\ntypeof &&&&ymeyyknmj*******\ntypedef &&&&errtype***** hbyqffrbitdgott\ntypeof &hbyqffrbitdgott**********\ntypedef &&&m** hbyqffrbitdgott\ntypeof &&hbyqffrbitdgott\ntypedef &&&void*** youdyfpinzk\ntypeof &&youdyfpinzk*********\ntypedef &&&&&xzgzsamjdufuyxz********* puerqioirikxej\ntypeof &&puerqioirikxej*****\n",
"output": "errtype\nerrtype\nerrtype\nvoid*******\nerrtype\n"
},
{
"input": "1\ntypeof a\n",
"output": "errtype\n"
},
{
"input": "4\ntypedef void voida\ntypedef voida* voidb\ntypedef voidb* voidc\ntypeof voidc\n",
"output": "void**\n"
}
] | code_contests | python | 0.1 | 170d63d000456c767e682b013c074005 |
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Input
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
Output
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
Examples
Input
5
1 2 3 1 3
Output
4
Input
4
6 6 5 5
Output
0
Input
4
6 6 4 4
Output
-8
Note
In the first example:
1. d(a1, a2) = 0;
2. d(a1, a3) = 2;
3. d(a1, a4) = 0;
4. d(a1, a5) = 2;
5. d(a2, a3) = 0;
6. d(a2, a4) = 0;
7. d(a2, a5) = 0;
8. d(a3, a4) = - 2;
9. d(a3, a5) = 0;
10. d(a4, a5) = 2.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from sys import stdin, stdout
n = int(stdin.readline())
a = [int(i) for i in stdin.readline().split()]
d = dict()
ans, sm = 0, 0
for i in range(n):
if a[i] not in d.keys():
d[a[i]] = 0
d[a[i]] += 1
ans += i * a[i] - sm
if (a[i] + 1) in d.keys():
ans += 1 * d[a[i] + 1]
if (a[i] - 1) in d.keys():
ans -= 1 * d[a[i] - 1]
sm += a[i]
stdout.write(str(ans))
| python | code_algorithm | [
{
"input": "4\n6 6 5 5\n",
"output": "0"
},
{
"input": "5\n1 2 3 1 3\n",
"output": "4"
},
{
"input": "4\n6 6 4 4\n",
"output": "-8"
},
{
"input": "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\n",
"output": "-91018"
},
{
"input": "1\n32955\n",
"output": "0"
},
{
"input": "2\n1 1000000000\n",
"output": "999999999"
},
{
"input": "1\n1\n",
"output": "0"
},
{
"input": "5\n3 1 1 1 3\n",
"output": "0"
},
{
"input": "100\n82 81 14 33 78 80 15 60 89 82 79 13 15 17 25 13 21 20 63 26 62 63 79 36 18 21 88 92 27 18 59 64 18 96 28 4 76 43 26 25 89 88 96 33 27 97 52 37 92 80 23 18 78 14 88 5 3 14 85 72 84 75 41 3 51 92 91 79 18 78 19 79 8 35 85 86 78 17 51 36 100 32 49 95 2 100 67 72 55 53 42 3 21 100 12 51 50 79 47 2\n",
"output": "6076"
},
{
"input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6\n",
"output": "-1774"
},
{
"input": "100\n7 8 5 9 5 6 6 9 7 6 8 7 5 10 7 2 6 1 8 10 7 9 9 8 9 6 8 5 10 6 3 7 5 8 9 7 6 1 9 9 6 9 9 2 10 4 4 6 7 9 7 7 9 10 6 10 8 6 4 7 5 5 8 10 10 7 6 9 8 1 5 1 6 6 2 9 8 4 6 6 9 10 6 1 9 9 9 6 1 8 9 2 8 7 1 10 8 2 4 7\n",
"output": "-1713"
},
{
"input": "1\n1000000000\n",
"output": "0"
},
{
"input": "5\n1 999999996 999999998 999999994 1000000000\n",
"output": "3999999992"
},
{
"input": "1\n22955\n",
"output": "0"
}
] | code_contests | python | 0 | e262ab32d5ab40e2b051a12279826e7e |
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A funny ring is a cycle that goes through all the vertices just once. Moreover, loops are funny rings too.
She has already drawn the apples and some of the graph edges. But now it is not clear, how to connect the rest of the vertices to get an interesting graph as a result. The answer should contain the minimal amount of added edges. And furthermore, the answer should be the lexicographically smallest one. The set of edges (x1, y1), (x2, y2), ..., (xn, yn), where xi ≤ yi, is lexicographically smaller than the set (u1, v1), (u2, v2), ..., (un, vn), where ui ≤ vi, provided that the sequence of integers x1, y1, x2, y2, ..., xn, yn is lexicographically smaller than the sequence u1, v1, u2, v2, ..., un, vn. If you do not cope, Hexadecimal will eat you. ...eat you alive.
Input
The first line of the input data contains a pair of integers n and m (1 ≤ n ≤ 50, 0 ≤ m ≤ 2500) — the amount of vertices and edges respectively. The following lines contain pairs of numbers xi and yi (1 ≤ xi, yi ≤ n) — the vertices that are already connected by edges. The initial graph may contain multiple edges and loops.
Output
In the first line output «YES» or «NO»: if it is possible or not to construct an interesting graph. If the answer is «YES», in the second line output k — the amount of edges that should be added to the initial graph. Finally, output k lines: pairs of vertices xj and yj, between which edges should be drawn. The result may contain multiple edges and loops. k can be equal to zero.
Examples
Input
3 2
1 2
2 3
Output
YES
1
1 3
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | def dfs(v, comp):
used[v] = comp
for u in graph[v]:
if not used[u]:
dfs(u, comp)
n, m = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(m):
v, u = map(int, input().split())
graph[v - 1].append(u - 1)
graph[u - 1].append(v - 1)
used = [0] * n
ncomp = 0
for v in range(n):
if not used[v]:
ncomp += 1
dfs(v, ncomp)
maxpwr = max(map(len, graph))
if n - m != ncomp or maxpwr > 2:
if n == m and ncomp == 1 and maxpwr == 2:
print("YES")
print(0)
else:
print("NO")
else:
print("YES")
print(n - m)
leaves = []
for v in range(n):
if len(graph[v]) == 1:
leaves.append([v + 1, used[v]])
elif len(graph[v]) == 0:
leaves.append([v + 1, used[v]])
leaves.append([v + 1, used[v]])
sets = []
for i in range(len(leaves)):
if leaves[i][0] == 0:
continue
for j in range(i + 1, len(leaves)):
if leaves[j][0] == 0:
continue
if leaves[i][1] == leaves[j][1]:
continue
seti = -1
for k in range(len(sets)):
if leaves[i][1] in sets[k]:
seti = k
break
setj = -2
for k in range(len(sets)):
if leaves[j][1] in sets[k]:
setj = k
break
if seti != setj:
print(leaves[i][0], leaves[j][0])
if seti >= 0:
if setj >= 0:
sets[seti] |= sets[setj]
sets.pop(setj)
else:
sets[seti].add(leaves[j][1])
else:
if setj >= 0:
sets[setj].add(leaves[i][1])
else:
sets.append(set([leaves[i][1], leaves[j][1]]))
leaves[i][0] = 0
leaves[j][0] = 0
break
for i in range(len(leaves)):
if leaves[i][0] == 0:
continue
for j in range(i + 1, len(leaves)):
if leaves[j][0] == 0:
continue
print(leaves[i][0], leaves[j][0])
break
else:
continue
break | python | code_algorithm | [
{
"input": "3 2\n1 2\n2 3\n",
"output": "YES\n1\n1 3\n"
},
{
"input": "42 28\n7 19\n15 24\n3 42\n18 5\n32 27\n26 20\n40 30\n35 2\n14 8\n22 10\n36 4\n16 14\n21 29\n37 40\n2 12\n30 21\n19 17\n39 34\n31 28\n20 3\n4 33\n11 42\n26 21\n9 10\n4 32\n6 1\n1 14\n14 12\n",
"output": "NO\n"
},
{
"input": "2 2\n1 2\n2 1\n",
"output": "YES\n0\n"
},
{
"input": "3 2\n3 2\n2 1\n",
"output": "YES\n1\n1 3\n"
},
{
"input": "3 3\n1 3\n2 1\n3 2\n",
"output": "YES\n0\n"
},
{
"input": "2 3\n1 1\n1 2\n2 1\n",
"output": "NO\n"
},
{
"input": "50 27\n10 7\n32 9\n17 33\n25 34\n47 28\n23 16\n15 46\n41 50\n18 24\n27 19\n35 36\n19 38\n50 31\n31 40\n4 14\n1 11\n6 48\n33 35\n36 30\n39 12\n28 45\n2 1\n22 13\n3 49\n29 36\n7 34\n36 8\n",
"output": "NO\n"
},
{
"input": "30 21\n6 14\n19 17\n25 20\n28 10\n10 3\n24 23\n22 13\n1 7\n11 26\n12 1\n16 8\n14 9\n30 15\n4 27\n13 21\n20 12\n24 14\n19 10\n7 10\n16 8\n26 11\n",
"output": "NO\n"
},
{
"input": "9 4\n7 6\n2 8\n3 5\n8 3\n",
"output": "YES\n5\n1 2\n1 4\n4 6\n5 9\n7 9\n"
},
{
"input": "6 1\n4 1\n",
"output": "YES\n5\n1 2\n2 3\n3 5\n4 6\n5 6\n"
},
{
"input": "34 18\n9 14\n30 23\n19 3\n34 19\n26 2\n31 28\n7 21\n20 27\n16 15\n18 20\n5 34\n17 22\n10 12\n6 4\n8 32\n29 24\n24 10\n34 22\n",
"output": "NO\n"
},
{
"input": "45 20\n37 5\n41 6\n13 22\n28 24\n30 10\n39 35\n5 20\n38 32\n26 1\n23 37\n35 17\n21 12\n7 8\n1 7\n4 16\n8 40\n44 3\n27 23\n19 2\n33 27\n",
"output": "YES\n25\n2 3\n4 6\n9 10\n9 11\n11 12\n13 14\n14 15\n15 16\n17 18\n18 19\n20 21\n22 24\n25 26\n25 28\n29 30\n29 31\n31 32\n33 34\n34 36\n36 39\n38 40\n41 42\n42 43\n43 45\n44 45\n"
},
{
"input": "1 3\n1 1\n1 1\n1 1\n",
"output": "NO\n"
},
{
"input": "47 36\n29 31\n25 45\n39 46\n12 19\n31 21\n4 41\n5 38\n33 3\n21 39\n40 1\n1 47\n35 12\n42 10\n2 4\n6 35\n17 16\n22 28\n14 22\n41 25\n10 14\n34 37\n27 20\n44 27\n20 2\n3 17\n45 13\n18 34\n47 15\n10 44\n25 15\n12 23\n27 17\n15 38\n17 32\n29 31\n3 39\n",
"output": "NO\n"
},
{
"input": "6 3\n3 4\n1 3\n2 5\n",
"output": "YES\n3\n1 2\n4 6\n5 6\n"
},
{
"input": "33 19\n27 23\n17 16\n20 33\n3 11\n1 31\n26 24\n25 10\n21 15\n14 9\n12 4\n29 2\n7 21\n32 13\n33 6\n5 26\n13 28\n6 22\n3 24\n27 19\n",
"output": "YES\n14\n1 2\n4 5\n7 8\n8 9\n10 11\n12 14\n15 16\n17 18\n18 19\n20 23\n22 28\n25 29\n30 31\n30 32\n"
},
{
"input": "49 29\n43 18\n44 26\n49 31\n37 19\n20 16\n18 22\n30 5\n7 28\n12 2\n31 11\n27 43\n25 9\n19 4\n35 25\n4 30\n6 27\n46 41\n38 23\n17 37\n13 8\n11 38\n29 20\n40 10\n22 29\n36 7\n17 36\n35 48\n41 36\n39 27\n",
"output": "NO\n"
},
{
"input": "50 0\n",
"output": "YES\n50\n1 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 50\n"
},
{
"input": "40 29\n23 2\n40 16\n35 31\n2 40\n39 35\n18 11\n21 7\n3 6\n15 5\n4 18\n17 19\n8 34\n16 17\n9 39\n37 21\n19 26\n26 36\n33 4\n10 9\n34 22\n13 20\n32 40\n35 11\n5 12\n14 5\n5 24\n40 6\n32 35\n21 21\n",
"output": "NO\n"
},
{
"input": "41 28\n6 28\n1 38\n11 7\n12 26\n10 36\n9 21\n8 3\n2 20\n33 32\n21 40\n34 10\n22 15\n30 22\n5 12\n19 35\n13 6\n31 37\n25 4\n15 23\n37 33\n19 19\n20 6\n14 8\n9 12\n27 33\n28 27\n37 11\n36 20\n",
"output": "NO\n"
},
{
"input": "39 25\n8 23\n27 38\n6 32\n20 33\n7 34\n22 26\n32 12\n23 2\n28 20\n33 35\n18 10\n1 21\n11 18\n39 28\n17 9\n36 8\n15 17\n14 1\n19 24\n37 30\n21 39\n38 13\n28 5\n36 30\n33 13\n",
"output": "NO\n"
},
{
"input": "46 24\n24 43\n38 20\n8 38\n22 13\n25 24\n40 35\n21 10\n7 39\n18 5\n33 19\n26 7\n1 27\n43 26\n9 17\n3 44\n44 14\n20 11\n5 2\n15 32\n23 8\n10 37\n27 23\n43 23\n33 25\n",
"output": "NO\n"
},
{
"input": "32 24\n9 15\n32 16\n26 7\n15 8\n30 21\n23 14\n22 17\n14 29\n19 1\n24 31\n3 22\n20 9\n5 23\n10 3\n27 24\n1 30\n8 18\n23 28\n14 4\n27 10\n11 9\n11 24\n11 18\n17 6\n",
"output": "NO\n"
},
{
"input": "44 31\n28 26\n5 36\n9 37\n36 29\n26 5\n25 42\n30 22\n29 3\n35 10\n44 28\n18 13\n16 6\n3 33\n22 9\n4 15\n27 19\n17 11\n19 41\n11 25\n10 30\n2 34\n12 7\n37 31\n16 40\n25 24\n28 44\n41 37\n21 21\n12 28\n20 23\n20 17\n",
"output": "NO\n"
},
{
"input": "48 32\n45 23\n17 3\n2 48\n47 20\n27 18\n13 28\n18 26\n26 21\n48 31\n21 9\n43 19\n34 43\n10 36\n14 17\n6 12\n3 11\n15 1\n23 37\n37 13\n42 40\n35 5\n16 7\n40 44\n4 29\n24 25\n5 16\n31 45\n39 22\n46 34\n22 30\n28 33\n33 41\n",
"output": "YES\n16\n1 2\n4 6\n7 8\n8 9\n10 11\n12 14\n15 19\n20 24\n25 27\n29 30\n32 35\n32 36\n38 39\n38 41\n42 46\n44 47\n"
},
{
"input": "49 0\n",
"output": "YES\n49\n1 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 49\n"
},
{
"input": "45 22\n15 23\n14 30\n5 44\n43 21\n24 17\n37 38\n40 9\n41 43\n7 4\n38 22\n26 18\n44 41\n42 11\n4 33\n35 24\n36 15\n19 1\n1 37\n9 35\n12 40\n31 29\n18 25\n",
"output": "YES\n23\n2 3\n2 5\n3 6\n6 7\n8 10\n8 11\n10 12\n13 14\n13 16\n16 17\n19 20\n20 21\n22 23\n25 27\n26 28\n27 29\n28 30\n31 32\n32 33\n34 36\n34 39\n39 45\n42 45\n"
},
{
"input": "1 0\n",
"output": "YES\n1\n1 1\n"
},
{
"input": "35 28\n6 24\n35 10\n14 19\n30 34\n29 23\n21 16\n34 5\n22 6\n7 35\n13 29\n27 3\n8 27\n5 15\n26 11\n19 1\n31 28\n17 31\n18 20\n12 32\n4 17\n10 4\n32 8\n35 18\n9 5\n33 30\n24 25\n12 12\n34 3\n",
"output": "NO\n"
},
{
"input": "48 26\n27 5\n13 21\n14 20\n41 31\n4 26\n21 39\n31 17\n18 4\n42 2\n28 43\n11 23\n35 22\n34 18\n23 15\n10 13\n7 48\n5 44\n19 25\n12 7\n15 27\n39 41\n33 10\n45 40\n20 42\n29 38\n17 28\n",
"output": "YES\n22\n1 2\n1 3\n3 6\n6 8\n8 9\n9 11\n12 14\n16 19\n16 22\n24 25\n24 26\n29 30\n30 32\n32 33\n34 36\n35 37\n36 38\n37 40\n43 44\n45 46\n46 47\n47 48\n"
},
{
"input": "1 2\n1 1\n1 1\n",
"output": "NO\n"
},
{
"input": "8 3\n3 8\n2 6\n1 7\n",
"output": "YES\n5\n1 2\n3 4\n4 5\n5 6\n7 8\n"
},
{
"input": "2 1\n1 1\n",
"output": "NO\n"
},
{
"input": "8 4\n1 7\n2 4\n6 2\n5 8\n",
"output": "YES\n4\n1 3\n3 4\n5 6\n7 8\n"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 1\n",
"output": "NO\n"
},
{
"input": "5 2\n1 5\n5 4\n",
"output": "YES\n3\n1 2\n2 3\n3 4\n"
},
{
"input": "6 6\n4 3\n3 5\n6 4\n1 6\n2 1\n5 2\n",
"output": "YES\n0\n"
},
{
"input": "37 22\n2 15\n37 11\n14 29\n9 37\n15 23\n24 35\n18 3\n23 12\n34 33\n4 19\n22 14\n21 26\n28 27\n12 36\n8 6\n26 28\n31 1\n29 5\n27 25\n17 10\n33 18\n35 20\n",
"output": "YES\n15\n1 2\n3 4\n5 6\n7 8\n7 9\n10 11\n13 16\n13 17\n16 19\n20 21\n22 24\n25 30\n30 31\n32 34\n32 36\n"
},
{
"input": "4 1\n3 1\n",
"output": "YES\n3\n1 2\n2 4\n3 4\n"
},
{
"input": "49 26\n33 34\n43 21\n26 27\n46 33\n32 47\n6 3\n44 14\n34 42\n4 8\n27 29\n12 4\n42 7\n22 16\n5 31\n35 24\n39 40\n20 12\n17 44\n8 18\n38 26\n48 39\n31 17\n9 19\n10 23\n1 30\n49 38\n",
"output": "YES\n23\n1 2\n2 3\n5 6\n7 9\n10 11\n11 13\n13 14\n15 16\n15 18\n19 20\n21 22\n23 24\n25 28\n25 29\n28 30\n32 35\n36 37\n36 40\n37 41\n41 43\n45 46\n45 47\n48 49\n"
},
{
"input": "2 1\n2 1\n",
"output": "YES\n1\n1 2\n"
},
{
"input": "9 5\n5 2\n4 6\n8 4\n1 8\n2 1\n",
"output": "YES\n4\n3 5\n3 7\n6 9\n7 9\n"
},
{
"input": "4 2\n3 1\n4 2\n",
"output": "YES\n2\n1 2\n3 4\n"
},
{
"input": "7 6\n5 6\n2 7\n7 3\n4 1\n1 5\n3 4\n",
"output": "YES\n1\n2 6\n"
},
{
"input": "38 30\n21 36\n20 21\n9 11\n27 10\n25 20\n33 16\n11 23\n31 4\n13 22\n36 27\n32 37\n12 6\n35 31\n5 34\n6 14\n7 38\n26 18\n4 24\n18 5\n23 17\n29 28\n38 13\n10 30\n18 3\n15 25\n1 24\n22 22\n17 22\n36 18\n23 13\n",
"output": "NO\n"
},
{
"input": "7 4\n3 2\n2 6\n6 7\n1 5\n",
"output": "YES\n3\n1 3\n4 5\n4 7\n"
},
{
"input": "9 2\n2 5\n1 6\n",
"output": "YES\n7\n1 2\n3 4\n3 5\n4 7\n6 8\n7 9\n8 9\n"
},
{
"input": "2 0\n",
"output": "YES\n2\n1 2\n1 2\n"
},
{
"input": "50 1\n2 3\n",
"output": "YES\n49\n1 2\n1 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 50\n"
},
{
"input": "4 3\n1 2\n4 1\n2 3\n",
"output": "YES\n1\n3 4\n"
},
{
"input": "3 2\n1 2\n1 2\n",
"output": "NO\n"
},
{
"input": "47 26\n24 2\n13 24\n25 14\n35 6\n4 10\n11 18\n29 41\n37 13\n38 3\n2 31\n30 29\n6 42\n33 25\n41 45\n40 8\n28 47\n43 39\n39 38\n1 5\n45 22\n19 21\n18 37\n36 17\n27 28\n16 11\n12 30\n",
"output": "YES\n21\n1 3\n4 5\n7 8\n7 9\n9 10\n12 14\n15 16\n15 17\n19 20\n20 22\n21 23\n23 26\n26 27\n31 32\n32 33\n34 35\n34 36\n40 42\n43 44\n44 46\n46 47\n"
},
{
"input": "31 24\n6 25\n8 13\n29 20\n13 5\n26 8\n16 9\n31 2\n22 7\n24 21\n28 18\n9 12\n27 14\n20 24\n23 10\n10 27\n15 1\n21 28\n11 16\n12 29\n8 7\n10 28\n27 19\n17 3\n23 16\n",
"output": "NO\n"
},
{
"input": "2 1\n2 2\n",
"output": "NO\n"
},
{
"input": "50 1\n2 3\n",
"output": "YES\n49\n1 2\n1 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 50\n"
},
{
"input": "4 3\n1 2\n1 3\n1 4\n",
"output": "NO\n"
},
{
"input": "36 23\n27 31\n33 14\n17 24\n14 25\n3 8\n1 21\n24 27\n13 26\n23 6\n35 22\n34 33\n36 4\n19 16\n18 15\n32 36\n5 7\n20 30\n21 11\n11 27\n8 23\n6 10\n4 31\n15 31\n",
"output": "NO\n"
},
{
"input": "5 3\n3 5\n4 2\n5 1\n",
"output": "YES\n2\n1 2\n3 4\n"
},
{
"input": "49 0\n",
"output": "YES\n49\n1 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 49\n"
},
{
"input": "7 3\n7 4\n5 2\n1 3\n",
"output": "YES\n4\n1 2\n3 4\n5 6\n6 7\n"
},
{
"input": "2 2\n1 1\n2 2\n",
"output": "NO\n"
},
{
"input": "50 21\n27 16\n42 35\n15 28\n46 17\n30 39\n47 18\n35 25\n26 24\n24 30\n28 41\n40 38\n11 21\n33 20\n43 10\n37 14\n1 43\n32 49\n49 6\n10 45\n21 50\n39 3\n",
"output": "YES\n29\n1 2\n2 3\n4 5\n4 6\n5 7\n7 8\n8 9\n9 11\n12 13\n12 14\n13 15\n16 17\n18 19\n19 20\n22 23\n22 25\n23 26\n27 29\n29 31\n31 32\n33 34\n34 36\n36 37\n38 41\n40 42\n44 45\n44 46\n47 48\n48 50\n"
},
{
"input": "1 1\n1 1\n",
"output": "YES\n0\n"
},
{
"input": "46 25\n44 40\n25 10\n28 44\n26 4\n38 7\n27 3\n46 8\n32 28\n22 20\n14 33\n30 14\n12 23\n13 30\n40 18\n37 35\n10 16\n23 22\n3 46\n36 24\n19 12\n18 42\n11 34\n34 36\n9 32\n24 19\n",
"output": "YES\n21\n1 2\n1 4\n2 5\n5 6\n6 7\n8 9\n11 13\n15 16\n15 17\n17 20\n21 25\n21 26\n27 29\n29 31\n31 33\n35 38\n37 39\n39 41\n41 43\n42 45\n43 45\n"
},
{
"input": "5 2\n1 3\n4 1\n",
"output": "YES\n3\n2 3\n2 5\n4 5\n"
},
{
"input": "50 0\n",
"output": "YES\n50\n1 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22\n21 23\n22 24\n23 25\n24 26\n25 27\n26 28\n27 29\n28 30\n29 31\n30 32\n31 33\n32 34\n33 35\n34 36\n35 37\n36 38\n37 39\n38 40\n39 41\n40 42\n41 43\n42 44\n43 45\n44 46\n45 47\n46 48\n47 49\n48 50\n49 50\n"
},
{
"input": "43 36\n3 24\n25 36\n36 11\n12 38\n11 32\n15 3\n8 9\n2 17\n5 40\n21 37\n39 20\n28 30\n16 22\n27 13\n31 6\n24 39\n34 19\n35 18\n43 21\n41 4\n7 31\n33 26\n6 5\n42 27\n29 2\n30 10\n40 1\n1 29\n20 14\n40 29\n29 6\n26 27\n37 21\n19 9\n31 4\n19 38\n",
"output": "NO\n"
},
{
"input": "8 5\n4 7\n3 6\n8 3\n6 5\n1 2\n",
"output": "YES\n3\n1 4\n2 5\n7 8\n"
}
] | code_contests | python | 0 | e723cf1f41573b81a3aabfebcbb4d521 |
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are n stages available. The rocket must contain exactly k of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — 26 tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.
Input
The first line of input contains two integers — n and k (1 ≤ k ≤ n ≤ 50) – the number of available stages and the number of stages to use in the rocket.
The second line contains string s, which consists of exactly n lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.
Output
Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
Examples
Input
5 3
xyabd
Output
29
Input
7 4
problem
Output
34
Input
2 2
ab
Output
-1
Input
12 1
abaabbaaabbb
Output
1
Note
In the first example, the following rockets satisfy the condition:
* "adx" (weight is 1+4+24=29);
* "ady" (weight is 1+4+25=30);
* "bdx" (weight is 2+4+24=30);
* "bdy" (weight is 2+4+25=31).
Rocket "adx" has the minimal weight, so the answer is 29.
In the second example, target rocket is "belo". Its weight is 2+5+12+15=34.
In the third example, n=k=2, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n,k = list(map(int,input().split()))
data = sorted(list(input()))
data = list(map(lambda x:ord(x)-ord('a')+1,data))
result = 0
used = 0
idx =0
prev = -2
# print(data)
for d in data:
if d > prev+1:
result+= d
prev = d
used += 1
if used == k:
break
if used < k:
print(-1)
else:
print(result)
| python | code_algorithm | [
{
"input": "7 4\nproblem\n",
"output": "34\n"
},
{
"input": "2 2\nab\n",
"output": "-1\n"
},
{
"input": "5 3\nxyabd\n",
"output": "29\n"
},
{
"input": "12 1\nabaabbaaabbb\n",
"output": "1\n"
},
{
"input": "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "1\n"
},
{
"input": "2 1\nxz\n",
"output": "24\n"
},
{
"input": "2 2\nac\n",
"output": "4\n"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "169\n"
},
{
"input": "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "-1\n"
},
{
"input": "12 6\nfwseyrarkwcd\n",
"output": "61\n"
},
{
"input": "20 20\ntzmvhskkyugkuuxpvtbh\n",
"output": "-1\n"
},
{
"input": "1 1\nc\n",
"output": "3\n"
},
{
"input": "3 1\nzzz\n",
"output": "26\n"
},
{
"input": "30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav\n",
"output": "-1\n"
},
{
"input": "2 1\nac\n",
"output": "1\n"
},
{
"input": "38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa\n",
"output": "5\n"
},
{
"input": "13 13\nhzdxpbfvrltnj\n",
"output": "182\n"
},
{
"input": "4 3\nadjz\n",
"output": "15\n"
},
{
"input": "40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv\n",
"output": "-1\n"
},
{
"input": "50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz\n",
"output": "-1\n"
},
{
"input": "1 1\na\n",
"output": "1\n"
},
{
"input": "1 1\nn\n",
"output": "14\n"
},
{
"input": "2 2\nad\n",
"output": "5\n"
},
{
"input": "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "-1\n"
},
{
"input": "10 7\niuiukrxcml\n",
"output": "99\n"
},
{
"input": "10 8\nsmzeblyjqw\n",
"output": "113\n"
},
{
"input": "3 3\naoz\n",
"output": "42\n"
},
{
"input": "13 13\nuwgmkyqeiaocs\n",
"output": "169\n"
},
{
"input": "5 1\naaddd\n",
"output": "1\n"
}
] | code_contests | python | 0.5 | bc8d4cae6039a0521a24b68e2f148e81 |
Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes l_{i} minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer.
Vasya is a bit lazy, so he likes taking smoke breaks for a minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
Input
The first line contains three integers n, L and a (0 ≤ n ≤ 10^{5}, 1 ≤ L ≤ 10^{9}, 1 ≤ a ≤ L).
The i-th of the next n lines contains two integers t_{i} and l_{i} (0 ≤ t_{i} ≤ L - 1, 1 ≤ l_{i} ≤ L). It is guaranteed that t_{i} + l_{i} ≤ t_{i + 1} and t_{n} + l_{n} ≤ L.
Output
Output one integer — the maximum number of breaks.
Examples
Input
2 11 3
0 1
1 1
Output
3
Input
0 5 2
Output
2
Input
1 3 2
1 2
Output
0
Note
In the first sample Vasya can take 3 breaks starting after 2, 5 and 8 minutes after the beginning of the day.
In the second sample Vasya can take 2 breaks starting after 0 and 2 minutes after the beginning of the day.
In the third sample Vasya can't take any breaks.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n,l,a = map(int,input().split())
b =[]
for i in range(n):
b.append([int(e) for e in input().split()])
ans = 0
for i in range(n-1):
ans += (b[i+1][0] - b[i][1] - b[i][0])//a
if(n > 0):
ans += b[0][0]//a
ans += (l - b[n-1][1] - b[n-1][0])//a
else:
ans += l//a
print(ans)
| python | code_algorithm | [
{
"input": "2 11 3\n0 1\n1 1\n",
"output": "3\n"
},
{
"input": "0 5 2\n",
"output": "2\n"
},
{
"input": "1 3 2\n1 2\n",
"output": "0\n"
},
{
"input": "0 1 1\n",
"output": "1\n"
},
{
"input": "1 5 3\n3 1\n",
"output": "1\n"
},
{
"input": "0 1000000000 1\n",
"output": "1000000000\n"
},
{
"input": "3 21 3\n3 3\n9 3\n15 3\n",
"output": "4\n"
},
{
"input": "0 1000000000 1000000000\n",
"output": "1\n"
},
{
"input": "1 1 1\n0 1\n",
"output": "0\n"
},
{
"input": "2 10 3\n0 1\n9 1\n",
"output": "2\n"
},
{
"input": "1 1000000000 1\n0 1000000000\n",
"output": "0\n"
},
{
"input": "0 1000000000 500000000\n",
"output": "2\n"
},
{
"input": "1 10 5\n5 2\n",
"output": "1\n"
},
{
"input": "1 3 2\n1 1\n",
"output": "0\n"
},
{
"input": "1 2 1\n1 1\n",
"output": "1\n"
}
] | code_contests | python | 0.7 | 23ef561789f11ae7305803e2740beec7 |
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the responsibility of a special seating program. It was found out that the large majority of Berland's inhabitants go to the cinema in order to watch a movie, that's why they want to sit as close to the hall center as possible. Moreover, a company of M people, who come to watch a movie, want necessarily to occupy M successive seats in one row. Let's formulate the algorithm, according to which the program chooses seats and sells tickets. As the request for M seats comes, the program should determine the row number x and the segment [yl, yr] of the seats numbers in this row, where yr - yl + 1 = M. From all such possible variants as a final result the program should choose the one with the minimum function value of total seats remoteness from the center. Say, <image> — the row and the seat numbers of the most "central" seat. Then the function value of seats remoteness from the hall center is <image>. If the amount of minimum function values is more than one, the program should choose the one that is closer to the screen (i.e. the row number x is lower). If the variants are still multiple, it should choose the one with the minimum yl. If you did not get yet, your task is to simulate the work of this program.
Input
The first line contains two integers N and K (1 ≤ N ≤ 1000, 1 ≤ K ≤ 99) — the amount of requests and the hall size respectively. The second line contains N space-separated integers Mi from the range [1, K] — requests to the program.
Output
Output N lines. In the i-th line output «-1» (without quotes), if it is impossible to find Mi successive seats in one row, otherwise output three numbers x, yl, yr. Separate the numbers with a space.
Examples
Input
2 1
1 1
Output
1 1 1
-1
Input
4 3
1 2 3 1
Output
2 2 2
1 1 2
3 1 3
2 1 1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | __author__ = 'Darren'
def solve():
n, k = map(int, input().split())
group = map(int, input().split())
available = [[k, 1][:] for _ in range(k+1)]
center = (k + 1) // 2
for m in group:
closest, best_row, best_col = 10000, -1, -1
for row in range(1, k+1):
col = 0
if available[row][0] < m and k - available[row][1] + 1 < m:
continue
if available[row][0] == k:
col = center - m // 2
elif center - available[row][0] <= available[row][1] - center:
col = available[row][0] - m + 1
else:
col = available[row][1]
distance = calc_distance(center, row, col, m)
if distance < closest:
closest = distance
best_row = row
best_col = col
if closest == 10000:
print(-1)
else:
print(best_row, best_col, best_col+m-1)
available[best_row][0] = min(available[best_row][0], best_col-1)
available[best_row][1] = max(available[best_row][1], best_col+m)
def calc_distance(center, row, col, num):
end_col = col + num - 1
distance = abs(center - row) * num
if col >= center:
distance += (col - center) * num + (num - 1) * num // 2
elif end_col <= center:
distance += (center - end_col) * num + (num - 1) * num // 2
else:
distance += ((center - col) * (center - col + 1) // 2 +
(end_col - center) * (end_col - center + 1) // 2)
return distance
if __name__ == '__main__':
solve()
| python | code_algorithm | [
{
"input": "4 3\n1 2 3 1\n",
"output": "2 2 2\n1 1 2\n3 1 3\n2 1 1\n"
},
{
"input": "2 1\n1 1\n",
"output": "1 1 1\n-1\n"
},
{
"input": "2 3\n3 3\n",
"output": "2 1 3\n1 1 3\n"
},
{
"input": "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16 29 7 12 17 5 17 14 6 15 8 25 11 16 14 4 3 7 25 2 5 2 12 12 22 18 14 16 5 19 25 4 21 24 7 11 21 27 10 16 21 17 19 13\n",
"output": "15 6 24\n14 8 22\n16 8 22\n13 2 28\n17 14 15\n12 3 27\n17 16 17\n18 13 17\n11 1 29\n19 10 20\n10 12 17\n17 10 13\n20 5 24\n9 10 20\n21 2 28\n8 7 22\n17 18 23\n18 7 12\n22 10 19\n18 18 19\n7 13 17\n23 9 20\n6 11 18\n24 4 26\n5 10 20\n10 18 24\n25 10 20\n4 9 21\n26 6 24\n3 1 29\n17 2 9\n18 20 23\n10 3 11\n27 9 21\n2 8 21\n28 4 25\n1 7 22\n29 1 29\n14 1 7\n7 1 12\n-1\n14 23 27\n-1\n-1\n16 2 7\n-1\n19 2 9\n-1\n7 18 28\n-1\n-1\n16 23 26\n15 3 5\n19 21 27\n-1\n15 25 26\n17 24 28\n9 8 9\n-1\n-1\n-1\n-1\n-1\n-1\n9 21 25\n-1\n-1\n18 3 6\n-1\n-1\n22 20 26\n6 19 29\n-1\n-1\n6 1 10\n-1\n-1\n-1\n-1\n-1\n"
},
{
"input": "1 3\n1\n",
"output": "2 2 2\n"
},
{
"input": "100 57\n5 19 50 55 18 54 30 56 54 16 44 49 10 47 6 26 5 28 52 28 6 11 1 25 6 43 36 24 48 34 50 46 24 9 35 17 10 28 19 5 23 43 55 25 48 42 15 6 2 26 45 6 22 1 54 17 19 40 32 19 25 10 55 48 14 37 14 42 57 26 23 16 37 43 13 37 37 18 17 16 8 46 28 39 2 11 8 46 33 21 20 9 40 19 12 16 53 53 42 6\n",
"output": "29 27 31\n28 20 38\n30 4 53\n27 2 56\n31 20 37\n26 2 55\n32 14 43\n25 1 56\n33 2 55\n24 21 36\n34 7 50\n23 5 53\n29 17 26\n35 6 52\n29 32 37\n22 16 41\n36 27 31\n21 15 42\n37 3 54\n20 15 42\n38 26 31\n19 24 34\n29 38 38\n39 17 41\n18 26 31\n40 8 50\n17 11 46\n41 17 40\n16 5 52\n42 12 45\n15 4 53\n43 6 51\n14 17 40\n29 39 47\n44 12 46\n36 10 26\n36 32 41\n13 15 42\n28 1 19\n28 39 43\n45 18 40\n12 8 50\n46 2 56\n38 32 56\n11 5 52\n47 8 49\n31 38 52\n31 14 19\n24 37 38\n10 16 41\n48 7 51\n29 11 16\n38 4 25\n18 32 32\n9 2 55\n24 4 20\n18 7 25\n49 9 48\n8 13 44\n18 33 51\n50 17 41\n24 39 48\n7 2 56\n51 5 52\n19 10 23\n6 11 47\n19 35 48\n52 8 49\n5 1 57\n53 16 41\n4 18 40\n22 42 57\n54 11 47\n3 8 50\n28 44 56\n55 11 47\n2 11 47\n56 20 37\n41 41 57\n36 42 57\n31 6 13\n1 6 51\n57 15 42\n-1\n32 44 45\n32 3 13\n29 3 10\n-1\n-1\n-1\n56 38 57\n29 48 56\n-1\n56 1 19\n32 46 57\n39 1 16\n-1\n-1\n-1\n22 10 15\n"
},
{
"input": "2 5\n3 4\n",
"output": "3 2 4\n2 1 4\n"
},
{
"input": "100 61\n29 27 54 52 15 7 11 55 3 19 48 52 58 36 41 25 29 20 28 4 57 51 20 16 40 14 15 26 57 2 27 17 39 13 13 50 23 56 5 60 41 9 23 49 34 34 21 41 41 23 24 7 25 36 8 22 9 59 35 58 5 36 47 53 32 11 45 28 10 13 44 52 30 42 41 57 7 7 26 55 17 52 2 6 54 48 58 60 54 53 5 9 40 20 8 18 32 40 24 35\n",
"output": "31 17 45\n30 18 44\n32 4 57\n29 5 56\n33 24 38\n28 28 34\n34 26 36\n27 4 58\n35 30 32\n26 22 40\n36 7 54\n25 5 56\n37 2 59\n24 13 48\n38 11 51\n23 19 43\n39 17 45\n22 21 40\n40 17 44\n35 26 29\n21 3 59\n41 6 56\n35 33 52\n28 12 27\n20 11 50\n28 35 48\n42 24 38\n19 18 43\n43 3 59\n34 24 25\n18 18 44\n34 37 53\n44 12 50\n33 11 23\n33 39 51\n17 6 55\n45 20 42\n16 3 58\n35 21 25\n46 1 60\n15 11 51\n34 15 23\n47 20 42\n14 7 55\n48 14 47\n13 14 47\n49 21 41\n12 11 51\n50 11 51\n11 20 42\n51 19 42\n26 15 21\n10 19 43\n52 13 48\n26 41 48\n9 20 41\n30 9 17\n53 2 60\n8 14 48\n54 2 59\n30 45 49\n7 13 48\n55 8 54\n6 5 57\n56 15 46\n31 6 16\n5 9 53\n57 17 44\n31 46 55\n35 8 20\n4 9 52\n58 5 56\n3 16 45\n59 10 51\n2 11 51\n60 3 59\n22 41 47\n42 17 23\n1 18 43\n61 4 58\n42 39 55\n-1\n22 19 20\n30 50 55\n-1\n-1\n-1\n-1\n-1\n-1\n34 10 14\n23 10 18\n-1\n49 1 20\n23 44 51\n22 1 18\n-1\n-1\n-1\n-1\n"
},
{
"input": "50 23\n11 20 3 5 5 14 20 18 18 22 9 17 6 13 1 23 21 3 2 3 11 4 16 20 14 22 6 6 19 21 13 10 8 10 21 9 10 9 21 23 6 21 21 17 1 23 15 10 13 20\n",
"output": "12 7 17\n11 2 21\n13 11 13\n10 10 14\n14 10 14\n9 5 18\n15 2 21\n8 3 20\n16 3 20\n7 1 22\n13 2 10\n17 4 20\n13 14 19\n6 6 18\n10 9 9\n18 1 23\n5 2 22\n10 15 17\n14 8 9\n14 15 17\n19 7 17\n10 5 8\n4 4 19\n20 2 21\n3 5 18\n21 1 22\n12 1 6\n12 18 23\n2 3 21\n22 2 22\n1 6 18\n23 7 16\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n14 2 7\n-1\n-1\n-1\n10 18 18\n-1\n-1\n-1\n-1\n-1\n"
},
{
"input": "50 27\n12 23 16 12 9 24 3 15 13 23 1 16 17 8 19 17 14 6 22 12 11 16 6 13 15 13 14 19 7 4 23 10 8 4 26 12 8 21 14 6 4 6 12 7 18 2 13 17 24 3\n",
"output": "14 8 19\n13 3 25\n15 6 21\n12 8 19\n16 10 18\n11 2 25\n17 13 15\n10 7 21\n18 8 20\n9 3 25\n17 12 12\n19 6 21\n8 6 22\n20 10 17\n7 5 23\n21 6 22\n6 7 20\n17 16 21\n22 3 24\n5 8 19\n17 1 11\n23 6 21\n14 20 25\n4 8 20\n24 7 21\n3 8 20\n25 7 20\n2 5 23\n14 1 7\n16 6 9\n26 3 25\n20 18 27\n16 19 26\n12 20 23\n1 1 26\n27 8 19\n20 2 9\n-1\n-1\n12 2 7\n15 22 25\n17 22 27\n-1\n18 1 7\n-1\n15 4 5\n-1\n-1\n-1\n16 3 5\n"
},
{
"input": "5 5\n4 1 3 1 1\n",
"output": "3 1 4\n2 3 3\n4 2 4\n1 3 3\n2 2 2\n"
},
{
"input": "100 53\n43 8 14 35 48 10 4 2 38 50 7 25 20 19 33 31 49 51 14 6 34 31 44 40 30 51 41 44 42 33 33 24 33 53 12 20 25 47 16 2 26 5 45 40 21 17 38 37 2 48 16 45 13 11 5 33 38 19 6 2 37 8 45 39 33 15 5 22 14 36 11 23 28 5 46 5 46 35 32 25 26 36 22 42 15 38 41 45 27 53 51 12 16 12 22 10 1 8 20 29\n",
"output": "27 6 48\n26 23 30\n28 20 33\n25 10 44\n29 3 50\n24 22 31\n30 25 28\n23 26 27\n31 8 45\n22 2 51\n32 24 30\n21 15 39\n33 17 36\n20 18 36\n34 11 43\n19 12 42\n35 3 51\n18 2 52\n23 28 41\n26 31 36\n36 10 43\n17 12 42\n37 5 48\n16 7 46\n38 12 41\n15 2 52\n39 7 47\n14 5 48\n40 6 47\n13 11 43\n41 11 43\n30 29 52\n12 11 43\n42 1 53\n23 14 25\n26 3 22\n11 15 39\n43 4 50\n30 9 24\n24 32 33\n10 14 39\n28 34 38\n44 5 49\n9 7 46\n24 1 21\n28 3 19\n45 8 45\n8 9 45\n32 22 23\n46 3 50\n32 31 46\n7 5 49\n24 34 46\n26 37 47\n32 17 21\n47 11 43\n6 8 45\n48 18 36\n28 39 44\n32 15 16\n5 9 45\n33 37 44\n49 5 49\n4 8 46\n50 11 43\n20 3 17\n20 37 41\n3 16 37\n33 3 16\n51 9 44\n23 3 13\n2 16 38\n52 13 40\n32 10 14\n1 4 49\n21 10 14\n53 4 49\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n48 3 17\n-1\n-1\n-1\n-1\n-1\n-1\n21 40 51\n48 37 52\n23 42 53\n-1\n20 42 51\n28 45 45\n25 2 9\n-1\n-1\n"
},
{
"input": "100 65\n20 39 12 31 16 51 58 15 7 37 58 39 39 44 43 55 59 61 13 22 25 13 8 26 3 55 28 45 27 27 19 59 63 13 14 46 7 36 20 9 30 37 63 12 34 59 50 33 65 56 5 17 17 36 61 12 51 45 30 11 12 62 46 65 11 49 49 40 15 19 15 2 41 34 55 57 8 18 39 36 38 49 49 3 15 43 48 13 3 49 58 5 56 41 25 10 64 52 4 54\n",
"output": "33 23 42\n32 14 52\n34 27 38\n31 18 48\n35 25 40\n30 8 58\n36 4 61\n29 26 40\n37 30 36\n28 15 51\n38 4 61\n27 14 52\n39 14 52\n26 11 54\n40 12 54\n25 6 60\n41 4 62\n24 3 63\n42 27 39\n23 22 43\n43 21 45\n34 39 51\n34 19 26\n22 20 45\n37 27 29\n44 6 60\n21 19 46\n45 11 55\n20 20 46\n46 20 46\n37 37 55\n19 4 62\n47 2 64\n33 43 55\n35 41 54\n18 10 55\n33 16 22\n48 15 50\n35 5 24\n37 18 26\n17 18 47\n49 15 51\n16 2 64\n29 14 25\n50 16 49\n15 4 62\n51 8 57\n14 17 49\n52 1 65\n13 5 60\n29 41 45\n34 2 18\n42 10 26\n53 15 50\n12 3 63\n42 40 51\n54 8 58\n11 11 55\n55 18 47\n29 46 56\n31 6 17\n10 2 63\n56 10 55\n9 1 65\n31 49 59\n57 9 57\n8 9 57\n58 13 52\n33 1 15\n23 44 62\n37 3 17\n34 52 53\n7 13 53\n59 16 49\n6 6 60\n60 5 61\n32 6 13\n23 4 21\n5 14 52\n61 15 50\n4 14 51\n62 9 57\n3 9 57\n32 53 55\n43 6 20\n63 12 54\n2 9 56\n43 46 58\n34 54 56\n64 9 57\n1 4 61\n33 56 60\n65 5 60\n-1\n-1\n22 46 55\n-1\n-1\n28 11 14\n-1\n"
},
{
"input": "50 23\n11 20 3 5 5 14 20 18 18 22 9 17 6 13 1 23 21 3 2 3 11 4 16 20 14 22 6 6 19 21 13 10 8 10 21 9 10 9 21 23 6 21 21 17 1 23 15 10 13 20\n",
"output": "12 7 17\n11 2 21\n13 11 13\n10 10 14\n14 10 14\n9 5 18\n15 2 21\n8 3 20\n16 3 20\n7 1 22\n13 2 10\n17 4 20\n13 14 19\n6 6 18\n10 9 9\n18 1 23\n5 2 22\n10 15 17\n14 8 9\n14 15 17\n19 7 17\n10 5 8\n4 4 19\n20 2 21\n3 5 18\n21 1 22\n12 1 6\n12 18 23\n2 3 21\n22 2 22\n1 6 18\n23 7 16\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n14 2 7\n-1\n-1\n-1\n10 18 18\n-1\n-1\n-1\n-1\n-1\n"
},
{
"input": "100 69\n43 49 44 68 20 67 45 53 55 67 68 32 31 6 13 69 18 20 26 5 6 24 46 13 57 8 11 19 27 46 34 32 10 47 28 66 50 49 31 25 54 67 25 27 11 26 41 36 64 55 43 9 65 29 4 45 63 8 45 16 50 58 41 65 1 57 5 56 29 20 49 63 64 28 5 64 64 35 1 27 25 64 42 69 50 41 52 59 31 19 40 50 56 54 63 51 10 49 14 12\n",
"output": "35 14 56\n34 11 59\n36 13 56\n33 1 68\n37 25 44\n32 2 68\n38 13 57\n31 9 61\n39 8 62\n30 2 68\n40 1 68\n29 19 50\n41 20 50\n28 32 37\n42 29 41\n27 1 69\n43 26 43\n26 25 44\n44 22 47\n25 33 37\n45 32 37\n24 23 46\n46 12 57\n23 29 41\n47 7 63\n28 38 45\n22 30 40\n48 26 44\n21 22 48\n49 12 57\n20 18 51\n50 19 50\n28 22 31\n19 12 58\n51 21 48\n18 2 67\n52 10 59\n17 11 59\n53 20 50\n37 45 69\n16 8 61\n54 2 68\n25 8 32\n25 38 64\n37 14 24\n45 38 63\n15 15 55\n55 17 52\n14 3 66\n56 8 62\n13 14 56\n42 20 28\n57 3 67\n45 3 31\n42 42 45\n12 13 57\n58 4 66\n43 44 51\n11 13 57\n28 46 61\n59 10 59\n10 6 63\n60 15 55\n9 3 67\n42 46 46\n61 7 63\n43 21 25\n8 7 62\n22 1 29\n22 41 60\n62 11 59\n7 4 66\n63 3 66\n23 1 28\n23 42 46\n6 3 66\n64 3 66\n5 18 52\n26 45 45\n65 22 48\n48 1 25\n4 3 66\n66 14 55\n3 1 69\n67 10 59\n2 15 55\n68 9 60\n1 6 64\n69 20 50\n42 47 65\n-1\n-1\n-1\n-1\n-1\n-1\n26 15 24\n-1\n26 46 59\n28 10 21\n"
},
{
"input": "10 13\n12 8 7 11 11 9 2 12 10 1\n",
"output": "7 1 12\n6 3 10\n8 4 10\n5 2 12\n9 2 12\n4 3 11\n10 6 7\n3 1 12\n11 2 11\n10 8 8\n"
},
{
"input": "1 5\n5\n",
"output": "3 1 5\n"
},
{
"input": "100 59\n48 13 59 51 54 5 35 36 16 25 18 59 9 42 58 1 53 12 19 9 54 5 51 42 45 15 4 35 33 19 36 42 14 46 41 13 7 17 43 43 36 7 24 40 40 1 43 4 42 4 37 51 56 12 5 59 56 21 21 30 54 9 19 30 58 18 7 21 45 32 45 8 12 36 29 52 37 48 27 55 10 28 51 3 33 11 15 49 47 17 22 42 33 14 47 23 42 2 22 10\n",
"output": "30 6 53\n29 24 36\n31 1 59\n28 5 55\n32 3 56\n27 28 32\n33 13 47\n26 12 47\n34 22 37\n25 18 42\n35 21 38\n24 1 59\n36 26 34\n23 9 50\n37 1 58\n27 27 27\n22 4 56\n38 24 35\n21 21 39\n27 33 41\n39 3 56\n27 22 26\n20 5 55\n40 9 50\n19 8 52\n41 23 37\n29 20 23\n18 13 47\n42 14 46\n29 37 55\n17 12 47\n43 9 50\n16 23 36\n44 7 52\n15 10 50\n36 13 25\n36 35 41\n45 22 38\n14 9 51\n46 9 51\n13 12 47\n27 15 21\n47 18 41\n12 10 49\n48 10 49\n29 19 19\n11 9 51\n34 38 41\n49 9 50\n29 15 18\n10 12 48\n50 5 55\n9 2 57\n34 10 21\n35 39 43\n51 1 59\n8 2 57\n38 36 56\n38 3 23\n52 15 44\n7 3 56\n27 42 50\n35 2 20\n53 15 44\n6 1 58\n34 42 59\n29 8 14\n41 2 22\n54 8 52\n5 14 45\n55 8 52\n25 10 17\n25 43 54\n4 12 47\n56 16 44\n3 4 55\n57 12 48\n2 6 53\n58 17 43\n1 3 57\n36 42 51\n59 16 43\n-1\n21 18 20\n-1\n21 40 50\n35 44 58\n-1\n-1\n41 38 54\n16 37 58\n-1\n-1\n27 1 14\n-1\n-1\n-1\n33 11 12\n16 1 22\n33 48 57\n"
},
{
"input": "3 3\n3 2 3\n",
"output": "2 1 3\n1 1 2\n3 1 3\n"
},
{
"input": "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16 29 7 12 17 5 17 14 6 15 8 25 11 16 14 4 3 7 25 2 5 2 12 12 22 18 14 16 5 19 25 4 21 24 7 11 21 27 10 16 21 17 19 13\n",
"output": "15 6 24\n14 8 22\n16 8 22\n13 2 28\n17 14 15\n12 3 27\n17 16 17\n18 13 17\n11 1 29\n19 10 20\n10 12 17\n17 10 13\n20 5 24\n9 10 20\n21 2 28\n8 7 22\n17 18 23\n18 7 12\n22 10 19\n18 18 19\n7 13 17\n23 9 20\n6 11 18\n24 4 26\n5 10 20\n10 18 24\n25 10 20\n4 9 21\n26 6 24\n3 1 29\n17 2 9\n18 20 23\n10 3 11\n27 9 21\n2 8 21\n28 4 25\n1 7 22\n29 1 29\n14 1 7\n7 1 12\n-1\n14 23 27\n-1\n-1\n16 2 7\n-1\n19 2 9\n-1\n7 18 28\n-1\n-1\n16 23 26\n15 3 5\n19 21 27\n-1\n15 25 26\n17 24 28\n9 8 9\n-1\n-1\n-1\n-1\n-1\n-1\n9 21 25\n-1\n-1\n18 3 6\n-1\n-1\n22 20 26\n6 19 29\n-1\n-1\n6 1 10\n-1\n-1\n-1\n-1\n-1\n"
},
{
"input": "4 5\n5 5 3 5\n",
"output": "3 1 5\n2 1 5\n4 2 4\n1 1 5\n"
},
{
"input": "10 11\n3 11 6 4 4 11 9 2 1 9\n",
"output": "6 5 7\n5 1 11\n7 3 8\n4 4 7\n8 4 7\n3 1 11\n9 2 10\n6 3 4\n6 8 8\n2 2 10\n"
},
{
"input": "3 5\n2 5 2\n",
"output": "3 2 3\n2 1 5\n3 4 5\n"
},
{
"input": "50 25\n19 18 3 12 15 2 22 14 4 4 6 15 16 1 23 1 21 12 13 9 22 5 17 6 8 24 12 2 13 13 22 6 4 7 23 20 8 3 5 6 9 3 1 17 22 7 23 25 23 13\n",
"output": "13 4 22\n12 4 21\n14 12 14\n11 7 18\n15 6 20\n10 12 13\n16 2 23\n9 6 19\n14 8 11\n14 15 18\n17 10 15\n8 6 20\n18 5 20\n10 14 14\n7 2 24\n10 11 11\n19 3 23\n6 7 18\n20 7 19\n10 15 23\n5 2 23\n10 6 10\n21 5 21\n14 2 7\n17 16 23\n4 1 24\n22 7 18\n14 19 20\n3 7 19\n23 7 19\n2 2 23\n11 19 24\n17 6 9\n24 10 16\n1 2 24\n25 3 22\n24 2 9\n11 4 6\n14 21 25\n9 20 25\n24 17 25\n12 22 24\n13 3 3\n-1\n-1\n6 19 25\n-1\n-1\n-1\n-1\n"
},
{
"input": "50 21\n8 17 19 1 14 17 16 19 6 2 8 5 20 17 6 17 20 4 16 15 16 17 4 3 17 20 17 8 13 10 21 21 6 13 6 13 10 5 12 7 21 21 21 2 12 16 13 5 5 9\n",
"output": "11 7 14\n10 3 19\n12 2 20\n9 11 11\n13 4 17\n8 3 19\n14 3 18\n7 2 20\n9 5 10\n9 12 13\n15 7 14\n11 15 19\n6 1 20\n16 3 19\n5 8 13\n17 3 19\n4 1 20\n9 14 17\n18 3 18\n3 4 18\n19 3 18\n2 3 19\n11 3 6\n15 15 17\n20 3 19\n1 1 20\n21 3 19\n5 14 21\n-1\n-1\n-1\n-1\n15 1 6\n-1\n5 2 7\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n9 3 4\n-1\n-1\n-1\n-1\n-1\n-1\n"
},
{
"input": "50 25\n19 18 3 12 15 2 22 14 4 4 6 15 16 1 23 1 21 12 13 9 22 5 17 6 8 24 12 2 13 13 22 6 4 7 23 20 8 3 5 6 9 3 1 17 22 7 23 25 23 13\n",
"output": "13 4 22\n12 4 21\n14 12 14\n11 7 18\n15 6 20\n10 12 13\n16 2 23\n9 6 19\n14 8 11\n14 15 18\n17 10 15\n8 6 20\n18 5 20\n10 14 14\n7 2 24\n10 11 11\n19 3 23\n6 7 18\n20 7 19\n10 15 23\n5 2 23\n10 6 10\n21 5 21\n14 2 7\n17 16 23\n4 1 24\n22 7 18\n14 19 20\n3 7 19\n23 7 19\n2 2 23\n11 19 24\n17 6 9\n24 10 16\n1 2 24\n25 3 22\n24 2 9\n11 4 6\n14 21 25\n9 20 25\n24 17 25\n12 22 24\n13 3 3\n-1\n-1\n6 19 25\n-1\n-1\n-1\n-1\n"
},
{
"input": "100 55\n9 2 36 28 47 12 54 2 18 34 15 25 19 19 22 27 55 13 41 8 31 31 55 26 49 26 44 15 30 18 3 47 40 16 41 1 5 32 49 51 15 29 43 54 24 30 51 52 34 33 31 51 13 3 12 13 30 21 3 25 39 43 25 25 15 44 26 40 14 40 32 7 39 16 45 26 44 5 35 41 17 14 32 44 30 41 5 35 16 43 25 7 19 1 39 20 5 39 15 16\n",
"output": "28 24 32\n27 27 28\n29 10 45\n26 14 41\n30 5 51\n25 22 33\n31 1 54\n27 29 30\n24 19 36\n32 11 44\n23 21 35\n33 16 40\n22 19 37\n34 19 37\n21 17 38\n35 15 41\n20 1 55\n27 14 26\n36 8 48\n27 31 38\n19 13 43\n37 13 43\n18 1 55\n38 15 40\n17 4 52\n39 15 40\n16 6 49\n28 9 23\n40 13 42\n28 33 50\n25 34 36\n15 5 51\n41 8 47\n25 6 21\n14 8 48\n25 37 37\n27 39 43\n42 12 43\n13 4 52\n43 3 53\n12 21 35\n44 14 42\n11 7 49\n45 1 54\n10 16 39\n46 13 42\n9 3 53\n47 2 53\n8 11 44\n48 12 44\n7 13 43\n49 3 53\n23 8 20\n23 36 38\n24 37 48\n25 38 50\n6 13 42\n50 18 38\n24 16 18\n5 16 40\n51 9 47\n4 7 49\n52 16 40\n3 16 40\n22 4 18\n53 6 49\n2 15 40\n54 8 47\n22 38 51\n1 8 47\n55 12 43\n23 39 45\n-1\n34 3 18\n-1\n-1\n-1\n26 42 46\n-1\n-1\n34 38 54\n24 2 15\n-1\n-1\n-1\n-1\n27 9 13\n-1\n21 39 54\n-1\n-1\n26 7 13\n12 2 20\n27 44 44\n-1\n12 36 55\n27 45 49\n-1\n33 1 15\n21 1 16\n"
},
{
"input": "10 15\n15 6 1 9 3 10 11 1 14 10\n",
"output": "8 1 15\n7 5 10\n9 8 8\n6 4 12\n10 7 9\n5 3 12\n11 3 13\n9 7 7\n4 1 14\n12 3 12\n"
},
{
"input": "10 17\n5 8 13 5 11 12 10 17 16 7\n",
"output": "9 7 11\n8 5 12\n10 3 15\n7 7 11\n11 4 14\n6 3 14\n12 4 13\n5 1 17\n13 1 16\n4 6 12\n"
},
{
"input": "100 63\n37 58 22 61 4 24 39 23 3 7 52 9 39 33 28 58 44 32 26 46 51 10 18 14 2 33 36 48 60 45 23 31 62 39 22 59 53 8 45 63 49 37 50 4 7 32 13 62 24 29 57 40 26 58 29 20 3 8 38 8 30 42 16 35 54 9 3 44 15 39 31 59 56 36 27 12 25 14 48 60 61 36 14 6 38 42 55 34 63 52 7 17 39 32 29 22 36 26 11 6\n",
"output": "32 14 50\n31 3 60\n33 21 42\n30 2 62\n34 30 33\n29 20 43\n35 13 51\n28 21 43\n36 31 33\n27 29 35\n37 6 57\n34 34 42\n26 13 51\n38 16 48\n25 18 45\n39 3 60\n24 10 53\n40 16 47\n23 19 44\n41 9 54\n22 7 57\n34 20 29\n36 13 30\n36 34 47\n27 27 28\n42 16 48\n21 14 49\n43 8 55\n20 2 61\n44 10 54\n19 21 43\n45 17 47\n18 1 62\n46 13 51\n27 36 57\n17 3 61\n47 6 58\n27 19 26\n16 10 54\n48 1 63\n15 8 56\n49 14 50\n14 7 56\n33 43 46\n33 14 20\n50 16 47\n34 43 55\n13 1 62\n51 20 43\n12 18 46\n52 4 60\n11 12 51\n53 19 44\n10 3 60\n54 18 46\n29 44 63\n34 17 19\n28 13 20\n9 13 50\n28 44 51\n55 17 46\n8 11 52\n29 4 19\n56 15 49\n7 5 58\n33 47 55\n34 14 16\n57 10 53\n27 4 18\n6 13 51\n58 17 47\n5 3 61\n59 4 59\n4 14 49\n60 19 45\n32 2 13\n3 20 44\n36 48 61\n61 8 55\n2 2 61\n62 2 62\n1 14 49\n25 46 59\n32 51 56\n63 13 50\n-1\n-1\n-1\n-1\n-1\n33 7 13\n23 45 61\n-1\n-1\n-1\n-1\n-1\n-1\n34 3 13\n25 12 17\n"
},
{
"input": "50 27\n12 23 16 12 9 24 3 15 13 23 1 16 17 8 19 17 14 6 22 12 11 16 6 13 15 13 14 19 7 4 23 10 8 4 26 12 8 21 14 6 4 6 12 7 18 2 13 17 24 3\n",
"output": "14 8 19\n13 3 25\n15 6 21\n12 8 19\n16 10 18\n11 2 25\n17 13 15\n10 7 21\n18 8 20\n9 3 25\n17 12 12\n19 6 21\n8 6 22\n20 10 17\n7 5 23\n21 6 22\n6 7 20\n17 16 21\n22 3 24\n5 8 19\n17 1 11\n23 6 21\n14 20 25\n4 8 20\n24 7 21\n3 8 20\n25 7 20\n2 5 23\n14 1 7\n16 6 9\n26 3 25\n20 18 27\n16 19 26\n12 20 23\n1 1 26\n27 8 19\n20 2 9\n-1\n-1\n12 2 7\n15 22 25\n17 22 27\n-1\n18 1 7\n-1\n15 4 5\n-1\n-1\n-1\n16 3 5\n"
},
{
"input": "100 67\n66 12 2 49 62 63 59 14 13 26 15 25 22 16 33 52 15 14 13 33 9 10 53 28 17 27 18 39 35 64 1 59 33 24 66 64 4 2 4 5 22 9 52 36 44 57 62 3 52 21 62 55 25 2 65 18 20 40 8 30 27 28 47 19 67 67 42 6 53 17 36 38 57 37 45 13 58 12 31 24 15 67 9 18 56 20 34 8 20 31 13 19 42 12 16 15 54 35 20 33\n",
"output": "34 1 66\n33 28 39\n35 33 34\n32 10 58\n36 3 64\n31 3 65\n37 5 63\n30 27 40\n38 28 40\n29 21 46\n39 27 41\n28 22 46\n40 23 44\n35 35 50\n27 18 50\n41 8 59\n35 18 32\n26 27 40\n42 28 40\n25 18 50\n33 40 48\n43 29 38\n24 8 60\n44 20 47\n23 26 42\n45 21 47\n22 25 42\n46 15 53\n21 17 51\n47 2 65\n33 27 27\n20 5 63\n48 18 50\n33 3 26\n19 1 66\n49 2 65\n30 41 44\n38 26 27\n38 41 44\n30 22 26\n18 23 44\n38 17 25\n50 8 59\n17 16 51\n51 12 55\n16 6 62\n52 3 64\n39 24 26\n15 8 59\n39 42 62\n53 3 64\n14 7 61\n43 39 63\n26 41 42\n54 2 66\n30 45 62\n38 45 64\n13 14 53\n42 20 27\n55 19 48\n42 41 67\n43 1 28\n12 11 57\n26 8 26\n56 1 67\n11 1 67\n57 13 54\n33 49 54\n10 8 60\n39 7 23\n58 16 51\n9 15 52\n59 6 62\n8 16 52\n60 12 56\n26 43 55\n7 5 62\n30 10 21\n61 19 49\n23 2 25\n40 45 59\n6 1 67\n29 47 55\n40 5 22\n62 6 61\n28 2 21\n5 17 50\n35 10 17\n28 47 66\n63 19 49\n35 51 63\n29 2 20\n4 13 54\n23 43 54\n22 43 58\n22 10 24\n64 7 60\n3 17 51\n44 48 67\n65 18 50\n"
},
{
"input": "100 51\n49 27 24 32 36 5 25 25 11 42 32 38 17 30 10 49 23 32 12 42 19 44 5 22 30 21 19 18 36 13 48 46 43 21 13 18 41 13 42 3 27 41 21 41 7 26 51 23 14 13 43 6 5 6 32 44 19 5 44 36 29 48 24 22 45 12 24 48 9 7 7 14 29 26 11 30 23 14 37 13 25 28 28 38 22 41 43 46 26 38 44 48 32 49 32 25 50 33 24 4\n",
"output": "26 2 50\n25 13 39\n27 14 37\n24 10 41\n28 8 43\n23 24 28\n29 14 38\n22 14 38\n30 21 31\n21 5 46\n31 10 41\n20 7 44\n32 18 34\n19 11 40\n33 21 30\n18 2 50\n34 15 37\n17 10 41\n23 12 23\n35 5 46\n16 17 35\n36 4 47\n23 29 33\n15 15 36\n37 11 40\n14 16 36\n38 17 35\n13 17 34\n39 8 43\n30 8 20\n12 2 49\n40 3 48\n11 5 47\n41 16 36\n30 32 44\n23 34 51\n10 6 46\n33 31 43\n42 5 46\n27 38 40\n9 13 39\n43 6 46\n8 16 36\n44 6 46\n33 14 20\n7 13 38\n45 1 51\n6 15 37\n32 4 17\n27 1 13\n46 5 47\n25 7 12\n25 40 44\n32 35 40\n5 10 41\n47 4 47\n4 17 35\n27 41 45\n48 4 47\n3 8 43\n49 12 40\n2 2 49\n50 14 37\n1 15 36\n51 4 48\n29 2 13\n-1\n-1\n29 39 47\n22 7 13\n22 39 45\n16 3 16\n-1\n-1\n23 1 11\n-1\n-1\n16 36 49\n-1\n33 1 13\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n24 42 45\n"
},
{
"input": "10 19\n8 19 17 12 4 5 9 16 7 3\n",
"output": "10 6 13\n9 1 19\n11 2 18\n8 4 15\n12 8 11\n7 8 12\n13 6 14\n6 2 17\n14 7 13\n10 14 16\n"
},
{
"input": "50 21\n8 17 19 1 14 17 16 19 6 2 8 5 20 17 6 17 20 4 16 15 16 17 4 3 17 20 17 8 13 10 21 21 6 13 6 13 10 5 12 7 21 21 21 2 12 16 13 5 5 9\n",
"output": "11 7 14\n10 3 19\n12 2 20\n9 11 11\n13 4 17\n8 3 19\n14 3 18\n7 2 20\n9 5 10\n9 12 13\n15 7 14\n11 15 19\n6 1 20\n16 3 19\n5 8 13\n17 3 19\n4 1 20\n9 14 17\n18 3 18\n3 4 18\n19 3 18\n2 3 19\n11 3 6\n15 15 17\n20 3 19\n1 1 20\n21 3 19\n5 14 21\n-1\n-1\n-1\n-1\n15 1 6\n-1\n5 2 7\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n9 3 4\n-1\n-1\n-1\n-1\n-1\n-1\n"
}
] | code_contests | python | 0.4 | f1aef2dfdde62974df1766ac27e989a9 |
Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates.
There are a total of n students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. After that, Technogoblet selects the strongest student from each school to participate.
Arkady is a hacker who wants to have k Chosen Ones selected by the Technogoblet. Unfortunately, not all of them are the strongest in their schools, but Arkady can make up some new school names and replace some names from Technogoblet with those. You can't use each made-up name more than once. In that case, Technogoblet would select the strongest student in those made-up schools too.
You know the power of each student and schools they study in. Calculate the minimal number of schools Arkady has to make up so that k Chosen Ones would be selected by the Technogoblet.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 100, 1 ≤ m, k ≤ n) — the total number of students, the number of schools and the number of the Chosen Ones.
The second line contains n different integers p_1, p_2, …, p_n (1 ≤ p_i ≤ n), where p_i denotes the power of i-th student. The bigger the power, the stronger the student.
The third line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ m), where s_i denotes the school the i-th student goes to. At least one student studies in each of the schools.
The fourth line contains k different integers c_1, c_2, …, c_k (1 ≤ c_i ≤ n) — the id's of the Chosen Ones.
Output
Output a single integer — the minimal number of schools to be made up by Arkady so that k Chosen Ones would be selected by the Technogoblet.
Examples
Input
7 3 1
1 5 3 4 6 7 2
1 3 1 2 1 2 3
3
Output
1
Input
8 4 4
1 2 3 4 5 6 7 8
4 3 2 1 4 3 2 1
3 4 5 6
Output
2
Note
In the first example there's just a single Chosen One with id 3. His power is equal to 3, but in the same school 1, there's a student with id 5 and power 6, and that means inaction would not lead to the latter being chosen. If we, however, make up a new school (let its id be 4) for the Chosen One, Technogoblet would select students with ids 2 (strongest in 3), 5 (strongest in 1), 6 (strongest in 2) and 3 (strongest in 4).
In the second example, you can change the school of student 3 to the made-up 5 and the school of student 4 to the made-up 6. It will cause the Technogoblet to choose students 8, 7, 6, 5, 3 and 4.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n,m,k=map(int,input().split())
p=list(map(int,input().split()))
s=list(map(int,input().split()))
c=set(map(int,input().split()))
d={}
for i in range(n):
if s[i] not in d:
d[s[i]]=[-1]
if p[i]>d[s[i]][0]:
d[s[i]]=(p[i],i)
st=set()
for i in d:
st.add(d[i][1]+1)
#print(c,st)
c=c.difference(st)
print(len(c))
| python | code_algorithm | [
{
"input": "8 4 4\n1 2 3 4 5 6 7 8\n4 3 2 1 4 3 2 1\n3 4 5 6\n",
"output": "2\n"
},
{
"input": "7 3 1\n1 5 3 4 6 7 2\n1 3 1 2 1 2 3\n3\n",
"output": "1\n"
},
{
"input": "2 1 1\n1 2\n1 1\n1\n",
"output": "1\n"
},
{
"input": "2 1 1\n1 2\n1 1\n2\n",
"output": "0\n"
},
{
"input": "1 1 1\n1\n1\n1\n",
"output": "0\n"
},
{
"input": "10 5 4\n4 2 1 7 10 9 6 3 5 8\n3 2 1 4 5 1 4 2 4 2\n9 3 2 6\n",
"output": "3\n"
},
{
"input": "10 1 10\n9 1 2 3 5 7 4 10 6 8\n1 1 1 1 1 1 1 1 1 1\n8 9 5 7 1 10 6 2 4 3\n",
"output": "9\n"
},
{
"input": "5 1 1\n4 3 2 1 5\n1 1 1 1 1\n5\n",
"output": "0\n"
},
{
"input": "13 2 4\n8 13 2 4 6 9 5 12 3 11 1 7 10\n2 2 1 2 2 1 1 1 1 2 1 1 2\n6 8 4 13\n",
"output": "3\n"
},
{
"input": "100 10 1\n62 68 24 82 66 47 73 43 85 23 78 13 94 14 84 17 27 5 72 48 59 46 97 81 88 9 76 69 11 15 12 61 70 7 91 34 99 52 54 57 56 64 55 67 40 38 74 25 30 4 22 92 33 3 86 45 37 26 87 53 75 71 58 96 98 20 36 1 95 63 10 49 19 41 89 21 39 100 93 42 32 90 28 83 6 29 60 65 44 35 18 16 8 50 80 31 51 2 77 79\n6 6 6 4 6 6 6 6 6 6 6 6 6 6 6 3 6 2 6 6 6 6 6 6 6 9 6 6 5 6 8 6 6 6 6 6 6 10 6 6 6 6 6 6 6 6 6 1 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6\n84\n",
"output": "1\n"
},
{
"input": "10 10 4\n3 4 6 1 5 2 8 7 10 9\n4 10 5 7 6 2 1 3 8 9\n5 8 4 7\n",
"output": "0\n"
},
{
"input": "5 1 1\n4 3 2 1 5\n1 1 1 1 1\n1\n",
"output": "1\n"
}
] | code_contests | python | 0.8 | 7498db4523629d099543bc46d180784e |
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show, the episode of which will be shown in i-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows d (1 ≤ d ≤ n) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of d consecutive days in which all episodes belong to the purchased shows.
Input
The first line contains an integer t (1 ≤ t ≤ 100) — the number of test cases in the input. Then t test case descriptions follow.
The first line of each test case contains three integers n, k and d (1 ≤ n ≤ 100, 1 ≤ k ≤ 100, 1 ≤ d ≤ n). The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show that is broadcasted on the i-th day.
It is guaranteed that the sum of the values of n for all test cases in the input does not exceed 100.
Output
Print t integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for d consecutive days. Please note that it is permissible that you will be able to watch more than d days in a row.
Example
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
Note
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show 1 and on show 2. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows 3,5,7,8,9, and you will be able to watch shows for the last eight days.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | x = int(input())
for i in range(x):
n, k, d = map(int, input().split(' '))
l = map(int, input().split(' '))
l = list(l)
ar = []
for j in range(n-d+1):
ar.append(len(set(l[j:(j+d)])))
print(min(ar)) | python | code_algorithm | [
{
"input": "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n",
"output": "2\n1\n4\n5\n"
},
{
"input": "1\n100 20 1\n10 17 9 8 11 8 8 3 7 20 11 10 7 7 2 13 10 7 7 10 7 8 4 17 20 9 5 18 12 8 3 5 19 1 18 14 9 11 12 11 11 12 12 9 13 8 20 3 8 1 15 20 6 18 8 1 13 11 4 17 12 15 4 4 11 19 18 5 2 12 15 20 5 8 11 16 14 13 17 14 14 5 6 8 8 13 6 3 18 14 8 14 11 11 9 4 18 1 16 6\n",
"output": "1\n"
},
{
"input": "1\n100 100 99\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n",
"output": "99\n"
},
{
"input": "1\n100 100 2\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\n",
"output": "2\n"
},
{
"input": "1\n100 100 33\n78 92 82 75 58 98 94 39 38 88 89 78 2 95 53 47 74 95 14 92 49 44 8 67 31 77 90 20 16 92 19 32 26 75 81 4 79 46 21 44 5 19 64 72 13 9 74 58 84 62 70 86 77 4 39 97 1 67 98 99 89 34 29 13 24 2 69 68 30 66 77 16 26 49 1 25 89 26 28 25 96 55 51 44 10 7 36 75 12 81 31 46 52 55 48 78 82 95 39 44\n",
"output": "28\n"
},
{
"input": "1\n100 100 10\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\n",
"output": "10\n"
},
{
"input": "1\n100 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "1\n"
},
{
"input": "1\n100 1 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\n",
"output": "1\n"
},
{
"input": "1\n100 100 99\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"output": "99\n"
},
{
"input": "1\n100 100 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\n",
"output": "100\n"
},
{
"input": "1\n100 10 100\n9 2 2 3 5 2 2 3 4 9 5 3 6 2 1 4 4 8 6 2 3 10 4 1 5 2 8 8 3 9 2 7 2 3 4 2 2 8 9 7 10 3 7 7 4 4 8 8 9 7 1 8 10 3 6 8 1 9 4 6 5 6 9 2 9 6 7 10 5 8 7 10 6 1 9 2 10 10 10 9 6 5 6 9 2 8 1 2 2 5 6 6 3 3 7 10 10 1 6 3\n",
"output": "10\n"
},
{
"input": "10\n6 9 4\n8 8 2 5 8 9\n5 3 4\n1 3 1 2 1\n10 5 10\n3 2 4 2 1 1 2 2 3 4\n7 7 3\n4 6 2 6 4 5 2\n9 9 6\n4 6 7 2 5 5 7 4 8\n6 5 4\n2 3 2 5 5 5\n8 3 4\n2 3 2 3 2 1 1 3\n10 6 9\n6 2 4 1 4 5 5 2 1 1\n8 7 2\n4 4 5 6 2 5 3 4\n1 9 1\n3\n",
"output": "3\n3\n4\n2\n4\n2\n2\n4\n1\n1\n"
},
{
"input": "1\n100 100 50\n40 23 65 71 63 65 82 49 42 62 80 68 30 97 95 11 19 16 50 33 99 40 100 88 7 52 83 80 68 30 32 40 67 16 45 89 54 88 9 42 40 65 96 97 9 100 53 84 40 40 66 13 47 30 71 14 83 18 35 70 73 52 17 91 87 59 81 5 84 94 1 9 23 90 32 91 69 77 38 84 38 74 6 26 100 47 39 23 84 90 67 86 67 80 31 51 71 97 69 68\n",
"output": "34\n"
},
{
"input": "1\n100 100 1\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n",
"output": "1\n"
},
{
"input": "1\n100 100 100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n",
"output": "100\n"
},
{
"input": "1\n100 100 1\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\n",
"output": "1\n"
},
{
"input": "15\n6 4 6\n2 3 2 3 4 2\n7 8 4\n5 6 2 7 7 3 3\n8 1 5\n1 1 1 1 1 1 1 1\n1 5 1\n1\n2 7 2\n6 7\n6 8 4\n8 5 4 1 6 6\n1 8 1\n2\n3 8 2\n2 3 3\n2 2 1\n1 1\n8 2 5\n2 2 1 1 1 1 1 1\n7 6 4\n2 4 1 1 2 4 3\n8 8 2\n6 5 6 1 3 1 2 8\n5 6 1\n6 1 2 6 2\n6 5 5\n1 5 2 4 4 5\n7 1 6\n1 1 1 1 1 1 1\n",
"output": "3\n2\n1\n1\n2\n3\n1\n1\n1\n1\n3\n2\n1\n3\n1\n"
},
{
"input": "1\n100 2 100\n2 1 2 2 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 1 1 1 2 2 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 2 2 2 1 1 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 2 1 2 2 2 1 2\n",
"output": "2\n"
},
{
"input": "1\n100 90 100\n8 39 60 46 68 2 42 45 7 54 89 78 16 59 21 29 5 30 20 12 64 42 34 33 13 17 55 30 54 31 23 27 38 36 2 49 45 43 47 55 4 6 55 38 60 16 34 86 67 76 55 86 39 62 12 58 74 51 10 31 38 85 50 61 48 35 69 24 64 53 4 19 15 35 28 22 88 3 25 60 9 40 67 47 26 57 58 61 65 21 76 4 15 35 37 49 62 45 81 32\n",
"output": "67\n"
},
{
"input": "1\n100 20 2\n18 1 3 1 13 1 3 15 3 2 7 14 1 8 1 10 1 1 9 18 11 6 9 12 17 5 6 7 13 14 9 4 6 14 7 14 19 6 13 10 7 2 17 3 10 11 11 7 2 4 9 12 11 6 20 20 4 16 7 10 8 4 19 18 2 4 6 5 20 2 12 6 20 20 18 7 11 20 10 2 8 5 16 4 19 17 18 9 7 9 13 10 3 12 18 2 6 12 18 10\n",
"output": "1\n"
},
{
"input": "1\n100 100 2\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n",
"output": "2\n"
},
{
"input": "1\n100 16 100\n1 11 2 2 13 8 3 15 8 11 13 1 16 16 3 5 12 10 11 16 1 14 16 8 14 3 15 8 2 8 10 1 16 14 8 4 2 10 3 8 3 5 8 10 4 12 11 8 8 15 16 5 7 6 3 9 15 7 1 14 14 2 13 4 10 6 12 13 9 8 9 2 9 3 2 12 9 3 8 11 14 9 3 3 15 10 12 10 10 16 2 12 13 7 6 7 13 1 14 15\n",
"output": "16\n"
},
{
"input": "1\n100 100 3\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n",
"output": "3\n"
},
{
"input": "30\n4 4 1\n3 3 1 2\n4 4 1\n4 1 4 1\n1 1 1\n1\n3 2 1\n2 1 2\n4 4 2\n3 2 2 2\n4 2 4\n1 2 2 2\n1 4 1\n4\n2 3 1\n2 3\n2 2 1\n2 2\n4 4 2\n1 2 4 2\n4 4 1\n2 4 4 3\n4 3 1\n1 3 1 3\n1 1 1\n1\n2 2 2\n2 1\n2 4 1\n1 4\n2 4 1\n3 4\n1 2 1\n1\n2 4 2\n2 1\n3 1 2\n1 1 1\n2 4 1\n1 4\n2 3 1\n3 3\n4 2 2\n2 1 2 2\n3 2 2\n2 2 1\n4 3 1\n2 2 1 2\n2 3 1\n1 3\n4 4 4\n3 2 2 3\n1 4 1\n1\n2 1 2\n1 1\n1 4 1\n4\n2 3 1\n3 3\n",
"output": "1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n1\n1\n1\n2\n1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n2\n1\n1\n1\n1\n"
},
{
"input": "1\n100 50 100\n22 28 34 29 43 8 12 12 4 29 36 38 22 5 19 38 4 41 20 33 39 11 2 40 42 8 33 23 20 47 45 30 47 33 27 23 50 26 30 43 8 3 4 38 46 32 20 19 10 3 18 29 21 19 37 30 12 38 27 44 24 39 25 18 50 44 37 22 39 41 18 26 37 40 40 16 38 9 12 36 27 31 45 47 31 31 29 48 25 7 29 24 10 2 8 3 36 48 8 9\n",
"output": "42\n"
},
{
"input": "5\n17 10 1\n8 5 10 7 4 7 2 9 8 10 7 2 6 5 1 1 5\n22 13 5\n1 9 12 4 6 1 8 10 1 11 1 2 1 6 8 12 11 8 10 6 2 12\n13 25 7\n22 7 19 12 7 17 7 6 22 19 5 5 23\n1 6 1\n6\n1 15 1\n7\n",
"output": "1\n3\n5\n1\n1\n"
}
] | code_contests | python | 1 | 8faae6e617348fd56aed5a26214976a3 |
You are given a board of size n × n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure.
In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move the figure to cells:
* (i - 1, j - 1);
* (i - 1, j);
* (i - 1, j + 1);
* (i, j - 1);
* (i, j + 1);
* (i + 1, j - 1);
* (i + 1, j);
* (i + 1, j + 1);
Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.
Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. n^2-1 cells should contain 0 figures and one cell should contain n^2 figures).
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 200) — the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 ≤ n < 5 ⋅ 10^5) — the size of the board. It is guaranteed that n is odd (not divisible by 2).
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5 (∑ n ≤ 5 ⋅ 10^5).
Output
For each test case print the answer — the minimum number of moves needed to get all the figures into one cell.
Example
Input
3
1
5
499993
Output
0
40
41664916690999888
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | I = input
for _ in range(int(I())):
n = int(I())+1
s = 0
for i in range(1,n//2):
s += 8*i*i
print(s) | python | code_algorithm | [
{
"input": "3\n1\n5\n499993\n",
"output": "0\n40\n41664916690999888\n"
},
{
"input": "3\n5\n3005\n3005\n",
"output": "40\n9045074040\n9045074040\n"
},
{
"input": "1\n69791\n",
"output": "113312287936960\n"
},
{
"input": "1\n214541\n",
"output": "3291619655775960\n"
},
{
"input": "1\n499999\n",
"output": "41666416667000000\n"
},
{
"input": "1\n214145\n",
"output": "3273426253628160\n"
}
] | code_contests | python | 0 | 9884f87a4188cd662887f5b0488516f9 |
Alica and Bob are playing a game.
Initially they have a binary string s consisting of only characters 0 and 1.
Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent characters of string s and delete them. For example, if s = 1011001 then the following moves are possible:
1. delete s_1 and s_2: 1011001 → 11001;
2. delete s_2 and s_3: 1011001 → 11001;
3. delete s_4 and s_5: 1011001 → 10101;
4. delete s_6 and s_7: 1011001 → 10110.
If a player can't make any move, they lose. Both players play optimally. You have to determine if Alice can win.
Input
First line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.
Only line of each test case contains one string s (1 ≤ |s| ≤ 100), consisting of only characters 0 and 1.
Output
For each test case print answer in the single line.
If Alice can win print DA (YES in Russian) in any register. Otherwise print NET (NO in Russian) in any register.
Example
Input
3
01
1111
0011
Output
DA
NET
NET
Note
In the first test case after Alice's move string s become empty and Bob can not make any move.
In the second test case Alice can not make any move initially.
In the third test case after Alice's move string s turn into 01. Then, after Bob's move string s become empty and Alice can not make any move.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from sys import stdin,stdout
t=int(stdin.readline().strip())
for _ in range(t):
s=stdin.readline().strip()
stdout.write(("NET","DA")[min(s.count('0'),s.count('1')) % 2]+"\n")
| python | code_algorithm | [
{
"input": "3\n01\n1111\n0011\n",
"output": "DA\nNET\nNET\n"
},
{
"input": "1\n00000000000\n",
"output": "NET\n"
},
{
"input": "1\n111111111111111110000000000000000\n",
"output": "NET\n"
},
{
"input": "1\n11111111111\n",
"output": "NET\n"
},
{
"input": "1\n1\n",
"output": "NET\n"
},
{
"input": "1\n0\n",
"output": "NET\n"
},
{
"input": "1\n1111111111\n",
"output": "NET\n"
},
{
"input": "2\n11111111111\n11111111111\n",
"output": "NET\nNET\n"
}
] | code_contests | python | 0 | ff6c9d109e13c3a6ba8235b4a94b4e6d |
The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess noticed that the dragon is very greedy and not too smart. To delay him, the princess decides to borrow a couple of bijous from his treasury. Once the dragon overtakes the princess, she will drop one bijou to distract him. In this case he will stop, pick up the item, return to the cave and spend f hours to straighten the things out in the treasury. Only after this will he resume the chase again from the very beginning.
The princess is going to run on the straight. The distance between the cave and the king's castle she's aiming for is c miles. How many bijous will she need to take from the treasury to be able to reach the castle? If the dragon overtakes the princess at exactly the same moment she has reached the castle, we assume that she reached the castle before the dragon reached her, and doesn't need an extra bijou to hold him off.
Input
The input data contains integers vp, vd, t, f and c, one per line (1 ≤ vp, vd ≤ 100, 1 ≤ t, f ≤ 10, 1 ≤ c ≤ 1000).
Output
Output the minimal number of bijous required for the escape to succeed.
Examples
Input
1
2
1
1
10
Output
2
Input
1
2
1
1
8
Output
1
Note
In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return to the cave and fixing the treasury will take the dragon two more hours; meanwhile the princess will be 4 miles away from the cave. Next time the dragon will overtake the princess 8 miles away from the cave, and she will need the second bijou, but after this she will reach the castle without any further trouble.
The second case is similar to the first one, but the second time the dragon overtakes the princess when she has reached the castle, and she won't need the second bijou.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | vp = int(input())
vd = int(input())
t = int(input())
f = int(input())
c = int(input())
distance = t * vp
time = t
treasure = 0
if vp == vd:
if t == 0:
print(1)
else:
print(0)
elif vp > vd:
print(0)
else:
while distance < c:
timeadd = distance/(vd - vp)
distance += vp * timeadd
if distance >= c:
break
else:
time += timeadd
treasure += 1
timeadd = f + distance/vd
distance += timeadd * vp
print(treasure) | python | code_algorithm | [
{
"input": "1\n2\n1\n1\n10\n",
"output": "2\n"
},
{
"input": "1\n2\n1\n1\n8\n",
"output": "1\n"
},
{
"input": "71\n19\n2\n10\n645\n",
"output": "0\n"
},
{
"input": "6\n24\n9\n8\n628\n",
"output": "3\n"
},
{
"input": "26\n36\n4\n7\n318\n",
"output": "0\n"
},
{
"input": "2\n100\n10\n10\n739\n",
"output": "22\n"
},
{
"input": "47\n43\n10\n9\n43\n",
"output": "0\n"
},
{
"input": "71\n45\n2\n6\n547\n",
"output": "0\n"
},
{
"input": "2\n1\n1\n1\n1000\n",
"output": "0\n"
},
{
"input": "13\n14\n3\n3\n79\n",
"output": "0\n"
},
{
"input": "77\n1\n6\n8\n831\n",
"output": "0\n"
},
{
"input": "2\n27\n4\n9\n937\n",
"output": "15\n"
},
{
"input": "6\n45\n7\n8\n407\n",
"output": "4\n"
},
{
"input": "51\n42\n10\n4\n901\n",
"output": "0\n"
},
{
"input": "2\n12\n6\n4\n907\n",
"output": "10\n"
},
{
"input": "59\n7\n8\n10\n357\n",
"output": "0\n"
},
{
"input": "35\n37\n9\n5\n792\n",
"output": "0\n"
},
{
"input": "31\n40\n6\n1\n397\n",
"output": "0\n"
},
{
"input": "97\n4\n8\n8\n829\n",
"output": "0\n"
},
{
"input": "98\n94\n4\n3\n437\n",
"output": "0\n"
},
{
"input": "38\n50\n1\n8\n761\n",
"output": "1\n"
},
{
"input": "59\n9\n7\n3\n498\n",
"output": "0\n"
},
{
"input": "62\n89\n8\n1\n83\n",
"output": "0\n"
},
{
"input": "1\n100\n1\n1\n1000\n",
"output": "152\n"
},
{
"input": "58\n4\n1\n10\n392\n",
"output": "0\n"
},
{
"input": "83\n7\n7\n7\n46\n",
"output": "0\n"
},
{
"input": "5\n3\n3\n3\n999\n",
"output": "0\n"
},
{
"input": "5\n25\n8\n9\n228\n",
"output": "2\n"
},
{
"input": "17\n99\n2\n3\n293\n",
"output": "3\n"
},
{
"input": "5\n8\n1\n2\n100\n",
"output": "2\n"
},
{
"input": "85\n45\n2\n1\n682\n",
"output": "0\n"
},
{
"input": "75\n26\n4\n3\n504\n",
"output": "0\n"
},
{
"input": "21\n35\n5\n6\n535\n",
"output": "1\n"
},
{
"input": "5\n5\n1\n1\n1000\n",
"output": "0\n"
},
{
"input": "87\n32\n3\n8\n754\n",
"output": "0\n"
},
{
"input": "2\n1\n1\n1\n100\n",
"output": "0\n"
},
{
"input": "67\n34\n7\n4\n954\n",
"output": "0\n"
},
{
"input": "94\n14\n2\n3\n481\n",
"output": "0\n"
},
{
"input": "39\n22\n8\n6\n291\n",
"output": "0\n"
},
{
"input": "74\n11\n8\n7\n835\n",
"output": "0\n"
},
{
"input": "30\n28\n4\n6\n9\n",
"output": "0\n"
},
{
"input": "63\n4\n7\n1\n48\n",
"output": "0\n"
},
{
"input": "55\n35\n5\n10\n592\n",
"output": "0\n"
},
{
"input": "46\n39\n8\n3\n964\n",
"output": "0\n"
},
{
"input": "95\n20\n9\n3\n149\n",
"output": "0\n"
},
{
"input": "34\n9\n6\n6\n70\n",
"output": "0\n"
},
{
"input": "79\n11\n2\n1\n144\n",
"output": "0\n"
},
{
"input": "1\n100\n1\n1\n1\n",
"output": "0\n"
},
{
"input": "14\n18\n5\n9\n862\n",
"output": "1\n"
},
{
"input": "10\n1\n10\n1\n11\n",
"output": "0\n"
},
{
"input": "78\n7\n7\n6\n38\n",
"output": "0\n"
},
{
"input": "93\n19\n3\n3\n82\n",
"output": "0\n"
},
{
"input": "100\n32\n1\n8\n537\n",
"output": "0\n"
},
{
"input": "25\n28\n4\n9\n226\n",
"output": "0\n"
},
{
"input": "100\n1\n1\n1\n1000\n",
"output": "0\n"
},
{
"input": "2\n1\n1\n1\n10\n",
"output": "0\n"
},
{
"input": "100\n99\n1\n1\n1000\n",
"output": "0\n"
},
{
"input": "43\n50\n1\n8\n544\n",
"output": "1\n"
},
{
"input": "50\n15\n1\n3\n216\n",
"output": "0\n"
},
{
"input": "63\n53\n5\n4\n189\n",
"output": "0\n"
},
{
"input": "79\n10\n4\n6\n3\n",
"output": "0\n"
},
{
"input": "49\n7\n2\n5\n326\n",
"output": "0\n"
},
{
"input": "10\n25\n9\n8\n363\n",
"output": "1\n"
},
{
"input": "17\n42\n10\n5\n684\n",
"output": "1\n"
},
{
"input": "86\n21\n7\n2\n982\n",
"output": "0\n"
}
] | code_contests | python | 0 | e2aa98cc5b6f7b5beb5a3dbb6558c6e7 |
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store:
* The store has an infinite number of items of every product.
* All products have the same price: 2 rubles per item.
* For every product i there is a discount for experienced buyers: if you buy b_i items of products (of any type, not necessarily type i), then for all future purchases of the i-th product there is a 50\% discount (so you can buy an item of the i-th product for 1 ruble!).
Lena needs to buy n products: she must purchase at least a_i items of the i-th product. Help Lena to calculate the minimum amount of money she needs to spend if she optimally chooses the order of purchasing. Note that if she wants, she can buy more items of some product than needed.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of products.
Each of next n lines contains a product description. Each description consists of two integers a_i and b_i (1 ≤ a_i ≤ 10^{14}, 1 ≤ b_i ≤ 10^{14}) — the required number of the i-th product and how many products you need to buy to get the discount on the i-th product.
The sum of all a_i does not exceed 10^{14}.
Output
Output the minimum sum that Lena needs to make all purchases.
Examples
Input
3
3 4
1 3
1 5
Output
8
Input
5
2 7
2 8
1 2
2 4
1 8
Output
12
Note
In the first example, Lena can purchase the products in the following way:
1. one item of product 3 for 2 rubles,
2. one item of product 1 for 2 rubles,
3. one item of product 1 for 2 rubles,
4. one item of product 2 for 1 ruble (she can use the discount because 3 items are already purchased),
5. one item of product 1 for 1 ruble (she can use the discount because 4 items are already purchased).
In total, she spends 8 rubles. It can be proved that it is impossible to spend less.
In the second example Lena can purchase the products in the following way:
1. one item of product 1 for 2 rubles,
2. two items of product 2 for 2 rubles for each,
3. one item of product 5 for 2 rubles,
4. one item of product 3 for 1 ruble,
5. two items of product 4 for 1 ruble for each,
6. one item of product 1 for 1 ruble.
In total, she spends 12 rubles.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
arr = []
for _ in range(n):
arr.append(list(map(int, input().split())))
arr.sort(key=lambda x:x[1])
# print(arr)
lo, hi = 0, n-1
ans, counter = 0, 0
while lo<=hi:
# print(lo, hi, counter)
to_buy, req = arr[lo]
if counter>=req or to_buy==0:
counter += to_buy
ans += to_buy
lo += 1
else:
a, b = arr[hi]
temp = min(a, req-counter)
counter += temp
ans += temp*2
arr[hi][0] -= temp
if arr[hi][0]==0:
hi -= 1
print(ans)
| python | code_algorithm | [
{
"input": "5\n2 7\n2 8\n1 2\n2 4\n1 8\n",
"output": "12\n"
},
{
"input": "3\n3 4\n1 3\n1 5\n",
"output": "8\n"
},
{
"input": "8\n1 8\n1 6\n1 5\n1 3\n1 3\n1 8\n1 7\n1 3\n",
"output": "11\n"
},
{
"input": "4\n4 1\n2 2\n1 6\n1 2\n",
"output": "9\n"
},
{
"input": "7\n2 11\n3 12\n2 1\n2 6\n1 6\n2 2\n3 14\n",
"output": "19\n"
},
{
"input": "8\n1 7\n3 16\n1 15\n2 1\n1 15\n4 11\n1 4\n2 15\n",
"output": "22\n"
},
{
"input": "4\n2 1\n3 2\n4 3\n5 100\n",
"output": "19\n"
},
{
"input": "15\n1 7\n1 14\n1 6\n1 13\n1 9\n1 10\n1 5\n1 14\n1 14\n1 11\n1 5\n1 4\n1 10\n1 8\n1 9\n",
"output": "19\n"
},
{
"input": "8\n1 63658803333197\n1 26806908300107\n1 37622010993115\n1 8932487734606\n1 55358687683237\n1 44940811911137\n1 29009786659098\n1 95047244855088\n",
"output": "16\n"
},
{
"input": "5\n3 10\n2 12\n1 11\n3 10\n1 8\n",
"output": "19\n"
},
{
"input": "15\n1 18646259228611\n1 76062756486449\n1 5817259716888\n1 22110867828535\n1 56957498169888\n1 40799537235509\n1 56529154503793\n1 56148198559428\n1 77940886559829\n1 74079407528201\n1 6574734766207\n1 79264199999788\n1 19171266033881\n1 38437872037474\n1 34320923862986\n",
"output": "30\n"
},
{
"input": "10\n471 505\n38 492\n1352 571\n46 759\n1081 2140\n768 1380\n2726 1156\n321 1743\n1775 1931\n2962 832\n",
"output": "12032\n"
},
{
"input": "2\n7 7\n1 4\n",
"output": "14\n"
},
{
"input": "1\n8 2\n",
"output": "10\n"
}
] | code_contests | python | 0 | 210c60a540e404aa67dc364e05856620 |
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb.
It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.
Your task is to count what number of teams from the given list shared the k-th place.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces.
Output
In the only line print the sought number of teams that got the k-th place in the final results' table.
Examples
Input
7 2
4 10
4 10
4 10
3 20
2 1
2 1
1 10
Output
3
Input
5 4
3 1
3 1
5 3
3 1
3 1
Output
4
Note
The final results' table for the first sample is:
* 1-3 places — 4 solved problems, the penalty time equals 10
* 4 place — 3 solved problems, the penalty time equals 20
* 5-6 places — 2 solved problems, the penalty time equals 1
* 7 place — 1 solved problem, the penalty time equals 10
The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.
The final table for the second sample is:
* 1 place — 5 solved problems, the penalty time equals 3
* 2-5 places — 3 solved problems, the penalty time equals 1
The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, k = map(int, input().split())
table =[]
table_dic = dict()
for i in range(n):
p, t = map(int, input().split())
table_dic[i + 1] = [p,t]
table.append([p, 50 - t])
ranking = sorted(table, key=lambda table: (table[0], table[1]), reverse=True)
for i in range(n):
ranking[i][1] = 50 - ranking[i][1]
counter = 0
for i in range(n):
if ranking[k - 1] == table_dic[i + 1]:
counter += 1
print(counter)
| python | code_algorithm | [
{
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n",
"output": "4\n"
},
{
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"output": "3\n"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n",
"output": "50\n"
},
{
"input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5\n",
"output": "1\n"
},
{
"input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"output": "20\n"
},
{
"input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"output": "50\n"
},
{
"input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8\n",
"output": "1\n"
},
{
"input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5\n",
"output": "2\n"
},
{
"input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2\n",
"output": "6\n"
},
{
"input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3\n",
"output": "1\n"
},
{
"input": "2 1\n50 50\n50 49\n",
"output": "1\n"
},
{
"input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2\n",
"output": "13\n"
},
{
"input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4\n",
"output": "4\n"
},
{
"input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14\n",
"output": "1\n"
},
{
"input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5\n",
"output": "1\n"
},
{
"input": "2 2\n1 2\n1 2\n",
"output": "2\n"
},
{
"input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3\n",
"output": "3\n"
},
{
"input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2\n",
"output": "1\n"
},
{
"input": "2 2\n50 50\n50 50\n",
"output": "2\n"
},
{
"input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4\n",
"output": "1\n"
},
{
"input": "2 1\n50 50\n50 50\n",
"output": "2\n"
},
{
"input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30\n",
"output": "2\n"
},
{
"input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10\n",
"output": "1\n"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49\n",
"output": "49\n"
},
{
"input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1\n",
"output": "5\n"
},
{
"input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6\n",
"output": "1\n"
},
{
"input": "1 1\n28 28\n",
"output": "1\n"
},
{
"input": "4 3\n1 1\n1 2\n2 1\n2 2\n",
"output": "1\n"
},
{
"input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2\n",
"output": "1\n"
},
{
"input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1\n",
"output": "13\n"
},
{
"input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1\n",
"output": "2\n"
},
{
"input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2\n",
"output": "2\n"
},
{
"input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1\n",
"output": "3\n"
},
{
"input": "4 1\n1 1\n1 1\n1 2\n1 3\n",
"output": "2\n"
},
{
"input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"output": "30\n"
},
{
"input": "4 2\n1 2\n1 3\n1 5\n1 2\n",
"output": "2\n"
},
{
"input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50\n",
"output": "1\n"
},
{
"input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3\n",
"output": "1\n"
},
{
"input": "3 2\n3 3\n3 3\n3 3\n",
"output": "3\n"
},
{
"input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2\n",
"output": "5\n"
},
{
"input": "2 2\n50 50\n50 49\n",
"output": "1\n"
},
{
"input": "3 1\n1 1\n1 2\n1 3\n",
"output": "1\n"
},
{
"input": "3 1\n2 1\n1 1\n1 2\n",
"output": "1\n"
},
{
"input": "4 3\n10 3\n6 10\n5 2\n5 2\n",
"output": "2\n"
}
] | code_contests | python | 0.2 | eba9115079535d72033b24fdaf44e820 |
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge.
John has been painting for long, but he has not been a success. Help him find such graph. Note that the number of vertices there shouldn't exceed 100, or else John will have problems painting it.
Input
A single line contains an integer k (1 ≤ k ≤ 105) — the number of cycles of length 3 in the required graph.
Output
In the first line print integer n (3 ≤ n ≤ 100) — the number of vertices in the found graph. In each of next n lines print n characters "0" and "1": the i-th character of the j-th line should equal "0", if vertices i and j do not have an edge between them, otherwise it should equal "1". Note that as the required graph is undirected, the i-th character of the j-th line must equal the j-th character of the i-th line. The graph shouldn't contain self-loops, so the i-th character of the i-th line must equal "0" for all i.
Examples
Input
1
Output
3
011
101
110
Input
10
Output
5
01111
10111
11011
11101
11110
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, k = 0, int(input())
p = [['0'] * 100 for i in range(100)]
while k:
for i in range(n):
if i > k: break
p[n][i] = p[i][n] = '1'
k -= i
n += 1
print(n)
for i in range(n): print(''.join(p[i][:n])) | python | code_algorithm | [
{
"input": "10\n",
"output": "5\n01111\n10111\n11011\n11101\n11110\n"
},
{
"input": "1\n",
"output": "3\n011\n101\n110\n"
},
{
"input": "99016\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111111000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99022\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111111100000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "5\n",
"output": "5\n01111\n10111\n11010\n11100\n11000\n"
},
{
"input": "99007\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "7\n",
"output": "5\n01111\n10111\n11011\n11100\n11100\n"
},
{
"input": "99007\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "98685\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n1111111111111000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "100000\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111111111111111111111111111111111000000000000000000000000000000000000000\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99020\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99994\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111111111111111111111111111111000000000000000000000000000000000000000\n1111111111000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "97560\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111111111111111111111111100000000000000000000\n111111111110000000000000000000000000000000000000000000000000000000000000000000000000000\n111110000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "4\n",
"output": "4\n0111\n1011\n1101\n1110\n"
},
{
"input": "99021\n",
"output": "90\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000\n111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "97560\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111111111111111111111111100000000000000000000\n111111111110000000000000000000000000000000000000000000000000000000000000000000000000000\n111110000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99994\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111111111111111111111111111111000000000000000000000000000000000000000\n1111111111000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99011\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111110000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99004\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "9\n",
"output": "7\n0111111\n1011111\n1101100\n1110000\n1110000\n1100000\n1100000\n"
},
{
"input": "99999\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111111111111111111111111111111100000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99009\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99004\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99003\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99999\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111111111111111111111111111111100000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99012\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99013\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99016\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111111000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99006\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99014\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99014\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99010\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "19\n",
"output": "7\n0111111\n1011111\n1101111\n1110110\n1111000\n1111000\n1110000\n"
},
{
"input": "99005\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99008\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "6\n",
"output": "6\n011111\n101111\n110100\n111000\n110000\n110000\n"
},
{
"input": "99009\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99019\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111110000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99990\n",
"output": "90\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000\n111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000\n111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "2\n",
"output": "4\n0111\n1011\n1100\n1100\n"
},
{
"input": "99023\n",
"output": "86\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111111111111111111111000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99025\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99018\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99990\n",
"output": "90\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000\n111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000\n111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "12\n",
"output": "7\n0111111\n1011111\n1101100\n1110100\n1111000\n1100000\n1100000\n"
},
{
"input": "99000\n",
"output": "90\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000\n111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "29257\n",
"output": "60\n011111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111110\n111011111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111100\n111110111111111111111111111111111111111111111111111111111100\n111111011111111111111111111111111111111111111111111111111100\n111111101111111111111111111111111111111111111111111111111100\n111111110111111111111111111111111111111111111111111111111100\n111111111011111111111111111111111111111111111111111111111100\n111111111101111111111111111111111111111111111111111111111000\n111111111110111111111111111111111111111111111111111111111000\n111111111111011111111111111111111111111111111111111111111000\n111111111111101111111111111111111111111111111111111111111000\n111111111111110111111111111111111111111111111111111111111000\n111111111111111011111111111111111111111111111111111111111000\n111111111111111101111111111111111111111111111111111111111000\n111111111111111110111111111111111111111111111111111111111000\n111111111111111111011111111111111111111111111111111111111000\n111111111111111111101111111111111111111111111111111111111000\n111111111111111111110111111111111111111111111111111111111000\n111111111111111111111011111111111111111111111111111111111000\n111111111111111111111101111111111111111111111111111111111000\n111111111111111111111110111111111111111111111111111111111000\n111111111111111111111111011111111111111111111111111111111000\n111111111111111111111111101111111111111111111111111111111000\n111111111111111111111111110111111111111111111111111111111000\n111111111111111111111111111011111111111111111111111111111000\n111111111111111111111111111101111111111111111111111111111000\n111111111111111111111111111110111111111111111111111111111000\n111111111111111111111111111111011111111111111111111111111000\n111111111111111111111111111111101111111111111111111111111000\n111111111111111111111111111111110111111111111111111111111000\n111111111111111111111111111111111011111111111111111111111000\n111111111111111111111111111111111101111111111111111111111000\n111111111111111111111111111111111110111111111111111111111000\n111111111111111111111111111111111111011111111111111111111000\n111111111111111111111111111111111111101111111111111111111000\n111111111111111111111111111111111111110111111111111111111000\n111111111111111111111111111111111111111011111111111111111000\n111111111111111111111111111111111111111101111111111111111000\n111111111111111111111111111111111111111110111111111111111000\n111111111111111111111111111111111111111111011111111111111000\n111111111111111111111111111111111111111111101111111111111000\n111111111111111111111111111111111111111111110111111111111000\n111111111111111111111111111111111111111111111011111111111000\n111111111111111111111111111111111111111111111101111111111000\n111111111111111111111111111111111111111111111110111111111000\n111111111111111111111111111111111111111111111111011111111000\n111111111111111111111111111111111111111111111111101111111000\n111111111111111111111111111111111111111111111111110111111000\n111111111111111111111111111111111111111111111111111011111000\n111111111111111111111111111111111111111111111111111101111000\n111111111111111111111111111111111111111111111111111110111000\n111111111111111111111111111111111111111111111111111111011000\n111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111100000\n111111111100000000000000000000000000000000000000000000000000\n111100000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "98770\n",
"output": "85\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n"
},
{
"input": "99002\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99011\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111110000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99003\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99019\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111110000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99006\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "8\n",
"output": "6\n011111\n101111\n110110\n111000\n111000\n110000\n"
},
{
"input": "99025\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "98685\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n1111111111111000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99010\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99024\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111110000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99013\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99017\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111110000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99017\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111110000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99002\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99024\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111110000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99005\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99021\n",
"output": "90\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000\n111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99020\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99008\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "3\n",
"output": "5\n01111\n10111\n11000\n11000\n11000\n"
},
{
"input": "99012\n",
"output": "88\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111110\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111100\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101000\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n1111111111111111111111000000000000000000000000000000000000000000000000000000000000000000\n1111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99015\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99000\n",
"output": "90\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110000\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100000\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000\n111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99001\n",
"output": "86\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99022\n",
"output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n111111101111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111110111111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111011111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111101111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111110111111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111011111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111101111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111110111111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111011111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111101111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111110111111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111011111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111101111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111110111111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111011111111111111111111111111111111111111111111111111111111111111110\n111111111111111111111101111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111110111111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111011111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111101111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111110111111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111011111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111101111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111110111111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111011111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111101111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111110111111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111011111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111101111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111110111111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111011111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111101111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111110111111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111011111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111101111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111110111111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111011111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111101111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111110111111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111011111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111101111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111110111111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111011111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111101111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111110111111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111011111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111101111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111110111111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111011111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111101111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111110111111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111101111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111110111111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111011111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111101111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111110111111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111011111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111101111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111110111111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111011111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111101111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111110111111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111011111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111101111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111110111111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111011111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111101111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111110111111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111011111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111101111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111110111111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111011111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111101111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111110111100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111011100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111101100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111110100\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n111111111111111111111100000000000000000000000000000000000000000000000000000000000000000\n111111100000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99001\n",
"output": "86\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99018\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11111100000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99023\n",
"output": "86\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111111111111111111111000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "99015\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111110000000000000000000000000000000000000000000000000000000000000000000\n11111000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "98770\n",
"output": "85\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1101111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1110111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111011111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111101111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111110111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111011111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111101111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111110111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111011111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111101111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111110111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111011111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111101111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111110111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111011111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111101111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111110111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111011111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111101111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111110111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111011111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111101111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111110111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111011111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111101111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111110111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111011111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111101111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111110111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111011111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111101111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111011111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111101111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111110111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111011111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111101111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111110111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111011111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111101111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111110111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111011111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111101111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111110111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111011111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111101111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111110111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111011111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111101111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111110111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111011111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111101111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111110111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111011111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111101111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111011111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111101111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111110111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111011111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111101111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111110111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111011111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111101111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111110111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111011111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111101111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111110111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111011111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111101111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111110111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111011111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111101111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111110111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111011111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111101111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111011111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111101111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111110111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111011\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111101\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111110\n"
},
{
"input": "100000\n",
"output": "89\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11011111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n11101111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11110111111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111011111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111101111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111110111111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111011111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111101111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111110111111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111011111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111101111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111110111111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111011111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111101111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111110111111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111011111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111101111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111110111111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111011111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111101111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111110111111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111011111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111101111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111110111111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111011111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111101111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111110111111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111011111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111101111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111110111111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111011111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111101111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111110111111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111011111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111101111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111110111111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111011111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111101111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111110111111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111011111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111101111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111110111111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111011111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111101111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111110111111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111111011111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111111101111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111111110111111111111111111111111111111111111000\n11111111111111111111111111111111111111111111111111011111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111101111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111110111111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111011111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111101111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111110111111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111011111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111101111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111110111111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111011111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111101111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111110111111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111011111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111101111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111110111111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111011111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111101111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111110111111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111011111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111101111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111110111111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111011111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111101111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111110111111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111011111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111101111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111110111111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111011111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111101111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111110111110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111011110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111101110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111110110000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111010000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n11111111111111111111111111111111111111111111111111000000000000000000000000000000000000000\n11100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "29257\n",
"output": "60\n011111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111111111111111111111111111111\n110111111111111111111111111111111111111111111111111111111110\n111011111111111111111111111111111111111111111111111111111110\n111101111111111111111111111111111111111111111111111111111100\n111110111111111111111111111111111111111111111111111111111100\n111111011111111111111111111111111111111111111111111111111100\n111111101111111111111111111111111111111111111111111111111100\n111111110111111111111111111111111111111111111111111111111100\n111111111011111111111111111111111111111111111111111111111100\n111111111101111111111111111111111111111111111111111111111000\n111111111110111111111111111111111111111111111111111111111000\n111111111111011111111111111111111111111111111111111111111000\n111111111111101111111111111111111111111111111111111111111000\n111111111111110111111111111111111111111111111111111111111000\n111111111111111011111111111111111111111111111111111111111000\n111111111111111101111111111111111111111111111111111111111000\n111111111111111110111111111111111111111111111111111111111000\n111111111111111111011111111111111111111111111111111111111000\n111111111111111111101111111111111111111111111111111111111000\n111111111111111111110111111111111111111111111111111111111000\n111111111111111111111011111111111111111111111111111111111000\n111111111111111111111101111111111111111111111111111111111000\n111111111111111111111110111111111111111111111111111111111000\n111111111111111111111111011111111111111111111111111111111000\n111111111111111111111111101111111111111111111111111111111000\n111111111111111111111111110111111111111111111111111111111000\n111111111111111111111111111011111111111111111111111111111000\n111111111111111111111111111101111111111111111111111111111000\n111111111111111111111111111110111111111111111111111111111000\n111111111111111111111111111111011111111111111111111111111000\n111111111111111111111111111111101111111111111111111111111000\n111111111111111111111111111111110111111111111111111111111000\n111111111111111111111111111111111011111111111111111111111000\n111111111111111111111111111111111101111111111111111111111000\n111111111111111111111111111111111110111111111111111111111000\n111111111111111111111111111111111111011111111111111111111000\n111111111111111111111111111111111111101111111111111111111000\n111111111111111111111111111111111111110111111111111111111000\n111111111111111111111111111111111111111011111111111111111000\n111111111111111111111111111111111111111101111111111111111000\n111111111111111111111111111111111111111110111111111111111000\n111111111111111111111111111111111111111111011111111111111000\n111111111111111111111111111111111111111111101111111111111000\n111111111111111111111111111111111111111111110111111111111000\n111111111111111111111111111111111111111111111011111111111000\n111111111111111111111111111111111111111111111101111111111000\n111111111111111111111111111111111111111111111110111111111000\n111111111111111111111111111111111111111111111111011111111000\n111111111111111111111111111111111111111111111111101111111000\n111111111111111111111111111111111111111111111111110111111000\n111111111111111111111111111111111111111111111111111011111000\n111111111111111111111111111111111111111111111111111101111000\n111111111111111111111111111111111111111111111111111110111000\n111111111111111111111111111111111111111111111111111111011000\n111111111111111111111111111111111111111111111111111111100000\n111111111111111111111111111111111111111111111111111111100000\n111111111100000000000000000000000000000000000000000000000000\n111100000000000000000000000000000000000000000000000000000000\n110000000000000000000000000000000000000000000000000000000000\n"
}
] | code_contests | python | 0 | 7196c76cdd45398e44079caa2dc398c1 |
The Bitlandians are quite weird people. They have very peculiar customs.
As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.
The kids are excited because just as is customary, they're going to be paid for the job!
Overall uncle J. has got n eggs. G. named his price for painting each egg. Similarly, A. named his price for painting each egg. It turns out that for each egg the sum of the money both A. and G. want for the painting equals 1000.
Uncle J. wants to distribute the eggs between the children so as to give each egg to exactly one child. Also, Uncle J. wants the total money paid to A. to be different from the total money paid to G. by no more than 500.
Help Uncle J. Find the required distribution of eggs or otherwise say that distributing the eggs in the required manner is impossible.
Input
The first line contains integer n (1 ≤ n ≤ 106) — the number of eggs.
Next n lines contain two integers ai and gi each (0 ≤ ai, gi ≤ 1000; ai + gi = 1000): ai is the price said by A. for the i-th egg and gi is the price said by G. for the i-th egg.
Output
If it is impossible to assign the painting, print "-1" (without quotes).
Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote the money Uncle J. must pay A. for the painting as Sa, and the money Uncle J. must pay G. for the painting as Sg, then this inequality must hold: |Sa - Sg| ≤ 500.
If there are several solutions, you are allowed to print any of them.
Examples
Input
2
1 999
999 1
Output
AG
Input
3
400 600
400 600
400 600
Output
AGA
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import sys
input = lambda: sys.stdin.readline()
n = int(input())
S = 0
ans = ''
for i in range(n):
a, g = [int(x) for x in input().split(' ')]
if abs(S + a) <= 500:
S += a
ans += 'A'
else:
S -= g
ans += 'G'
print(ans) | python | code_algorithm | [
{
"input": "2\n1 999\n999 1\n",
"output": "AG\n"
},
{
"input": "3\n400 600\n400 600\n400 600\n",
"output": "AGA\n"
},
{
"input": "1\n500 500\n",
"output": "A\n"
},
{
"input": "2\n500 500\n500 500\n",
"output": "AG\n"
},
{
"input": "1\n1 999\n",
"output": "A\n"
},
{
"input": "2\n499 501\n501 499\n",
"output": "AG\n"
},
{
"input": "10\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n",
"output": "AAAAAAAAAA\n"
},
{
"input": "1\n0 1000\n",
"output": "A\n"
},
{
"input": "1\n1000 0\n",
"output": "G\n"
},
{
"input": "3\n500 500\n1 999\n400 600\n",
"output": "AGA\n"
}
] | code_contests | python | 0.2 | b30c9807772a1bff49a00302a05df104 |
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I know for sure that either x or y did it!'
The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at least p of n coders agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?
Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting.
Input
The first line contains integers n and p (3 ≤ n ≤ 3·105; 0 ≤ p ≤ n) — the number of coders in the F company and the minimum number of agreed people.
Each of the next n lines contains two integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of coders named by the i-th coder. It is guaranteed that xi ≠ i, yi ≠ i, xi ≠ yi.
Output
Print a single integer — the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets (1, 2) and (2, 1) are considered identical.
Examples
Input
4 2
2 3
1 4
1 4
2 1
Output
6
Input
8 6
5 6
5 7
5 8
6 2
2 1
7 3
1 3
1 4
Output
1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from collections import defaultdict
from bisect import bisect_left as lower
import sys
input = sys.stdin.readline
def put():
return map(int, input().split())
try:
n,m = put()
cnt, mp, ans = [0]*n, defaultdict(), [0]*n
for _ in range(n):
x,y = put()
x,y = x-1,y-1
key = (min(x,y), max(x,y))
if key in mp:
mp[key]+=1
else:
mp[key]=1
cnt[x]+=1
cnt[y]+=1
except:
print('lol')
for (x,y),val in mp.items():
if cnt[x]+cnt[y]>= m and cnt[x]+cnt[y]-val<m:
ans[x]-=1
ans[y]-=1
scnt = cnt.copy()
scnt.sort()
for i in range(n):
ans[i]+= n-lower(scnt, m-cnt[i])
if 2*cnt[i]>=m:
ans[i]-=1
print(sum(ans)//2)
| python | code_algorithm | [
{
"input": "8 6\n5 6\n5 7\n5 8\n6 2\n2 1\n7 3\n1 3\n1 4\n",
"output": "1\n"
},
{
"input": "4 2\n2 3\n1 4\n1 4\n2 1\n",
"output": "6\n"
},
{
"input": "10 3\n6 3\n6 10\n2 5\n5 7\n6 2\n9 2\n8 1\n10 5\n5 10\n7 6\n",
"output": "34\n"
},
{
"input": "4 2\n3 4\n4 3\n4 2\n3 1\n",
"output": "6\n"
},
{
"input": "10 10\n5 6\n1 4\n1 4\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 4\n",
"output": "2\n"
},
{
"input": "5 5\n3 2\n3 4\n2 5\n3 2\n4 3\n",
"output": "3\n"
},
{
"input": "6 6\n5 6\n5 6\n5 6\n1 2\n1 3\n3 4\n",
"output": "0\n"
},
{
"input": "5 3\n4 5\n4 5\n4 5\n3 2\n2 3\n",
"output": "7\n"
},
{
"input": "8 8\n6 5\n1 6\n1 6\n1 6\n1 6\n1 2\n1 3\n6 4\n",
"output": "1\n"
},
{
"input": "5 3\n5 2\n4 3\n4 5\n3 1\n4 2\n",
"output": "9\n"
},
{
"input": "10 1\n4 9\n8 9\n7 6\n1 5\n3 6\n4 3\n4 6\n10 1\n1 8\n7 9\n",
"output": "45\n"
},
{
"input": "4 4\n3 4\n4 3\n1 2\n2 1\n",
"output": "4\n"
},
{
"input": "5 1\n4 2\n4 5\n5 1\n5 1\n4 2\n",
"output": "10\n"
},
{
"input": "10 4\n8 7\n1 5\n7 4\n7 8\n3 2\n10 8\n3 6\n9 7\n8 7\n4 1\n",
"output": "19\n"
},
{
"input": "4 1\n3 2\n4 1\n4 2\n1 2\n",
"output": "6\n"
},
{
"input": "10 2\n10 2\n9 3\n9 4\n7 2\n4 6\n10 1\n9 2\n3 10\n7 1\n5 1\n",
"output": "43\n"
},
{
"input": "8 5\n5 6\n5 7\n5 8\n6 2\n2 1\n7 3\n1 3\n1 4\n",
"output": "5\n"
},
{
"input": "5 5\n3 2\n3 4\n1 2\n1 2\n1 2\n",
"output": "3\n"
},
{
"input": "4 4\n3 4\n3 4\n1 2\n1 2\n",
"output": "4\n"
},
{
"input": "4 4\n2 3\n4 3\n2 1\n2 3\n",
"output": "3\n"
},
{
"input": "8 7\n7 8\n7 8\n1 6\n1 6\n1 2\n1 3\n6 4\n6 5\n",
"output": "0\n"
},
{
"input": "3 2\n2 3\n3 1\n2 1\n",
"output": "3\n"
},
{
"input": "5 2\n4 3\n1 3\n4 2\n1 2\n1 4\n",
"output": "10\n"
},
{
"input": "5 3\n3 4\n3 4\n1 2\n1 2\n1 2\n",
"output": "7\n"
},
{
"input": "5 3\n5 3\n5 1\n2 1\n5 3\n1 4\n",
"output": "9\n"
},
{
"input": "6 4\n2 3\n3 1\n1 2\n5 6\n6 4\n4 5\n",
"output": "9\n"
},
{
"input": "4 3\n3 2\n4 3\n2 4\n3 2\n",
"output": "5\n"
},
{
"input": "6 5\n5 6\n5 6\n5 6\n5 6\n1 2\n3 4\n",
"output": "8\n"
},
{
"input": "4 3\n3 4\n3 4\n1 2\n1 2\n",
"output": "4\n"
},
{
"input": "4 4\n2 3\n3 4\n2 4\n2 1\n",
"output": "2\n"
},
{
"input": "5 5\n4 5\n4 5\n4 5\n1 2\n1 2\n",
"output": "4\n"
}
] | code_contests | python | 0.2 | 55e363b3395d789a30dc27c47f026b5d |
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.
Input
The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
Output
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word t even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.
Examples
Input
automaton
tomat
Output
automaton
Input
array
arary
Output
array
Input
both
hot
Output
both
Input
need
tree
Output
need tree
Note
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | s = input()
t = input()
ind = 0
for x in t:
ind = s.find(x, ind) + 1
if ind <= 0:
break
if ind > 0 or len(t) == 0:
print('automaton')
else:
ss = list(s)
tt = list(t)
bb1 = True
if len(ss) >= len(tt):
for x in tt:
bb = False
for y in ss:
if y == x:
ss.remove(y)
bb = True
break
if not bb:
bb1 = False
break
if bb1:
if len(s) > len(t):
print('both')
else:
print('array')
else:
print('need tree')
else:
print('need tree')
| python | code_algorithm | [
{
"input": "need\ntree\n",
"output": "need tree\n"
},
{
"input": "automaton\ntomat\n",
"output": "automaton\n"
},
{
"input": "array\narary\n",
"output": "array\n"
},
{
"input": "both\nhot\n",
"output": "both\n"
},
{
"input": "hxsvvydmzhxrswvhkvrbjrfqkazbkjabnrdghposgyfeslzumaovfkallszzumztftgpcilwfrzpvhhbgdzdvnmseqywlzmhhoxh\ndbelhtzgkssyfrqgzuurdjhwvmdbhylhmvphjgxpzhxbb\n",
"output": "both\n"
},
{
"input": "smywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhuqqcttokbljfbppdinzqgdupkfevmke\nsmywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhufqcttokbljfbppdinzqgdupkqevmke\n",
"output": "array\n"
},
{
"input": "kjnohlseyntrslfssrshjxclzlsbkfzfwwwgyxsysvmfkxugdwjodfyxhdsveruoioutwmtcbaljomaorvzjsbmglqckmsyieeiu\netihhycsjgdysowuljmaoksoecxawsgsljofkrjftuweidrkwtymyswdlilsozsxevfbformnbsumlxzqzykjvsnrlxufvgbmshc\n",
"output": "array\n"
},
{
"input": "gzvvawianfysfuxhruarhverinqsbrfxvkcsermuzowahevgskmpvfdljtcztnbkzftfhvnarvkfkqjgrzbrcfthqmspvpqcva\nwnm\n",
"output": "automaton\n"
},
{
"input": "ddmgoarkuhknbtjggnomyxvvavobmylixwuxnnsdrrbibitoteaiydptnvtfblathihflefuggfnyayniragbtkommycpdyhft\ntejwybmyrhmalraptqwhghsckvnnaagtmzhnpwbhzzgfgritqwqqamgssllnicjqdkivrwaqyxngsqopwieljfxcdywjaal\n",
"output": "need tree\n"
},
{
"input": "itwtyhhsdjjffmmoqkkhxjouypznewstyorotxhozlytndehmaxogrohccnqcgkrjrdmnuaogiwmnmsbdaizqkxnkqxxiihbwepc\nsnixfywvcntitcefsgqxjcodwtumurcglfmnamnowzbjzmfzspbfuldraiepeeiyasmrsneekydsbvazoqszyjxkjiotushsddet\n",
"output": "need tree\n"
},
{
"input": "kobhhrqgwbgqkzcoacrhpkegyepzfds\nhlwcgbvvlegoyrcrjhsjywpdnccxtzgmeujxciuwjlnefllwldidlnjswmetkarxqjigokfvmpxpzfxarhkpdcia\n",
"output": "need tree\n"
},
{
"input": "ypyhyabmljukejpltkgunwuanhxblhiouyltdiczttndrhdprqtlpfanmzlyzbqanfwfyurxhepuzspdvehxnblhajczqcxlqebx\nlladxuucky\n",
"output": "both\n"
},
{
"input": "dvzohfzgzdjavqwhjcrdphpdqjwtqijabbrhformstqaonlhbglmxugkwviigqaohwvqfhdwwcvdkjrcgxblhvtashhcxssbvpo\nzgvqhpjhforlugkwfwrchvhp\n",
"output": "automaton\n"
},
{
"input": "iypjqiiqxhtinlmywpetgqqsdopxhghthjopgbodkwrdxzaaxmtaqcfuiarhrvasusanklzcqaytdyzndakcpljqupowompjjved\nhxeatriypptbhnokarhgqdrkqkypqzdttixphngmpqjodzjqlmcztyjfgoswjelwwdaqdjayavsdocuhqsluxaaopniviaumxip\n",
"output": "both\n"
},
{
"input": "abacaba\naaaa\n",
"output": "automaton\n"
},
{
"input": "lloloooolooollololloooloololooollooloollolllloolllllllloollollllolooloollloololollllooloooololooolol\nlooooollooolllololloollooooololollollloloollollolo\n",
"output": "both\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "automaton\n"
},
{
"input": "nppjzscfgcvdcnsjtiaudvutmgswqbewejlzibczzowgkdrjgxrpirfdaekvngcsonroheepdoeoeevaullbfwprcnhlxextbxpd\nifilrvacohnwcgzuleicucebrfxphosrgwnglxxkqrcorsxegjoppbb\n",
"output": "both\n"
},
{
"input": "wkfoyetcjivofxaktmauapzeuhcpzjloszzxwydgavebgniiuzrscytsokjkjfkpylvxtlqlquzduywbhqdzmtwprfdohmwgmysy\ny\n",
"output": "automaton\n"
},
{
"input": "z\nzz\n",
"output": "need tree\n"
},
{
"input": "baaa\nbb\n",
"output": "need tree\n"
},
{
"input": "ba\naa\n",
"output": "need tree\n"
},
{
"input": "lllolloloolllloolollololololollllooololoooloooolololloolloollllolloolloooooooololllolllolllloolllool\nlollollololololooooloooooooooolloolllololooollllol\n",
"output": "automaton\n"
},
{
"input": "ggzmtrhkpdswwqgcbtviahqrgzhyhzddtdekchrpjgngupitzyyuipwstgzewktcqpwezidwvvxgjixnflpjhfznokmpbyzczrzk\ngpgwhtzrcytstezmhettkppgmvxlxqnkjzibiqdtceczkbfhdziuajwjqzgwnhnkdzizprgzwud\n",
"output": "both\n"
},
{
"input": "kipjuscf\nkbwfqfwuvkyhmvnaznzsgdgdnpipikbicmlcwehjirmhgwpxwpgfztqjwfqfaapmsgskr\n",
"output": "need tree\n"
},
{
"input": "nbjigpsbammkuuqrxfnmhtimwpflrflehffykbylmnxgadldchdbqklqbremcmzlpxieozgpfgrhegmdcxxfyehzzelcwgkierrj\nbjbakuqrnhimwhffykylmngadhbqkqbrcziefredxxezcgkerj\n",
"output": "automaton\n"
},
{
"input": "abc\naa\n",
"output": "need tree\n"
},
{
"input": "y\nu\n",
"output": "need tree\n"
},
{
"input": "yyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxyxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx\nyyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxxxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx\n",
"output": "need tree\n"
},
{
"input": "vwesbxsifsjqapwridrenumrukgemlldpbtdhxivsrmzbgprtkqgaryniudkjgpjndluwxuohwwysmyuxyrulwsodgunzirudgtx\nugeabdszfshqsksddireguvsukieqlluhngdpxjvwwnzdrtrtrdjiuxgadtgjpxrmlynspyyryngxuiibrmurwpmoxwwuklbwumo\n",
"output": "array\n"
},
{
"input": "npeidcoiulxdxzjozsonkdwnoazsbntfclnpubgweaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf\nnpeidcoiulxdxzjozsonkdwnoazsbntfclnpubgeaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf\n",
"output": "automaton\n"
},
{
"input": "gahcqpgmypeahjcwkzahnhmsmxosnikucqwyzklbfwtujjlzvwklqzxakcrcqalhsvsgvknpxsoqkjnyjkypfsiogbcaxjyugeet\ngahcqpgmypeahjwwkzahnhmsmxopnikucacyzklbfwtujjlzvwkoqzxakcrcqqlhsvsgvknpxslgkjnyjkysfoisqbcaxjyuteeg\n",
"output": "array\n"
},
{
"input": "abracadabra\nlol\n",
"output": "need tree\n"
},
{
"input": "boosss\nosos\n",
"output": "both\n"
},
{
"input": "ezbpsylkfztypqrefinexshtgglmkoinrktkloitqhfkivoabrfrivvqrcxkjckzvcozpchhiodrbbxuhnwcjigftnrjfiqyxakh\niacxghqffzdbsiqunhxbiooqvfohzticjpvrzykcrlrxklgknyrkrhjxcetmfocierekatfvkbslkkrbhftwngoijpipvqyznthi\n",
"output": "array\n"
},
{
"input": "abbb\naaab\n",
"output": "need tree\n"
}
] | code_contests | python | 0.4 | a1e270e3dcfc0ff4fd338e2ce6e959f9 |
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives ai hits.
Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.
Input
The first line contains three integers n,x,y (1 ≤ n ≤ 105, 1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.
Next n lines contain integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster.
Output
Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.
Examples
Input
4 3 2
1
2
3
4
Output
Vanya
Vova
Vanya
Both
Input
2 1 1
1
2
Output
Both
Both
Note
In the first sample Vanya makes the first hit at time 1 / 3, Vova makes the second hit at time 1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time 1.
In the second sample Vanya and Vova make the first and second hit simultaneously at time 1.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, x, y = map(int, input().split())
for _ in range(n):
a = int(input())
c1, c2 = ((a + 1) * x // (x + y)) / x, ((a + 1) * y // (x + y)) / y
if c1 == c2:
print('Both')
elif c1 > c2:
print('Vanya')
else:
print('Vova')
| python | code_algorithm | [
{
"input": "2 1 1\n1\n2\n",
"output": "Both\nBoth\n"
},
{
"input": "4 3 2\n1\n2\n3\n4\n",
"output": "Vanya\nVova\nVanya\nBoth\n"
},
{
"input": "10 13 27\n3\n21\n23\n17\n15\n23\n16\n7\n24\n20\n",
"output": "Vanya\nVanya\nVova\nVova\nVanya\nVova\nVova\nVova\nVanya\nVova\n"
},
{
"input": "5 5 6\n999999999\n999999998\n999999997\n999999996\n999999995\n",
"output": "Vova\nVanya\nVova\nVanya\nVova\n"
},
{
"input": "10 10 1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
"output": "Vanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nBoth\n"
},
{
"input": "11 22 33\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n",
"output": "Both\nVova\nVanya\nVova\nBoth\nBoth\nVova\nVanya\nVova\nBoth\nBoth\n"
},
{
"input": "5 999999 1000000\n1999997\n1999998\n1999999\n2000000\n2000001\n",
"output": "Vova\nBoth\nBoth\nVova\nVanya\n"
},
{
"input": "1 999999 1000000\n1000000000\n",
"output": "Vanya\n"
},
{
"input": "1 1 1\n1\n",
"output": "Both\n"
},
{
"input": "10 1 10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
"output": "Vova\nVova\nVova\nVova\nVova\nVova\nVova\nVova\nVova\nBoth\n"
},
{
"input": "20 5 15\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n",
"output": "Both\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\n"
},
{
"input": "7 5 20\n26\n27\n28\n29\n30\n31\n32\n",
"output": "Vova\nVova\nVova\nBoth\nBoth\nVova\nVova\n"
},
{
"input": "5 999998 1000000\n999997\n999998\n999999\n1000000\n1000001\n",
"output": "Vova\nBoth\nBoth\nVova\nVanya\n"
}
] | code_contests | python | 0 | 8525bd0f5a192a4cbd463fb201a51a0f |
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.
While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn.
Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).
Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
Input
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order.
The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of integers written on cubes after Stepan rearranged their order.
It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
Output
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
Examples
Input
5 2 4
3 4 2 3 1
3 2 3 4 1
Output
TRUTH
Input
3 1 2
1 2 3
3 1 2
Output
LIE
Input
4 2 4
1 1 1 1
1 1 1 1
Output
TRUTH
Note
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).
In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.
In the third example for any values l and r there is a situation when Stepan said the truth.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n,l,r = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if(a[:l - 1] == b[:l - 1] and a[r:] == b[r:]):
print("TRUTH")
else:
print("LIE") | python | code_algorithm | [
{
"input": "4 2 4\n1 1 1 1\n1 1 1 1\n",
"output": "TRUTH\n"
},
{
"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1\n",
"output": "TRUTH\n"
},
{
"input": "3 1 2\n1 2 3\n3 1 2\n",
"output": "LIE\n"
},
{
"input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2\n",
"output": "TRUTH\n"
},
{
"input": "7 2 4\n1 2 3 4 5 7 6\n1 2 3 4 5 6 7\n",
"output": "LIE\n"
},
{
"input": "5 1 2\n1 2 3 4 5\n1 2 3 5 4\n",
"output": "LIE\n"
},
{
"input": "10 1 10\n6 7 6 1 10 10 9 5 3 9\n7 10 9 6 1 5 9 3 10 6\n",
"output": "TRUTH\n"
},
{
"input": "8 3 6\n5 3 1 1 1 1 3 5\n3 3 1 1 1 1 5 5\n",
"output": "LIE\n"
},
{
"input": "4 2 2\n2 1 2 2\n1 2 2 2\n",
"output": "LIE\n"
},
{
"input": "4 3 4\n1 2 3 4\n2 1 3 4\n",
"output": "LIE\n"
},
{
"input": "7 1 4\n2 5 5 5 4 3 4\n2 5 5 5 4 3 4\n",
"output": "TRUTH\n"
},
{
"input": "1 1 1\n1\n1\n",
"output": "TRUTH\n"
}
] | code_contests | python | 1 | 482cbe03fa19ed7dd845e997349ac876 |
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | def main():
s = input()
print(solver(s))
def solver(s):
L1 = [int(x) for x in s[0:3]]
L2 = [int(x) for x in s[3:6]]
diff = sum(L2) - sum(L1)
if diff == 0:
return 0
elif diff < 0:
L1, L2 = L2, L1
diff = -diff
changes = [9 - L1[i] for i in range(3)] + [L2[i] - 0 for i in range(3)]
changes.sort(reverse = True)
#print(changes)
for i in range(6):
diff -= changes[i]
if diff <= 0:
return i + 1
main()
#solver('321456')
#print(solver('000000'))
#print(solver('654321'))
#print(solver('111000'))
| python | code_algorithm | [
{
"input": "111000\n",
"output": "1\n"
},
{
"input": "000000\n",
"output": "0\n"
},
{
"input": "123456\n",
"output": "2\n"
},
{
"input": "191578\n",
"output": "2\n"
},
{
"input": "877542\n",
"output": "2\n"
},
{
"input": "977330\n",
"output": "2\n"
},
{
"input": "000990\n",
"output": "2\n"
},
{
"input": "100172\n",
"output": "1\n"
},
{
"input": "202597\n",
"output": "2\n"
},
{
"input": "944234\n",
"output": "1\n"
},
{
"input": "000009\n",
"output": "1\n"
},
{
"input": "033788\n",
"output": "2\n"
},
{
"input": "000018\n",
"output": "1\n"
},
{
"input": "123996\n",
"output": "2\n"
},
{
"input": "444776\n",
"output": "2\n"
},
{
"input": "123689\n",
"output": "2\n"
},
{
"input": "317596\n",
"output": "1\n"
},
{
"input": "011299\n",
"output": "2\n"
},
{
"input": "858022\n",
"output": "2\n"
},
{
"input": "899888\n",
"output": "1\n"
},
{
"input": "999801\n",
"output": "2\n"
},
{
"input": "889444\n",
"output": "2\n"
},
{
"input": "101488\n",
"output": "3\n"
},
{
"input": "024768\n",
"output": "2\n"
},
{
"input": "202877\n",
"output": "3\n"
},
{
"input": "779114\n",
"output": "2\n"
},
{
"input": "811010\n",
"output": "1\n"
},
{
"input": "990999\n",
"output": "1\n"
},
{
"input": "101389\n",
"output": "2\n"
},
{
"input": "698213\n",
"output": "2\n"
},
{
"input": "000333\n",
"output": "1\n"
},
{
"input": "012561\n",
"output": "1\n"
},
{
"input": "333945\n",
"output": "1\n"
},
{
"input": "034988\n",
"output": "2\n"
},
{
"input": "023778\n",
"output": "2\n"
},
{
"input": "123985\n",
"output": "2\n"
},
{
"input": "809116\n",
"output": "1\n"
},
{
"input": "120111\n",
"output": "0\n"
},
{
"input": "023977\n",
"output": "2\n"
},
{
"input": "199880\n",
"output": "1\n"
},
{
"input": "744438\n",
"output": "0\n"
},
{
"input": "001019\n",
"output": "1\n"
},
{
"input": "999990\n",
"output": "1\n"
},
{
"input": "111993\n",
"output": "2\n"
},
{
"input": "999999\n",
"output": "0\n"
},
{
"input": "011389\n",
"output": "2\n"
},
{
"input": "642479\n",
"output": "1\n"
},
{
"input": "024887\n",
"output": "2\n"
},
{
"input": "223456\n",
"output": "2\n"
},
{
"input": "999000\n",
"output": "3\n"
},
{
"input": "822569\n",
"output": "1\n"
},
{
"input": "858643\n",
"output": "1\n"
},
{
"input": "126999\n",
"output": "2\n"
},
{
"input": "000001\n",
"output": "1\n"
},
{
"input": "969503\n",
"output": "2\n"
},
{
"input": "999911\n",
"output": "2\n"
},
{
"input": "335667\n",
"output": "2\n"
},
{
"input": "777445\n",
"output": "2\n"
},
{
"input": "505777\n",
"output": "2\n"
},
{
"input": "888213\n",
"output": "3\n"
},
{
"input": "958031\n",
"output": "2\n"
},
{
"input": "145892\n",
"output": "1\n"
},
{
"input": "211597\n",
"output": "2\n"
},
{
"input": "117999\n",
"output": "2\n"
},
{
"input": "118000\n",
"output": "2\n"
},
{
"input": "023869\n",
"output": "2\n"
},
{
"input": "301697\n",
"output": "2\n"
},
{
"input": "369009\n",
"output": "1\n"
},
{
"input": "999198\n",
"output": "1\n"
},
{
"input": "588121\n",
"output": "3\n"
},
{
"input": "222455\n",
"output": "2\n"
},
{
"input": "213986\n",
"output": "2\n"
},
{
"input": "301679\n",
"output": "2\n"
},
{
"input": "123789\n",
"output": "3\n"
},
{
"input": "010339\n",
"output": "2\n"
},
{
"input": "738000\n",
"output": "2\n"
},
{
"input": "111956\n",
"output": "2\n"
},
{
"input": "123986\n",
"output": "2\n"
},
{
"input": "198999\n",
"output": "1\n"
},
{
"input": "900000\n",
"output": "1\n"
},
{
"input": "213698\n",
"output": "2\n"
},
{
"input": "989010\n",
"output": "3\n"
},
{
"input": "099999\n",
"output": "1\n"
},
{
"input": "201984\n",
"output": "2\n"
},
{
"input": "887321\n",
"output": "3\n"
},
{
"input": "004977\n",
"output": "3\n"
},
{
"input": "989473\n",
"output": "2\n"
},
{
"input": "321933\n",
"output": "1\n"
},
{
"input": "989304\n",
"output": "3\n"
},
{
"input": "242367\n",
"output": "2\n"
},
{
"input": "652858\n",
"output": "1\n"
},
{
"input": "766100\n",
"output": "2\n"
},
{
"input": "006456\n",
"output": "1\n"
},
{
"input": "420337\n",
"output": "1\n"
},
{
"input": "022995\n",
"output": "3\n"
},
{
"input": "769302\n",
"output": "2\n"
},
{
"input": "001000\n",
"output": "1\n"
},
{
"input": "988034\n",
"output": "2\n"
},
{
"input": "000111\n",
"output": "1\n"
},
{
"input": "320869\n",
"output": "2\n"
},
{
"input": "988430\n",
"output": "2\n"
},
{
"input": "042762\n",
"output": "1\n"
},
{
"input": "089753\n",
"output": "1\n"
},
{
"input": "030039\n",
"output": "1\n"
},
{
"input": "117099\n",
"output": "1\n"
},
{
"input": "868580\n",
"output": "1\n"
},
{
"input": "651894\n",
"output": "1\n"
},
{
"input": "191000\n",
"output": "2\n"
},
{
"input": "434946\n",
"output": "1\n"
},
{
"input": "371130\n",
"output": "1\n"
},
{
"input": "111695\n",
"output": "2\n"
},
{
"input": "103452\n",
"output": "1\n"
},
{
"input": "878033\n",
"output": "2\n"
},
{
"input": "111965\n",
"output": "2\n"
},
{
"input": "000444\n",
"output": "2\n"
},
{
"input": "123987\n",
"output": "3\n"
},
{
"input": "777544\n",
"output": "2\n"
},
{
"input": "333665\n",
"output": "2\n"
},
{
"input": "696327\n",
"output": "1\n"
},
{
"input": "895130\n",
"output": "2\n"
},
{
"input": "899889\n",
"output": "1\n"
},
{
"input": "979245\n",
"output": "2\n"
},
{
"input": "122669\n",
"output": "2\n"
},
{
"input": "011488\n",
"output": "3\n"
},
{
"input": "636915\n",
"output": "0\n"
},
{
"input": "023680\n",
"output": "1\n"
},
{
"input": "401779\n",
"output": "2\n"
},
{
"input": "000900\n",
"output": "1\n"
},
{
"input": "599257\n",
"output": "1\n"
},
{
"input": "003669\n",
"output": "2\n"
},
{
"input": "111399\n",
"output": "2\n"
},
{
"input": "697742\n",
"output": "1\n"
},
{
"input": "999333\n",
"output": "2\n"
},
{
"input": "466341\n",
"output": "1\n"
},
{
"input": "132069\n",
"output": "1\n"
},
{
"input": "314347\n",
"output": "1\n"
},
{
"input": "080189\n",
"output": "2\n"
},
{
"input": "949256\n",
"output": "1\n"
},
{
"input": "154999\n",
"output": "2\n"
},
{
"input": "002667\n",
"output": "2\n"
},
{
"input": "990900\n",
"output": "1\n"
},
{
"input": "788024\n",
"output": "2\n"
},
{
"input": "990131\n",
"output": "2\n"
},
{
"input": "567235\n",
"output": "2\n"
},
{
"input": "990000\n",
"output": "2\n"
}
] | code_contests | python | 0 | 59a2476b897553251ccbe3ec1527b782 |
You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the N days you would like to again own zero shares, but want to have as much money as possible.
Input
Input begins with an integer N (2 ≤ N ≤ 3·105), the number of days.
Following this is a line with exactly N integers p1, p2, ..., pN (1 ≤ pi ≤ 106). The price of one share of stock on the i-th day is given by pi.
Output
Print the maximum amount of money you can end up with at the end of N days.
Examples
Input
9
10 5 4 7 9 12 6 2 10
Output
20
Input
20
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
Output
41
Note
In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is - 5 - 4 + 9 + 12 - 2 + 10 = 20.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from heapq import *
N = int(input())
price = [int(i) for i in input().split()]
total = 0
inf = (10**6) + 1
h = [inf]
#Assume we bought and sold optimally for the first k prices.
#We adjust our answer for the (k+1)th price that comes up.
for p in price:
if p > h[0]:
total += (p - heappop(h))
#We push p onto heap in case we should have bought at this price instead
#of selling.
heappush(h, p)
heappush(h, p)
print(total) | python | code_algorithm | [
{
"input": "9\n10 5 4 7 9 12 6 2 10\n",
"output": "20\n"
},
{
"input": "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\n",
"output": "41\n"
},
{
"input": "100\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 501 603 234 285 297 453 587 550 72 130 163 282 298 605 349 270 198 24 179 243 92 115 56 83 26 3 456 622 325 366 360 299 153 140 552 216 117 61 307 278 189 496 562 38 527 566 503 303 16 36 286 632 196 395 452 194 77 321 615 356 250 381 174 139 123\n",
"output": "13765\n"
},
{
"input": "20\n499559 302871 194704 903169 447219 409938 42087 753609 589270 719332 855199 609182 315644 980473 966759 851389 900793 905536 258772 453222\n",
"output": "4620235\n"
},
{
"input": "47\n403136 169462 358897 935260 150614 688938 111490 148144 462915 753991 551831 303917 772190 188564 854800 7094 491120 997932 271873 236736 797113 427200 681780 911765 217707 339475 313125 56785 749677 313468 902148 993064 747609 387815 768631 41886 68862 707668 32853 653517 941150 858711 562604 867235 840369 337814 129019\n",
"output": "12525965\n"
},
{
"input": "2\n4 77\n",
"output": "73\n"
},
{
"input": "20\n9 29 8 9 13 4 14 27 16 11 27 14 4 29 23 17 3 9 30 19\n",
"output": "147\n"
}
] | code_contests | python | 0 | 5c55d79e471054a5b62c0645ba09927e |
Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends exactly one minute to move to some adjacent cell. Vasya cannot leave the glade. Two cells are considered adjacent if they share a common side. When Vasya enters some cell, he instantly collects all the mushrooms growing there.
Vasya begins his journey in the left upper cell. Every minute Vasya must move to some adjacent cell, he cannot wait for the mushrooms to grow. He wants to visit all the cells exactly once and maximize the total weight of the collected mushrooms. Initially, all mushrooms have a weight of 0. Note that Vasya doesn't need to return to the starting cell.
Help Vasya! Calculate the maximum total weight of mushrooms he can collect.
Input
The first line contains the number n (1 ≤ n ≤ 3·105) — the length of the glade.
The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the growth rate of mushrooms in the first row of the glade.
The third line contains n numbers b1, b2, ..., bn (1 ≤ bi ≤ 106) is the growth rate of mushrooms in the second row of the glade.
Output
Output one number — the maximum total weight of mushrooms that Vasya can collect by choosing the optimal route. Pay attention that Vasya must visit every cell of the glade exactly once.
Examples
Input
3
1 2 3
6 5 4
Output
70
Input
3
1 1000 10000
10 100 100000
Output
543210
Note
In the first test case, the optimal route is as follows:
<image> Thus, the collected weight of mushrooms will be 0·1 + 1·2 + 2·3 + 3·4 + 4·5 + 5·6 = 70.
In the second test case, the optimal route is as follows:
<image> Thus, the collected weight of mushrooms will be 0·1 + 1·10 + 2·100 + 3·1000 + 4·10000 + 5·100000 = 543210.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
u1 = list(map(int, input().split()))
u2 = list(map(int, input().split()))
a1 = u1[:n]
a2 = u2[:n]
for i in range(1, n):
a1[i] += a1[i - 1]
a2[i] += a2[i - 1]
q1 = [0] * (2 * n)
q2 = [0] * (2 * n)
for i in range(1, n):
q1[i] = u1[i] * (i) + q1[i - 1]
q2[i] = u2[i] * (i) + q2[i - 1]
for i in range(n):
q1[i + n] = u2[n - i - 1] * (n + i) + q1[i + n - 1]
q2[i + n] = u1[n - i - 1] * (n + i) + q2[i + n - 1]
ans = q1[-1]
cur = 0
#print(ans)
for i in range(n):
ans1 = (a1[-1] - a1[i] + a2[-1] - a2[i]) * (i + 1)
if i % 2 == 0:
cur += u1[i] * (i * 2)
cur += u2[i] * (i * 2 + 1)
ans1 += (q2[n * 2 - i - 2] - q2[i]) + cur
else:
cur += u2[i] * (i * 2)
cur += u1[i] * (i * 2 + 1)
ans1 += (q1[n * 2 - i - 2] - q1[i]) + cur
ans = max(ans, ans1)
#print(ans1, cur)
print(ans)
'''
3
1 100000 10000
10 100 1000
6
12 8 12 17 20 5
17 4 8 8 8 4
'''
| python | code_algorithm | [
{
"input": "3\n1 2 3\n6 5 4\n",
"output": "70\n"
},
{
"input": "3\n1 1000 10000\n10 100 100000\n",
"output": "543210\n"
},
{
"input": "6\n12 8 12 17 20 5\n17 4 8 8 8 4\n",
"output": "705\n"
},
{
"input": "6\n4 1 12 9 3 11\n12 20 19 12 19 11\n",
"output": "917\n"
},
{
"input": "1\n1\n1\n",
"output": "1\n"
},
{
"input": "2\n1 2\n1 1\n",
"output": "9\n"
},
{
"input": "1\n7\n5\n",
"output": "5\n"
},
{
"input": "6\n16 20 18 7 14 2\n17 12 4 10 7 4\n",
"output": "741\n"
}
] | code_contests | python | 0 | 744ae33c115c70dd917b868aec1add27 |
The Fair Nut found a string s. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p_1, p_2, …, p_k, such that:
1. For each i (1 ≤ i ≤ k), s_{p_i} = 'a'.
2. For each i (1 ≤ i < k), there is such j that p_i < j < p_{i + 1} and s_j = 'b'.
The Nut is upset because he doesn't know how to find the number. Help him.
This number should be calculated modulo 10^9 + 7.
Input
The first line contains the string s (1 ≤ |s| ≤ 10^5) consisting of lowercase Latin letters.
Output
In a single line print the answer to the problem — the number of such sequences p_1, p_2, …, p_k modulo 10^9 + 7.
Examples
Input
abbaa
Output
5
Input
baaaa
Output
4
Input
agaa
Output
3
Note
In the first example, there are 5 possible sequences. [1], [4], [5], [1, 4], [1, 5].
In the second example, there are 4 possible sequences. [2], [3], [4], [5].
In the third example, there are 3 possible sequences. [1], [3], [4].
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | s=input()
sss=''
for i in s:
if i in ['a','b']:
sss+=i
from itertools import groupby
xxx=[''.join(g) for _, g in groupby(sss)]
xxx=[len(i)+1 for i in xxx if 'a' in i]
ans=1
if len(xxx)==1:
print((xxx[0]-1)%1000000007)
else:
for i in xxx:
ans*=i
print((ans-1)%1000000007)
| python | code_algorithm | [
{
"input": "agaa\n",
"output": "3\n"
},
{
"input": "baaaa\n",
"output": "4\n"
},
{
"input": "abbaa\n",
"output": "5\n"
},
{
"input": "aaaaabb\n",
"output": "5\n"
},
{
"input": "aabaaaa\n",
"output": "14\n"
},
{
"input": "babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb\n",
"output": "42467327\n"
},
{
"input": "baaahbbbba\n",
"output": "7\n"
},
{
"input": "ababavvvv\n",
"output": "7\n"
},
{
"input": "abnxabbaab\n",
"output": "11\n"
},
{
"input": "krflnzhter\n",
"output": "0\n"
},
{
"input": "amaabbbbxaabbbabaabaabbaaabaaaaabibbabaabaaabaabcaaxabablbbbbmbbbaaaaaabbaabbbaaabaaaababaababbabbbb\n",
"output": "98718509\n"
},
{
"input": "babbbaaaaaabbbaabaaaaaoaabababaababaaaaababaaaaaaabbbbbbaaapaabaaabaaababaaaabaaaabaaaaababaaaabaaab\n",
"output": "813881762\n"
}
] | code_contests | python | 0 | 882c318bace45523e58f9028249935b4 |
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.
The j-th key can be used to unlock the i-th chest if and only if the sum of the key number and the chest number is an odd number. Formally, a_i + b_j ≡ 1 \pmod{2}. One key can be used to open at most one chest, and one chest can be opened at most once.
Find the maximum number of chests Neko can open.
Input
The first line contains integers n and m (1 ≤ n, m ≤ 10^5) — the number of chests and the number of keys.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the numbers written on the treasure chests.
The third line contains m integers b_1, b_2, …, b_m (1 ≤ b_i ≤ 10^9) — the numbers written on the keys.
Output
Print the maximum number of chests you can open.
Examples
Input
5 4
9 14 6 2 11
8 4 7 20
Output
3
Input
5 1
2 4 6 8 10
5
Output
1
Input
1 4
10
20 30 40 50
Output
0
Note
In the first example, one possible way to unlock 3 chests is as follows:
* Use first key to unlock the fifth chest,
* Use third key to unlock the second chest,
* Use fourth key to unlock the first chest.
In the second example, you can use the only key to unlock any single chest (note that one key can't be used twice).
In the third example, no key can unlock the given chest.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aeven = 0
aodd = 0
beven = 0
bodd = 0
for i in range(n):
if a[i] % 2 == 0:
aeven += 1
else:
aodd += 1
for i in range(m):
if b[i] % 2 == 0:
beven += 1
else:
bodd += 1
print(min(aeven, bodd)+min(aodd, beven))
| python | code_algorithm | [
{
"input": "5 1\n2 4 6 8 10\n5\n",
"output": "1\n"
},
{
"input": "1 4\n10\n20 30 40 50\n",
"output": "0\n"
},
{
"input": "5 4\n9 14 6 2 11\n8 4 7 20\n",
"output": "3\n"
},
{
"input": "4 1\n3 5 7 8\n2\n",
"output": "1\n"
},
{
"input": "5 1\n2 2 2 3 3\n3\n",
"output": "1\n"
},
{
"input": "4 1\n1 1 2 2\n2\n",
"output": "1\n"
},
{
"input": "10 10\n522312461 931001459 598654597 488228616 544064902 21923894 329635457 980089248 988262691 654502493\n967529230 543358150 835120075 128123793 809901567 613170206 152157661 479980560 859252956 318029856\n",
"output": "10\n"
},
{
"input": "27 9\n72 105 100 105 110 103 32 109 101 115 115 97 103 101 115 32 105 110 32 116 101 115 116 99 97 115 101\n83 110 101 97 107 32 49 48 48\n",
"output": "9\n"
},
{
"input": "4 1\n1 1 1 2\n2\n",
"output": "1\n"
},
{
"input": "7 4\n116 111 117 114 105 115 116\n112 101 116 114\n",
"output": "4\n"
},
{
"input": "4 1\n2 2 3 3\n2\n",
"output": "1\n"
},
{
"input": "7 4\n2 2 1 1 1 1 1\n2 2 2 1\n",
"output": "4\n"
},
{
"input": "6 4\n2 4 6 1 3 5\n8 10 7 9\n",
"output": "4\n"
},
{
"input": "4 2\n3 2 1 4\n2 3\n",
"output": "2\n"
},
{
"input": "1 5\n3\n3 4 4 4 4\n",
"output": "1\n"
},
{
"input": "5 1\n1 2 3 4 5\n1\n",
"output": "1\n"
},
{
"input": "3 10\n107 117 110\n71 114 101 101 110 71 114 97 112 101\n",
"output": "3\n"
},
{
"input": "1 10\n1\n1 2 3 4 5 6 7 8 9 10\n",
"output": "1\n"
},
{
"input": "2 4\n1 2\n1 1 2 2\n",
"output": "2\n"
},
{
"input": "5 2\n1 2 2 2 2\n1 1\n",
"output": "2\n"
}
] | code_contests | python | 1 | f1f14bc602cb2f7d6d9da5c4ad841cbd |
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.
Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
<image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10.
Tokitsukaze wants to know the number of operations she would do in total.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 10^{18}, 1 ≤ m ≤ 10^5, 1 ≤ m, k ≤ n) — the number of items, the number of special items to be discarded and the number of positions in each page.
The second line contains m distinct integers p_1, p_2, …, p_m (1 ≤ p_1 < p_2 < … < p_m ≤ n) — the indices of special items which should be discarded.
Output
Print a single integer — the number of operations that Tokitsukaze would do in total.
Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
For the first example:
* In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5;
* In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7;
* In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10.
For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from collections import deque
n,m,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
d=deque()
for i in arr:
d.append(i)
chances=curr=tot=0
# print("WORKING")
while tot<m:
# print("S")
if (d[0]-curr)%k==0:
p=(d[0]-curr)//k
else:p=((d[0]-curr)//k)+1
temp=curr
while tot<m and d[0]-temp<=(p*k):
d.popleft()
curr+=1
tot+=1
chances+=1
print(chances) | python | code_algorithm | [
{
"input": "13 4 5\n7 8 9 10\n",
"output": "1\n"
},
{
"input": "10 4 5\n3 5 7 10\n",
"output": "3\n"
},
{
"input": "10 5 5\n2 3 4 5 6\n",
"output": "2\n"
},
{
"input": "1 1 1\n1\n",
"output": "1\n"
},
{
"input": "1000000000000000000 10 68\n9818112234872670 233245257111863071 266483628625876079 375103213040049805 431982380866113633 489732004669478331 501030096787260719 541800997319766183 551892546260532408 696178619227890200\n",
"output": "10\n"
},
{
"input": "1000000000000000000 2 1\n1 1000000000000000000\n",
"output": "2\n"
},
{
"input": "33 32 1\n1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33\n",
"output": "32\n"
},
{
"input": "101 55 10\n1 3 5 7 8 9 10 16 18 21 22 23 24 25 27 30 32 35 36 37 38 39 40 43 45 47 49 50 51 52 54 57 59 61 64 66 67 68 69 70 71 72 73 80 83 86 87 88 89 90 91 92 96 97 98\n",
"output": "15\n"
},
{
"input": "1000000000000000000 5 1000\n1 1000000000 1000000000000 1000000000000000 1000000000000001\n",
"output": "4\n"
},
{
"input": "15 15 15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n",
"output": "1\n"
},
{
"input": "21 21 20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21\n",
"output": "2\n"
},
{
"input": "45 43 2\n1 2 3 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45\n",
"output": "35\n"
},
{
"input": "107 20 13\n5 9 20 25 26 30 37 45 51 58 62 73 82 87 89 90 99 101 104 106\n",
"output": "9\n"
},
{
"input": "3 2 1\n1 2\n",
"output": "2\n"
},
{
"input": "1000000000 2 1000000000\n1 1000000000\n",
"output": "1\n"
},
{
"input": "11 7 3\n2 3 4 5 6 7 11\n",
"output": "4\n"
},
{
"input": "13 9 4\n1 2 3 6 7 8 11 12 13\n",
"output": "4\n"
},
{
"input": "1000000000000000000 2 1000000000\n102306300054748096 267367244641009859\n",
"output": "2\n"
},
{
"input": "16 7 5\n2 3 4 5 6 15 16\n",
"output": "4\n"
},
{
"input": "35 35 1\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\n",
"output": "35\n"
},
{
"input": "1000000000000000000 20 365\n31881893160049984 103938857870698567 103962228223609431 140762820261865064 175962215264653912 239086305245565642 354522451098745823 383839975876242372 443471287955807705 478923027151493682 511195154588214957 619570919279066139 677571312513476877 705864797651447277 789633853044745934 867300890280086078 883297431113041450 891736036124527038 937306858250803630 990892290394455512\n",
"output": "20\n"
}
] | code_contests | python | 0 | f905e505c1508f529048de622c3bf9df |
Dawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?
Note, that you can't keep bags for yourself or throw them away, each bag should be given to one of the friends.
Input
The only line contains four integers a_1, a_2, a_3 and a_4 (1 ≤ a_i ≤ 100) — the numbers of candies in each bag.
Output
Output YES if it's possible to give the bags to Dawid's friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).
Examples
Input
1 7 11 5
Output
YES
Input
7 3 2 5
Output
NO
Note
In the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive 12 candies.
In the second sample test, it's impossible to distribute the bags.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | list1 = list(map(int, input().split()))
list1.sort()
if list1[0] + list1[3] == list1[1] + list1[2]:
print("YES")
elif list1[0] + list1[2] +list1[1] == list1[3]:
print("YES")
else:
print("NO") | python | code_algorithm | [
{
"input": "1 7 11 5\n",
"output": "YES\n"
},
{
"input": "7 3 2 5\n",
"output": "NO\n"
},
{
"input": "44 58 90 53\n",
"output": "NO\n"
},
{
"input": "20 14 37 71\n",
"output": "YES\n"
},
{
"input": "4 2 4 2\n",
"output": "YES\n"
},
{
"input": "1 2 5 5\n",
"output": "NO\n"
},
{
"input": "1 2 8 9\n",
"output": "YES\n"
},
{
"input": "99 100 3 98\n",
"output": "NO\n"
},
{
"input": "92 69 83 97\n",
"output": "NO\n"
},
{
"input": "3 1 1 1\n",
"output": "YES\n"
},
{
"input": "18 88 18 18\n",
"output": "NO\n"
},
{
"input": "1 1 1 1\n",
"output": "YES\n"
},
{
"input": "69 7 44 30\n",
"output": "NO\n"
},
{
"input": "90 30 30 30\n",
"output": "YES\n"
},
{
"input": "1 2 3 5\n",
"output": "NO\n"
},
{
"input": "1 1 3 1\n",
"output": "YES\n"
},
{
"input": "6 3 6 6\n",
"output": "NO\n"
},
{
"input": "26 52 7 19\n",
"output": "YES\n"
},
{
"input": "6 4 8 6\n",
"output": "YES\n"
},
{
"input": "10 2 3 5\n",
"output": "YES\n"
},
{
"input": "34 11 84 39\n",
"output": "YES\n"
},
{
"input": "1 1 14 12\n",
"output": "YES\n"
},
{
"input": "3 2 1 1\n",
"output": "NO\n"
},
{
"input": "2 4 6 6\n",
"output": "NO\n"
},
{
"input": "1 1 2 1\n",
"output": "NO\n"
},
{
"input": "72 96 2 26\n",
"output": "YES\n"
},
{
"input": "97 95 91 27\n",
"output": "NO\n"
},
{
"input": "1 2 1 3\n",
"output": "NO\n"
},
{
"input": "1 1 2 3\n",
"output": "NO\n"
},
{
"input": "1 1 1 2\n",
"output": "NO\n"
},
{
"input": "1 1 10 20\n",
"output": "NO\n"
},
{
"input": "2 3 2 5\n",
"output": "NO\n"
},
{
"input": "1 2 10 7\n",
"output": "YES\n"
},
{
"input": "2 1 28 9\n",
"output": "NO\n"
},
{
"input": "4 4 4 8\n",
"output": "NO\n"
},
{
"input": "2 2 4 6\n",
"output": "NO\n"
},
{
"input": "72 52 62 62\n",
"output": "YES\n"
},
{
"input": "76 97 99 74\n",
"output": "YES\n"
},
{
"input": "100 100 99 100\n",
"output": "NO\n"
},
{
"input": "30 74 41 63\n",
"output": "YES\n"
},
{
"input": "5 10 1 6\n",
"output": "YES\n"
},
{
"input": "18 17 17 20\n",
"output": "NO\n"
},
{
"input": "2 4 1 1\n",
"output": "YES\n"
},
{
"input": "7 3 6 3\n",
"output": "NO\n"
},
{
"input": "1 1 4 5\n",
"output": "NO\n"
},
{
"input": "2 2 6 2\n",
"output": "YES\n"
},
{
"input": "1 2 6 3\n",
"output": "YES\n"
},
{
"input": "3 5 1 3\n",
"output": "YES\n"
},
{
"input": "70 100 10 86\n",
"output": "NO\n"
},
{
"input": "48 14 3 31\n",
"output": "YES\n"
},
{
"input": "2 6 3 2\n",
"output": "NO\n"
},
{
"input": "2 3 10 10\n",
"output": "NO\n"
},
{
"input": "4 4 12 4\n",
"output": "YES\n"
},
{
"input": "14 9 10 6\n",
"output": "NO\n"
},
{
"input": "100 98 99 97\n",
"output": "YES\n"
},
{
"input": "5 7 1 3\n",
"output": "YES\n"
},
{
"input": "1 1 4 2\n",
"output": "YES\n"
},
{
"input": "14 10 18 24\n",
"output": "NO\n"
},
{
"input": "1 100 100 1\n",
"output": "YES\n"
},
{
"input": "1 2 4 5\n",
"output": "YES\n"
},
{
"input": "1 2 3 4\n",
"output": "YES\n"
},
{
"input": "1 2 3 3\n",
"output": "NO\n"
},
{
"input": "4 4 4 5\n",
"output": "NO\n"
},
{
"input": "66 68 16 82\n",
"output": "NO\n"
},
{
"input": "1 2 3 2\n",
"output": "YES\n"
},
{
"input": "2 3 3 4\n",
"output": "YES\n"
},
{
"input": "100 100 100 100\n",
"output": "YES\n"
},
{
"input": "1 2 2 7\n",
"output": "NO\n"
},
{
"input": "3 14 36 53\n",
"output": "YES\n"
},
{
"input": "1 1 3 4\n",
"output": "NO\n"
}
] | code_contests | python | 0.1 | 80b0623685a5c1d5696f1ae45b1023bd |
VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications.
The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of i-th category within t_i seconds.
What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can't remove publications recommended by the batch algorithm.
Input
The first line of input consists of single integer n — the number of news categories (1 ≤ n ≤ 200 000).
The second line of input consists of n integers a_i — the number of publications of i-th category selected by the batch algorithm (1 ≤ a_i ≤ 10^9).
The third line of input consists of n integers t_i — time it takes for targeted algorithm to find one new publication of category i (1 ≤ t_i ≤ 10^5).
Output
Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.
Examples
Input
5
3 7 9 7 8
5 2 5 7 5
Output
6
Input
5
1 2 3 4 5
1 1 1 1 1
Output
0
Note
In the first example, it is possible to find three publications of the second type, which will take 6 seconds.
In the second example, all news categories contain a different number of publications.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | # Код программы написал на языке Python 3
import sys
from heapq import heappush, heappop
def main():
n = int(sys.stdin.readline())
h = sorted(list(zip([int(i) for i in sys.stdin.readline().split()], [int(i) for i in sys.stdin.readline().split()])))
z, w, o, res = [], 0, 0, 0
while o < n:
t = h[o][0]
w += h[o][1]
heappush(z, -1 * h[o][1])
while 0 < n - o - 1 and h[o][0] == h[o + 1][0]:
o += 1
w += h[o][1]
heappush(z, -1 * h[o][1])
if o + 1 == n:
cur = 1e18
else:
cur = h[o + 1][0]
while z and t - cur < 0:
t += 1
w += heappop(z)
res += w
o += 1
print(res)
for test in range(1):
main() | python | code_algorithm | [
{
"input": "5\n3 7 9 7 8\n5 2 5 7 5\n",
"output": "6\n"
},
{
"input": "5\n1 2 3 4 5\n1 1 1 1 1\n",
"output": "0\n"
},
{
"input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n100000 100000 100000 100000 100000\n",
"output": "1000000\n"
},
{
"input": "10\n14 31 50 67 42 44 86 82 35 63\n76 17 26 44 60 54 50 73 71 70\n",
"output": "0\n"
},
{
"input": "10\n4 4 1 2 2 2 5 4 1 5\n28 81 36 44 2 40 39 43 36 33\n",
"output": "593\n"
},
{
"input": "10\n69564153 558821634 273092444 121621442 354953668 157021146 918149509 902159900 772175415 945981912\n29 26 22 78 90 35 24 75 52 53\n",
"output": "0\n"
},
{
"input": "1\n743365444\n98\n",
"output": "0\n"
},
{
"input": "5\n298137706 371378543 159326899 423775489 643749813\n1 90 76 23 14\n",
"output": "0\n"
},
{
"input": "5\n2 52 60 67 26\n51 96 75 41 88\n",
"output": "0\n"
},
{
"input": "2\n8 4\n57 28\n",
"output": "0\n"
},
{
"input": "5\n12 4 19 18 19\n15467 14873 66248 58962 90842\n",
"output": "66248\n"
},
{
"input": "1\n380100964\n63923\n",
"output": "0\n"
},
{
"input": "2\n3 2\n55839 83916\n",
"output": "0\n"
},
{
"input": "2\n1000000000 1000000000\n100000 100000\n",
"output": "100000\n"
},
{
"input": "2\n5 3\n96 59\n",
"output": "0\n"
},
{
"input": "1\n4\n85648\n",
"output": "0\n"
},
{
"input": "2\n84 18\n96 92\n",
"output": "0\n"
},
{
"input": "5\n4 2 4 3 3\n8 9 34 54 14\n",
"output": "44\n"
},
{
"input": "1\n23\n29532\n",
"output": "0\n"
},
{
"input": "2\n759394108 613490963\n19556 57005\n",
"output": "0\n"
},
{
"input": "1\n1000000000\n100000\n",
"output": "0\n"
},
{
"input": "2\n624526990 51492804\n74 4\n",
"output": "0\n"
},
{
"input": "1\n1\n72\n",
"output": "0\n"
},
{
"input": "1\n5\n16\n",
"output": "0\n"
},
{
"input": "2\n86 67\n77701 9079\n",
"output": "0\n"
},
{
"input": "2\n7 6\n2374 9808\n",
"output": "0\n"
},
{
"input": "5\n487208130 193137490 653652531 77955217 628457798\n37995 12724 66478 45619 87697\n",
"output": "0\n"
},
{
"input": "1\n204\n74562\n",
"output": "0\n"
},
{
"input": "5\n82 90 21 10 3\n37195 83314 87379 83209 32491\n",
"output": "0\n"
},
{
"input": "5\n3 10 9 5 8\n12157 40766 83283 22455 29741\n",
"output": "0\n"
},
{
"input": "10\n1 4 2 3 5 1 3 5 4 2\n95757 10134 79392 48220 34450 34587 61472 88154 76492 38800\n",
"output": "779373\n"
},
{
"input": "5\n8 2 3 10 1\n2 37 19 73 60\n",
"output": "0\n"
},
{
"input": "1\n3\n31\n",
"output": "0\n"
},
{
"input": "10\n2 2 2 6 4 4 10 2 2 8\n18 13 94 43 72 62 23 47 94 41\n",
"output": "630\n"
},
{
"input": "10\n97 75 68 98 56 44 68 24 40 18\n75753 53146 17573 59200 87853 73083 67536 45475 70260 99681\n",
"output": "17573\n"
},
{
"input": "40\n19 20 8 13 13 17 1 14 15 20 14 17 2 9 9 10 19 16 6 12 9 7 20 5 12 6 4 4 12 5 4 11 8 1 2 8 11 19 18 4\n52258 5648 46847 9200 63940 79328 64407 54479 1788 60107 8234 64215 15419 84411 50307 78075 92548 17867 43456 7970 1390 99373 97297 90662 82950 678 79356 51351 2794 82477 16508 19254 81295 9711 72350 11578 21595 69230 82626 25134\n",
"output": "6113465\n"
},
{
"input": "10\n400625724 498124775 960958038 697226708 233136478 292118728 33139194 339478293 914271877 828083523\n9789 90524 51162 97707 59267 60261 43260 60358 64419 44097\n",
"output": "0\n"
},
{
"input": "10\n2 5 1 9 1 2 7 8 1 10\n38888 43309 35602 62895 51161 96523 20607 20309 21976 21231\n",
"output": "255574\n"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000\n",
"output": "4500000\n"
},
{
"input": "5\n1 5 1 2 1\n49027 92184 18591 86401 84238\n",
"output": "153827\n"
},
{
"input": "1\n1\n40825\n",
"output": "0\n"
}
] | code_contests | python | 0 | 406f59ca0c42acfab93e8a30a04271eb |
Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i.
First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). The score of the game is the total value of the remaining cards on the segment (a_l + a_{l + 1} + ... + a_{j - 1} + a_{j + 1} + ... + a_{r - 1} + a_r). In particular, if Alice chooses a segment with just one element, then the score after Bob removes the only card is 0.
Alice wants to make the score as big as possible. Bob takes such a card that the score is as small as possible.
What segment should Alice choose so that the score is maximum possible? Output the maximum score.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of cards.
The second line contains n integers a_1, a_2, ..., a_n (-30 ≤ a_i ≤ 30) — the values on the cards.
Output
Print a single integer — the final score of the game.
Examples
Input
5
5 -2 10 -1 4
Output
6
Input
8
5 2 5 3 -30 -30 6 9
Output
10
Input
3
-10 6 -15
Output
0
Note
In the first example Alice chooses a segment [1;5] — the entire row of cards. Bob removes card 3 with the value 10 from the segment. Thus, the final score is 5 + (-2) + (-1) + 4 = 6.
In the second example Alice chooses a segment [1;4], so that Bob removes either card 1 or 3 with the value 5, making the answer 5 + 2 + 3 = 10.
In the third example Alice can choose any of the segments of length 1: [1;1], [2;2] or [3;3]. Bob removes the only card, so the score is 0. If Alice chooses some other segment then the answer will be less than 0.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import math
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(31):
s = 0
for j in a:
if j <= i:
s = max(0, s + j)
else:
s = 0
ans = max(ans, s - i)
print(ans) | python | code_algorithm | [
{
"input": "3\n-10 6 -15\n",
"output": "0\n"
},
{
"input": "8\n5 2 5 3 -30 -30 6 9\n",
"output": "10\n"
},
{
"input": "5\n5 -2 10 -1 4\n",
"output": "6\n"
},
{
"input": "10\n-3 4 -4 1 1 -4 -5 3 -4 -2\n",
"output": "1\n"
},
{
"input": "10\n8 9 -10 -10 -4 -3 5 9 -9 9\n",
"output": "8\n"
},
{
"input": "6\n5 -4 2 -1 2 -2\n",
"output": "1\n"
},
{
"input": "11\n3 0 1 -2 5 -5 -1 0 3 2 2\n",
"output": "4\n"
},
{
"input": "10\n4 -2 -2 -2 2 0 1 0 -4 -1\n",
"output": "1\n"
},
{
"input": "4\n2 2 -3 4\n",
"output": "2\n"
},
{
"input": "11\n-11 -7 -2 -24 30 -26 24 9 -8 -9 23\n",
"output": "15\n"
},
{
"input": "6\n30 -29 5 5 -29 30\n",
"output": "5\n"
},
{
"input": "24\n-8 -6 6 -11 -15 -7 10 -19 -6 21 14 -4 -21 -10 12 17 1 -1 5 19 2 0 -4 -23\n",
"output": "36\n"
},
{
"input": "10\n-9 -6 -1 9 -2 0 0 -1 5 0\n",
"output": "2\n"
},
{
"input": "6\n10 -8 3 3 -8 10\n",
"output": "3\n"
},
{
"input": "10\n-2 -3 -1 4 -3 2 0 1 -5 4\n",
"output": "1\n"
},
{
"input": "5\n30 -29 10 -1 10\n",
"output": "9\n"
},
{
"input": "31\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 -29 30\n",
"output": "28\n"
},
{
"input": "7\n30 -20 5 1 3 -20 30\n",
"output": "4\n"
},
{
"input": "5\n30 -29 4 -3 4\n",
"output": "1\n"
},
{
"input": "10\n-5 28 -18 -10 9 -2 11 -6 -19 30\n",
"output": "7\n"
},
{
"input": "8\n4 -10 13 -13 2 2 -11 6\n",
"output": "2\n"
},
{
"input": "131\n30 -29 29 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 27 -26 27\n",
"output": "1\n"
},
{
"input": "10\n-4 4 0 -2 3 0 1 2 3 -4\n",
"output": "7\n"
},
{
"input": "10\n-2 -8 5 4 -1 -6 -9 6 1 -6\n",
"output": "4\n"
},
{
"input": "7\n25 -17 13 13 -25 25 -24\n",
"output": "13\n"
},
{
"input": "10\n3 -3 2 1 -4 -2 3 -2 -3 0\n",
"output": "1\n"
},
{
"input": "10\n4 -5 0 4 0 0 -3 1 1 -4\n",
"output": "1\n"
},
{
"input": "10\n0 4 4 1 -3 4 2 1 4 -1\n",
"output": "13\n"
},
{
"input": "17\n15 -13 7 8 8 1 -19 12 8 -23 -4 16 -13 -28 10 -30 -14\n",
"output": "16\n"
},
{
"input": "4\n1 1 -4 10\n",
"output": "1\n"
},
{
"input": "11\n3 -2 1 1 1 1 1 1 1 -3 4\n",
"output": "6\n"
},
{
"input": "7\n30 -29 10 10 10 -29 30\n",
"output": "20\n"
},
{
"input": "7\n25 -13 17 -23 12 12 9\n",
"output": "21\n"
},
{
"input": "7\n15 -14 10 10 10 -14 15\n",
"output": "20\n"
},
{
"input": "10\n3 0 0 -4 3 1 -2 -1 -1 4\n",
"output": "1\n"
},
{
"input": "6\n8 -7 7 -6 5 5\n",
"output": "5\n"
},
{
"input": "10\n1 -4 -4 4 -2 -3 3 0 -2 3\n",
"output": "1\n"
},
{
"input": "15\n1 -26 -6 26 7 10 -2 -4 -6 14 -9 25 9 -12 -28\n",
"output": "44\n"
},
{
"input": "6\n30 -29 10 10 -29 30\n",
"output": "10\n"
},
{
"input": "1\n6\n",
"output": "0\n"
},
{
"input": "2\n1 1\n",
"output": "1\n"
},
{
"input": "5\n0 5 -4 3 -1\n",
"output": "0\n"
},
{
"input": "7\n5 -4 3 -1 3 -4 4\n",
"output": "2\n"
},
{
"input": "10\n16 -15 13 -1 10 -2 -20 26 5 -30\n",
"output": "9\n"
},
{
"input": "10\n-1 2 0 -1 2 -1 4 3 -5 1\n",
"output": "5\n"
},
{
"input": "7\n5 -4 1 1 1 -4 5\n",
"output": "2\n"
},
{
"input": "5\n10 -3 -5 3 5\n",
"output": "3\n"
},
{
"input": "10\n4 -4 3 -2 3 -4 -2 0 1 0\n",
"output": "1\n"
},
{
"input": "10\n-5 -5 -3 1 -2 2 0 2 -3 4\n",
"output": "2\n"
},
{
"input": "10\n2 -4 -2 3 1 1 -2 -1 -3 4\n",
"output": "2\n"
},
{
"input": "10\n-4 -5 4 -3 2 -2 2 1 -1 0\n",
"output": "1\n"
},
{
"input": "10\n0 -1 4 -2 3 -2 -1 -5 -5 2\n",
"output": "1\n"
},
{
"input": "5\n19 -6 1 -11 19\n",
"output": "3\n"
},
{
"input": "10\n1 0 -4 3 -5 3 -1 2 2 -5\n",
"output": "3\n"
},
{
"input": "7\n5 -5 3 4 3 -5 5\n",
"output": "6\n"
},
{
"input": "10\n-5 2 -3 -3 -4 3 3 0 2 4\n",
"output": "8\n"
},
{
"input": "4\n2 3 -10 11\n",
"output": "2\n"
},
{
"input": "10\n27 -17 15 -22 18 17 -6 2 16 -14\n",
"output": "29\n"
},
{
"input": "6\n30 -22 6 7 -22 30\n",
"output": "6\n"
},
{
"input": "7\n30 -25 0 6 9 -2 10\n",
"output": "13\n"
},
{
"input": "9\n7 2 -1 1 1 -10 6 -1 6\n",
"output": "5\n"
},
{
"input": "4\n1 -10 1 10\n",
"output": "1\n"
},
{
"input": "5\n17 -16 12 -11 15\n",
"output": "1\n"
},
{
"input": "35\n-23 -22 23 4 -22 29 -4 -6 -28 18 -5 21 -7 -8 -11 -7 30 -25 -1 12 19 5 -8 12 -1 10 -24 -19 24 -17 -7 24 20 -22 16\n",
"output": "30\n"
},
{
"input": "10\n4 -3 1 -2 1 1 0 -4 4 -2\n",
"output": "1\n"
},
{
"input": "10\n4 -2 1 0 1 -5 -2 1 0 -5\n",
"output": "1\n"
},
{
"input": "2\n3 9\n",
"output": "3\n"
},
{
"input": "9\n11 -5 -5 1 2 3 -5 -5 11\n",
"output": "3\n"
}
] | code_contests | python | 0 | 14460e3f1d903100b118e0acc276edbc |
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on the rear wheel axle has bj (0 < b1 < b2 < ... < bm) teeth. Any pair (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i, j) has a gear ratio, equal to the value <image>.
Since Vasya likes integers, he wants to find such gears (i, j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i, j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.
In the problem, fraction <image> denotes division in real numbers, that is, no rounding is performed.
Input
The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing.
The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing.
It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.
Output
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
Examples
Input
2
4 5
3
12 13 15
Output
2
Input
4
1 2 3 4
5
10 11 12 13 14
Output
1
Note
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them a1 = 4, b1 = 12, and for the other a2 = 5, b3 = 15.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
count = []
for i in range(n):
for j in range(m):
if((b[j]/a[i])==int(b[j]/a[i])):
count.append(int(b[j]/a[i]))
o = max(count)
print(count.count(o))
| python | code_algorithm | [
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14\n",
"output": "1\n"
},
{
"input": "2\n4 5\n3\n12 13 15\n",
"output": "2\n"
},
{
"input": "1\n1\n2\n1 2\n",
"output": "1\n"
},
{
"input": "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 1649 1940 2078 2134 2716 3492 3686 4462 4559 4656 4756 4850 5044 5490 5529 5592 5626 6014 6111 6693 6790 7178 7275 7566 7663 7702 7857 7954 8342 8511 8730 8957 9021 9215 9377 9445 9991\n",
"output": "28\n"
},
{
"input": "3\n3 4 5\n3\n6 20 25\n",
"output": "2\n"
},
{
"input": "2\n4 5\n3\n12 15 20\n",
"output": "1\n"
},
{
"input": "50\n2 4 5 16 18 19 22 23 25 26 34 44 48 54 67 79 80 84 92 110 116 133 138 154 163 171 174 202 205 218 228 229 234 245 247 249 250 263 270 272 274 275 277 283 289 310 312 334 339 342\n50\n1 5 17 18 25 37 46 47 48 59 67 75 80 83 84 107 115 122 137 141 159 162 175 180 184 204 221 224 240 243 247 248 249 258 259 260 264 266 269 271 274 293 294 306 329 330 334 335 342 350\n",
"output": "1\n"
},
{
"input": "39\n10 13 21 25 36 38 47 48 58 64 68 69 73 79 86 972 2012 2215 2267 2503 3717 3945 4197 4800 5266 6169 6612 6824 7023 7322 7582 7766 8381 8626 8879 9079 9088 9838 9968\n50\n432 877 970 1152 1202 1223 1261 1435 1454 1578 1843 1907 2003 2037 2183 2195 2215 2425 3065 3492 3615 3637 3686 3946 4189 4415 4559 4656 4665 4707 4886 4887 5626 5703 5955 6208 6521 6581 6596 6693 6985 7013 7081 7343 7663 8332 8342 8637 9207 9862\n",
"output": "15\n"
},
{
"input": "20\n79 113 151 709 809 983 1291 1399 1409 1429 2377 2659 2671 2897 3217 3511 3557 3797 3823 4363\n10\n19 101 659 797 1027 1963 2129 2971 3299 9217\n",
"output": "3\n"
},
{
"input": "50\n6 9 11 21 28 39 42 56 60 63 81 88 91 95 105 110 117 125 149 165 174 176 185 189 193 196 205 231 233 268 278 279 281 286 289 292 298 303 305 306 334 342 350 353 361 371 372 375 376 378\n50\n6 17 20 43 45 52 58 59 82 83 88 102 111 118 121 131 145 173 190 191 200 216 224 225 232 235 243 256 260 271 290 291 321 322 323 329 331 333 334 341 343 348 351 354 356 360 366 379 387 388\n",
"output": "1\n"
},
{
"input": "20\n179 359 401 467 521 601 919 941 1103 1279 1709 1913 1949 2003 2099 2143 2179 2213 2399 4673\n20\n151 181 191 251 421 967 1109 1181 1249 1447 1471 1553 1619 2327 2551 2791 3049 3727 6071 7813\n",
"output": "3\n"
},
{
"input": "47\n66 262 357 457 513 530 538 540 592 691 707 979 1015 1242 1246 1667 1823 1886 1963 2133 2649 2679 2916 2949 3413 3523 3699 3958 4393 4922 5233 5306 5799 6036 6302 6629 7208 7282 7315 7822 7833 7927 8068 8150 8870 8962 9987\n39\n167 199 360 528 1515 1643 1986 1988 2154 2397 2856 3552 3656 3784 3980 4096 4104 4240 4320 4736 4951 5266 5656 5849 5850 6169 6517 6875 7244 7339 7689 7832 8120 8716 9503 9509 9933 9936 9968\n",
"output": "12\n"
},
{
"input": "30\n19 47 109 179 307 331 389 401 461 509 547 569 617 853 883 1249 1361 1381 1511 1723 1741 1783 2459 2531 2621 3533 3821 4091 5557 6217\n20\n401 443 563 941 967 997 1535 1567 1655 1747 1787 1945 1999 2251 2305 2543 2735 4415 6245 7555\n",
"output": "8\n"
},
{
"input": "3\n2 5 7\n3\n4 5 7\n",
"output": "1\n"
},
{
"input": "10\n6 12 13 20 48 53 74 92 96 97\n10\n1 21 32 36 47 54 69 75 95 97\n",
"output": "1\n"
},
{
"input": "4\n3 5 7 11\n4\n3 5 7 22\n",
"output": "1\n"
},
{
"input": "10\n5 9 10 14 15 17 19 22 24 26\n10\n2 11 17 19 21 22 24 25 27 28\n",
"output": "1\n"
},
{
"input": "50\n5 8 13 16 19 20 21 22 24 27 28 29 30 32 33 34 35 43 45 48 50 51 54 55 58 59 60 61 62 65 70 71 72 76 78 79 80 81 83 84 85 87 89 91 92 94 97 98 99 100\n50\n2 3 5 6 7 10 15 16 17 20 23 28 29 30 31 34 36 37 40 42 45 46 48 54 55 56 58 59 61 62 69 70 71 72 75 76 78 82 84 85 86 87 88 89 90 91 92 97 99 100\n",
"output": "1\n"
},
{
"input": "50\n11 17 23 53 59 109 137 149 173 251 353 379 419 421 439 503 593 607 661 773 821 877 941 997 1061 1117 1153 1229 1289 1297 1321 1609 1747 2311 2389 2543 2693 3041 3083 3137 3181 3209 3331 3373 3617 3767 4201 4409 4931 6379\n50\n55 59 67 73 85 89 101 115 211 263 295 353 545 599 607 685 739 745 997 1031 1255 1493 1523 1667 1709 1895 1949 2161 2195 2965 3019 3035 3305 3361 3373 3673 3739 3865 3881 4231 4253 4385 4985 5305 5585 5765 6145 6445 8045 8735\n",
"output": "23\n"
},
{
"input": "2\n2 3\n4\n4 6 21 40\n",
"output": "1\n"
},
{
"input": "3\n3 5 8\n3\n6 8 10\n",
"output": "2\n"
},
{
"input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n1\n14\n",
"output": "1\n"
},
{
"input": "50\n14 19 33 35 38 41 51 54 69 70 71 73 76 80 84 94 102 104 105 106 107 113 121 128 131 168 180 181 187 191 195 201 205 207 210 216 220 238 249 251 263 271 272 275 281 283 285 286 291 294\n50\n2 3 5 20 21 35 38 40 43 48 49 52 55 64 73 77 82 97 109 113 119 121 125 132 137 139 145 146 149 180 182 197 203 229 234 241 244 251 264 271 274 281 284 285 287 291 292 293 294 298\n",
"output": "1\n"
},
{
"input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959\n",
"output": "5\n"
},
{
"input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782\n",
"output": "3\n"
},
{
"input": "4\n2 3 4 5\n3\n1 2 3\n",
"output": "2\n"
},
{
"input": "3\n4 9 10\n3\n8 9 10\n",
"output": "1\n"
},
{
"input": "5\n25 58 91 110 2658\n50\n21 372 909 1172 1517 1554 1797 1802 1843 1977 2006 2025 2137 2225 2317 2507 2645 2754 2919 3024 3202 3212 3267 3852 4374 4487 4553 4668 4883 4911 4916 5016 5021 5068 5104 5162 5683 5856 6374 6871 7333 7531 8099 8135 8173 8215 8462 8776 9433 9790\n",
"output": "4\n"
},
{
"input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428\n",
"output": "4\n"
},
{
"input": "50\n26 367 495 585 675 789 855 1185 1312 1606 2037 2241 2587 2612 2628 2807 2873 2924 3774 4067 4376 4668 4902 5001 5082 5100 5104 5209 5345 5515 5661 5777 5902 5907 6155 6323 6675 6791 7503 8159 8207 8254 8740 8848 8855 8933 9069 9164 9171 9586\n5\n1557 6246 7545 8074 8284\n",
"output": "1\n"
},
{
"input": "50\n51 67 75 186 194 355 512 561 720 876 1077 1221 1503 1820 2153 2385 2568 2608 2937 2969 3271 3311 3481 4081 4093 4171 4255 4256 4829 5020 5192 5636 5817 6156 6712 6717 7153 7436 7608 7612 7866 7988 8264 8293 8867 9311 9879 9882 9889 9908\n1\n5394\n",
"output": "1\n"
},
{
"input": "5\n1 5 6 9 51\n5\n5 12 18 27 10000\n",
"output": "1\n"
},
{
"input": "50\n3 5 6 8 9 11 13 19 21 23 24 32 34 35 42 50 51 52 56 58 59 69 70 72 73 75 76 77 78 80 83 88 90 95 96 100 101 102 108 109 113 119 124 135 138 141 142 143 145 150\n50\n5 8 10 11 18 19 23 30 35 43 51 53 55 58 63 68 69 71 77 78 79 82 83 86 88 89 91 92 93 94 96 102 103 105 109 110 113 114 116 123 124 126 127 132 133 135 136 137 142 149\n",
"output": "1\n"
},
{
"input": "3\n1 2 3\n4\n2 4 6 49\n",
"output": "1\n"
},
{
"input": "4\n3 7 11 13\n4\n51 119 187 221\n",
"output": "4\n"
},
{
"input": "10\n17 239 443 467 661 1069 1823 2333 3767 4201\n20\n51 83 97 457 593 717 997 1329 1401 1459 1471 1983 2371 2539 3207 3251 3329 5469 6637 6999\n",
"output": "8\n"
},
{
"input": "45\n37 48 56 59 69 70 79 83 85 86 99 114 131 134 135 145 156 250 1739 1947 2116 2315 2449 3104 3666 4008 4406 4723 4829 5345 5836 6262 6296 6870 7065 7110 7130 7510 7595 8092 8442 8574 9032 9091 9355\n50\n343 846 893 1110 1651 1837 2162 2331 2596 3012 3024 3131 3294 3394 3528 3717 3997 4125 4347 4410 4581 4977 5030 5070 5119 5229 5355 5413 5418 5474 5763 5940 6151 6161 6164 6237 6506 6519 6783 7182 7413 7534 8069 8253 8442 8505 9135 9308 9828 9902\n",
"output": "17\n"
},
{
"input": "10\n24 53 56 126 354 432 442 740 795 856\n10\n273 438 494 619 689 711 894 947 954 958\n",
"output": "1\n"
},
{
"input": "2\n2 3\n3\n20 30 50\n",
"output": "1\n"
},
{
"input": "10\n1 6 8 14 15 17 25 27 34 39\n10\n1 8 16 17 19 22 32 39 44 50\n",
"output": "1\n"
},
{
"input": "10\n3 4 6 7 8 10 14 16 19 20\n10\n3 4 5 7 8 10 15 16 18 20\n",
"output": "1\n"
},
{
"input": "2\n1 2\n1\n1\n",
"output": "1\n"
},
{
"input": "2\n2 3\n4\n4 6 9 33\n",
"output": "1\n"
},
{
"input": "1\n1\n1\n1\n",
"output": "1\n"
},
{
"input": "50\n6 16 24 25 27 33 36 40 51 60 62 65 71 72 75 77 85 87 91 93 98 102 103 106 117 118 120 121 122 123 125 131 134 136 143 148 155 157 160 161 164 166 170 178 184 187 188 192 194 197\n50\n5 9 17 23 27 34 40 44 47 59 62 70 81 82 87 88 89 90 98 101 102 110 113 114 115 116 119 122 124 128 130 137 138 140 144 150 152 155 159 164 166 169 171 175 185 186 187 189 190 193\n",
"output": "1\n"
},
{
"input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664\n",
"output": "24\n"
},
{
"input": "50\n159 880 1070 1139 1358 1608 1691 1841 2073 2171 2213 2597 2692 2759 2879 2931 3173 3217 3441 4201 4878 5106 5129 5253 5395 5647 5968 6019 6130 6276 6286 6330 6409 6728 7488 7713 7765 7828 7899 8064 8264 8457 8483 8685 8900 8946 8965 9133 9187 9638\n45\n57 159 1070 1139 1391 1608 1691 1841 2171 2213 2692 2759 2931 3173 3217 3441 4201 4878 5106 5129 5253 5647 5968 6130 6276 6286 6409 7488 7694 7713 7765 7828 7899 8003 8064 8081 8244 8264 8685 8900 8946 8965 9133 9638 9673\n",
"output": "38\n"
},
{
"input": "50\n7 144 269 339 395 505 625 688 709 950 1102 1152 1350 1381 1641 1830 1977 1999 2093 2180 2718 3308 3574 4168 4232 4259 4393 4689 4982 5154 5476 5581 5635 5721 6159 6302 6741 7010 7152 7315 7417 7482 8116 8239 8640 9347 9395 9614 9661 9822\n20\n84 162 292 1728 1866 2088 3228 3470 4068 5318 5470 6060 6380 6929 7500 8256 8399 8467 8508 9691\n",
"output": "8\n"
},
{
"input": "30\n3 43 97 179 257 313 353 359 367 389 397 457 547 599 601 647 1013 1021 1063 1433 1481 1531 1669 3181 3373 3559 3769 4157 4549 5197\n50\n13 15 17 19 29 79 113 193 197 199 215 223 271 293 359 485 487 569 601 683 895 919 941 967 1283 1285 1289 1549 1565 1765 1795 1835 1907 1931 1945 1985 1993 2285 2731 2735 2995 3257 4049 4139 5105 5315 7165 7405 7655 8345\n",
"output": "20\n"
},
{
"input": "1\n94\n50\n423 446 485 1214 1468 1507 1853 1930 1999 2258 2271 2285 2425 2543 2715 2743 2992 3196 4074 4108 4448 4475 4652 5057 5250 5312 5356 5375 5731 5986 6298 6501 6521 7146 7255 7276 7332 7481 7998 8141 8413 8665 8908 9221 9336 9491 9504 9677 9693 9706\n",
"output": "1\n"
},
{
"input": "50\n14 22 23 31 32 35 48 63 76 79 88 97 101 102 103 104 106 113 114 115 116 126 136 138 145 152 155 156 162 170 172 173 179 180 182 203 208 210 212 222 226 229 231 232 235 237 245 246 247 248\n50\n2 5 6 16 28 44 45 46 54 55 56 63 72 80 87 93 94 96 97 100 101 103 132 135 140 160 164 165 167 168 173 180 182 185 186 192 194 198 199 202 203 211 213 216 217 227 232 233 236 245\n",
"output": "1\n"
},
{
"input": "4\n2 3 5 8\n4\n2 6 8 10\n",
"output": "1\n"
},
{
"input": "10\n5 21 22 23 25 32 35 36 38 39\n10\n3 7 8 9 18 21 23 24 36 38\n",
"output": "4\n"
}
] | code_contests | python | 0.9 | fa51ba373dbf9aa051f3cd1c3030057b |
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3word1<3word2<3 ... wordn<3.
Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.
Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.
Output
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
Examples
Input
3
i
love
you
<3i<3love<23you<3
Output
yes
Input
7
i
am
not
main
in
the
family
<3i<>3am<3the<3<main<3in<3the<3><3family<3
Output
no
Note
Please note that Dima got a good old kick in the pants for the second sample from the statement.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | def werify_message(words, message):
true_message = ''.join(['<3', '<3'.join(words), '<3'])
# index in true_message
i = 0
for litera in message:
if len(true_message) != i:
if litera == true_message[i]:
i += 1
else:
# Дошли до конца исходного сообщения и не нашли вставок
return 'yes'
if i == len(true_message):
return 'yes'
else:
return 'no'
n = int(input())
words = list()
for i in range(n):
word = input()
words.append(word)
message = input()
print(werify_message(words, message)) | python | code_algorithm | [
{
"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n",
"output": "no\n"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3\n",
"output": "no\n"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3ww\n",
"output": "yes\n"
},
{
"input": "1\na\n<3a<3b\n",
"output": "yes\n"
},
{
"input": "4\na\nb\nc\nd\n<3a<3b<3c<3d\n",
"output": "no\n"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<3you<3\n",
"output": "yes\n"
},
{
"input": "4\na\nb\nc\nd\na<3b<3c<3d<3\n",
"output": "no\n"
},
{
"input": "1\naa\n<3a<3\n",
"output": "no\n"
},
{
"input": "1\na\na\n",
"output": "no\n"
},
{
"input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3\n",
"output": "yes\n"
},
{
"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n",
"output": "no\n"
},
{
"input": "3\ni\nlove\nyou\n<3ilove<23you<3\n",
"output": "no\n"
},
{
"input": "2\na\ni\n<3ai<3\n",
"output": "no\n"
},
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3\n",
"output": "yes\n"
}
] | code_contests | python | 0 | dc0a13c08e03549d7528dc5c7dac97f0 |
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
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
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.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
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.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input(""))
cards=list(map(int,input().split()))
sereja = 0
dima = 0
temp = 0
turn = 1
while cards != []:
nMax=max(cards[0],cards[-1])
if turn==1:
temp = sereja + nMax
sereja+=nMax
turn=2
else:
temp = dima + nMax
dima+=nMax
turn=1
cards.remove(nMax)
print("{} {}".format(sereja, dima)) | python | code_algorithm | [
{
"input": "7\n1 2 3 4 5 6 7\n",
"output": "16 12\n"
},
{
"input": "4\n4 1 2 10\n",
"output": "12 5\n"
},
{
"input": "1\n1\n",
"output": "1 0\n"
},
{
"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\n",
"output": "5246 4864\n"
},
{
"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\n",
"output": "8147 7807\n"
},
{
"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\n",
"output": "613 418\n"
},
{
"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\n",
"output": "644 500\n"
},
{
"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\n",
"output": "315 315\n"
},
{
"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\n",
"output": "9562 9561\n"
},
{
"input": "1\n3\n",
"output": "3 0\n"
},
{
"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\n",
"output": "6848 6568\n"
},
{
"input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304\n",
"output": "3238 2222\n"
}
] | code_contests | python | 0.1 | 49e2a9295e66cbf3dfdf869e8212c770 |
We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".
Given a string, you have to find two values:
1. the number of good substrings of even length;
2. the number of good substrings of odd length.
Input
The first line of the input contains a single string of length n (1 ≤ n ≤ 105). Each character of the string will be either 'a' or 'b'.
Output
Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.
Examples
Input
bb
Output
1 2
Input
baab
Output
2 4
Input
babb
Output
2 5
Input
babaa
Output
2 7
Note
In example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length.
In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.
In example 3, there are seven good substrings (i.e. "b", "a", "b", "b", "bb", "bab", "babb"). Two of them have even length and five of them have odd length.
Definitions
A substring s[l, r] (1 ≤ l ≤ r ≤ n) of string s = s1s2... sn is string slsl + 1... sr.
A string s = s1s2... sn is a palindrome if it is equal to string snsn - 1... s1.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | s = input()
blocks = []
evenA = [0]
oddA = [0]
evenB = [0]
oddB = [0]
even = True
for x in s:
evenA.append(evenA[-1])
oddA.append(oddA[-1])
evenB.append(evenB[-1])
oddB.append(oddB[-1])
if x == 'a':
if even:
evenA[-1] += 1
else:
oddA[-1] += 1
else:
if even:
evenB[-1] += 1
else:
oddB[-1] += 1
even = not even
even = True
totalE = 0
totalO = 0
for x in range(len(s)):
if s[x] == 'a':
if x%2 == 0:
totalE += evenA[-1] - evenA[x]
totalO += oddA[-1] - oddA[x]
else:
totalE += oddA[-1] - oddA[x]
totalO += evenA[-1] - evenA[x]
else:
if x%2 == 0:
totalE += evenB[-1] - evenB[x]
totalO += oddB[-1] - oddB[x]
else:
totalE += oddB[-1] - oddB[x]
totalO += evenB[-1] - evenB[x]
print(totalO,totalE)
| python | code_algorithm | [
{
"input": "babaa\n",
"output": "2 7\n"
},
{
"input": "bb\n",
"output": "1 2\n"
},
{
"input": "baab\n",
"output": "2 4\n"
},
{
"input": "babb\n",
"output": "2 5\n"
},
{
"input": "bbabaaabaaaabaabbababbbabababaabaaaaabbaabbbbbaababaabbbaabaabaaaababaabaabbabaaabaabbbabbaaaaaaabaabababaaabaaabbbabbabbaabaaabaabbbbbabbababbbbbbbababbababbbabbbbbababaaaababaabbabaaabbaaabaabbbbabbaaababbbbbbaaabbaaabbaaabaaaaaababaabababaabaaabaaaabaabbabbabbbbabbaaabaabbaababaaabbbbbaabbbbabbbabaabaaabbbbbbbbabbaaabbabbbabaaabbbabaaaabbbbbbaabbbbabbaabaabbabbbbbbaaabbbabbbaaaaaaabbaabaababbabaabaaaaabaaabbaabaaaaabaababaabababbabbababbbabbbaabbbaabababbbbaabababaaaabbabbaabbbaaba\n",
"output": "29662 30369\n"
},
{
"input": "baabaababaabbaabaaabbbaaaaaabbbabaaaabbbaaaaaaaaabbaabbbaabbaabbaabbababbbbbaaabbaabaaaaabaababbbbababaabaababbbaabbbaabbbbaaaabaabbbaabbbbbabbbabbabaaaabbbabbbaabaaaabbbbabbbababbabaaaabbabababbaaaaaabaabaaaaabbbbabbabbababaaaaabbbbaabaaaaabaaabbaaaaabaabbabbabaaabbaaabbaabbaabaabbbabbaabaabbabaabbbabaaaabbbbbbbbbabaaaaaaabaaaaaabaaabbababbabb\n",
"output": "14924 15322\n"
},
{
"input": "aba\n",
"output": "0 4\n"
},
{
"input": "a\n",
"output": "0 1\n"
},
{
"input": "ab\n",
"output": "0 2\n"
},
{
"input": "baabbbb\n",
"output": "7 11\n"
},
{
"input": "aa\n",
"output": "1 2\n"
},
{
"input": "babbbbbaaabaabbabbabbababbaaba\n",
"output": "102 142\n"
},
{
"input": "ba\n",
"output": "0 2\n"
}
] | code_contests | python | 0.5 | 5f4e83de39e4dfbb8c3b33b743f99c25 |
Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles.
Initially, each mole i (1 ≤ i ≤ 4n) is placed at some position (xi, yi) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compact, if it's possible.
Each mole i has a home placed at the position (ai, bi). Moving this mole one time means rotating his position point (xi, yi) 90 degrees counter-clockwise around it's home point (ai, bi).
A regiment is compact only if the position points of the 4 moles form a square with non-zero area.
Help Captain Marmot to find out for each regiment the minimal number of moves required to make that regiment compact, if it's possible.
Input
The first line contains one integer n (1 ≤ n ≤ 100), the number of regiments.
The next 4n lines contain 4 integers xi, yi, ai, bi ( - 104 ≤ xi, yi, ai, bi ≤ 104).
Output
Print n lines to the standard output. If the regiment i can be made compact, the i-th line should contain one integer, the minimal number of required moves. Otherwise, on the i-th line print "-1" (without quotes).
Examples
Input
4
1 1 0 0
-1 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-2 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-1 1 0 0
-1 1 0 0
-1 1 0 0
2 2 0 1
-1 0 0 -2
3 0 0 -2
-1 1 -2 0
Output
1
-1
3
3
Note
In the first regiment we can move once the second or the third mole.
We can't make the second regiment compact.
In the third regiment, from the last 3 moles we can move once one and twice another one.
In the fourth regiment, we can move twice the first mole and once the third mole.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | #a+b-y
#x+b-a
#1 -
import sys
input=sys.stdin.readline
def distSq(p1,p2):
return (p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1])
def isSquare(p1, p2, p3, p4):
d2 = distSq(p1, p2) # from p1 to p2
d3 = distSq(p1, p3) # from p1 to p3
d4 = distSq(p1, p4) # from p1 to p4
# If lengths if (p1, p2) and (p1, p3) are same, then
# following conditions must be met to form a square.
# 1) Square of length of (p1, p4) is same as twice
# the square of (p1, p2)
# 2) Square of length of (p2, p3) is same
# as twice the square of (p2, p4)
if d2 == d3 and 2 * d2 == d4 and 2 * distSq(p2, p4) == distSq(p2, p3):
return True
# The below two cases are similar to above case
if d3 == d4 and 2 * d3 == d2 and 2 * distSq(p3, p2) == distSq(p3, p4):
return True
if d2 == d4 and 2 * d2 == d3 and 2 * distSq(p2, p3) == distSq(p2, p4):
return True
return False
for _ in range(int(input())):
l=[]
for i in range(4):
x,y,a,b=map(int,input().split())
for j in range(4):
l.append([x,y,j])
x,y=a+b-y,x+b-a
mini=10**9
for i in range(4):
for j in range(4,8):
for k in range(8,12):
for z in range(12,16):
if l[i]==l[j] or l[j]==l[k] or l[i]==l[k] or l[i]==l[z] or l[j]==l[z] or l[k]==l[z]:
continue
if isSquare(l[i],l[j],l[k],l[z]):
# print(l[i],l[j],l[k],l[z])
curr=l[i][2]+l[j][2]+l[k][2]+l[z][2]
#print(curr)
if curr<mini:
mini=curr
print(mini if mini<10**9 else -1) | python | code_algorithm | [
{
"input": "4\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0\n",
"output": "1\n-1\n3\n3\n"
},
{
"input": "1\n1 0 2 0\n-1 0 -2 0\n0 1 0 2\n0 -1 0 -2\n",
"output": "0\n"
},
{
"input": "4\n1 0 0 0\n0 2 0 0\n-1 0 0 0\n0 -2 0 0\n1 0 0 0\n0 1 0 0\n-1 0 0 0\n0 -1 0 0\n1 2 0 0\n-1 2 0 0\n-1 -2 0 0\n1 -2 0 0\n19 0 0 0\n0 20 0 0\n-19 0 0 0\n0 -20 0 0\n",
"output": "-1\n0\n-1\n-1\n"
},
{
"input": "1\n1 1 1 1\n1 1 1 1\n2 2 2 2\n2 2 2 2\n",
"output": "-1\n"
},
{
"input": "1\n-1 1 -9999 9999\n-1 -1 9998 9998\n-1 1 9998 -9998\n-1 -1 -9999 -9999\n",
"output": "8\n"
},
{
"input": "1\n2 1 0 0\n-2 1 0 0\n2 -1 0 0\n-2 -1 0 0\n",
"output": "-1\n"
},
{
"input": "1\n0 0 0 0\n1 0 1 0\n1 1 1 1\n-1 0 -1 0\n",
"output": "-1\n"
},
{
"input": "1\n0 0 0 0\n0 1 0 1\n2 0 2 0\n2 1 2 1\n",
"output": "-1\n"
},
{
"input": "3\n-1 3 0 0\n3 1 0 0\n1 -3 0 0\n-3 -1 0 0\n1 1 0 0\n1 1 0 0\n1 1 0 0\n1 1 0 0\n-4 12 0 0\n-4 12 0 0\n-4 12 0 0\n-4 12 0 0\n",
"output": "0\n6\n6\n"
},
{
"input": "1\n0 1 0 1\n0 -1 0 -1\n1 0 1 0\n-1 0 -1 0\n",
"output": "0\n"
},
{
"input": "1\n1 0 0 0\n0 2 0 0\n-1 0 0 0\n0 -2 0 0\n",
"output": "-1\n"
},
{
"input": "1\n2 0 5 5\n0 1 5 5\n0 -1 5 5\n-2 0 5 5\n",
"output": "-1\n"
},
{
"input": "1\n0 3 0 3\n3 2 3 2\n-1 0 -1 0\n2 -1 2 -1\n",
"output": "0\n"
},
{
"input": "1\n0 0 0 0\n1 1 1 1\n2 0 2 0\n1 -1 1 -1\n",
"output": "0\n"
},
{
"input": "1\n1 0 2 0\n-1 0 -2 0\n0 2 0 3\n0 -2 0 -3\n",
"output": "4\n"
},
{
"input": "1\n0 0 -1 -1\n-3 4 0 0\n2 4 0 0\n5 0 0 0\n",
"output": "-1\n"
},
{
"input": "1\n1 0 0 0\n3 1 0 0\n2 3 0 0\n0 2 0 0\n",
"output": "0\n"
},
{
"input": "1\n0 -1 0 -1\n2 0 2 0\n0 1 0 1\n-2 0 -2 0\n",
"output": "-1\n"
},
{
"input": "3\n-2248 6528 -2144 6181\n-2245 6663 -2100 7054\n-4378 7068 -4061 7516\n-4274 6026 -3918 5721\n4942 -6793 5014 -6807\n3463 -5170 3112 -5181\n2870 -6992 3038 -6567\n5688 -4318 5358 -4744\n5249 7233 5016 6863\n4312 7385 4162 7383\n5965 9138 5607 8728\n4053 8349 4124 8389\n",
"output": "8\n6\n6\n"
},
{
"input": "5\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0\n0 1 0 0\n1 0 0 0\n-1 0 0 0\n0 -1 0 0\n",
"output": "1\n-1\n3\n3\n0\n"
},
{
"input": "2\n1 0 0 0\n0 2 0 0\n-1 0 0 0\n0 -2 0 0\n1 0 0 0\n0 1 0 0\n-1 0 0 0\n0 -1 0 0\n",
"output": "-1\n0\n"
},
{
"input": "3\n1 0 0 0\n0 2 0 0\n-1 0 0 0\n0 -2 0 0\n1 0 0 0\n0 1 0 0\n-1 0 0 0\n0 -1 0 0\n1 2 0 0\n-1 2 0 0\n-1 -2 0 0\n1 -2 0 0\n",
"output": "-1\n0\n-1\n"
},
{
"input": "1\n-1 1 -9999 9999\n3 3 10000 10000\n3 -3 10000 -10000\n-1 -1 -9999 -9999\n",
"output": "8\n"
}
] | code_contests | python | 0 | 9e0bb7f56c38321e479755646c97b805 |
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no two pluses in such a partition can stand together (between any two adjacent pluses there must be at least one digit), and no plus can stand at the beginning or the end of a line. For example, in the string 100500, ways 100500 (add no pluses), 1+00+500 or 10050+0 are correct, and ways 100++500, +1+0+0+5+0+0 or 100500+ are incorrect.
The lesson was long, and Vasya has written all the correct ways to place exactly k pluses in a string of digits. At this point, he got caught having fun by a teacher and he was given the task to calculate the sum of all the resulting arithmetic expressions by the end of the lesson (when calculating the value of an expression the leading zeros should be ignored). As the answer can be large, Vasya is allowed to get only its remainder modulo 109 + 7. Help him!
Input
The first line contains two integers, n and k (0 ≤ k < n ≤ 105).
The second line contains a string consisting of n digits.
Output
Print the answer to the problem modulo 109 + 7.
Examples
Input
3 1
108
Output
27
Input
3 2
108
Output
9
Note
In the first sample the result equals (1 + 08) + (10 + 8) = 27.
In the second sample the result equals 1 + 0 + 8 = 9.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, k = map(int, input().split())
t = list(map(int, input()))
p, d = 1, 10 ** 9 + 7
s, f = 0, [1] * n
for i in range(2, n): f[i] = (i * f[i - 1]) % d
c = lambda a, b: 0 if a > b else (f[b] * pow(f[a] * f[b - a], d - 2, d)) % d
if k:
u = [0] * (n + 1)
p = [1] * (n + 1)
for i in range(n):
u[i] = (p[i] * c(k - 1, n - 2 - i) + u[i - 1]) % d
p[i + 1] = (10 * p[i]) % d
for i in range(n):
v = u[n - 2 - i] + p[n - 1 - i] * c(k, i)
s = (s + t[i] * v) % d
else:
for i in t: s = (s * 10 + i) % d
print(s)
# Made By Mostafa_Khaled | python | code_algorithm | [
{
"input": "3 1\n108\n",
"output": "27\n"
},
{
"input": "3 2\n108\n",
"output": "9\n"
},
{
"input": "57 13\n177946005798852216692528643323484389368821547834013121843\n",
"output": "734611754\n"
},
{
"input": "16 15\n8086179429588546\n",
"output": "90\n"
},
{
"input": "14 6\n00000000000001\n",
"output": "1716\n"
},
{
"input": "200 100\n56988719755815575893282254081467698462485803782142631369385180999746639622554559884281193367342283559238834106917388166048020056852911293394377949964185368886333934084399980368238188117302968424219707\n",
"output": "295455656\n"
},
{
"input": "5 2\n39923\n",
"output": "2667\n"
},
{
"input": "69 42\n702219529742805879674066565317944328886138640496101944672203835664744\n",
"output": "94769311\n"
},
{
"input": "132 104\n558881515858815818855111851188551181818185155585188885588555158518555118155511851558151188115518858811551515158155181855155181588185\n",
"output": "999404541\n"
},
{
"input": "1 0\n5\n",
"output": "5\n"
},
{
"input": "20 19\n33137197659033083606\n",
"output": "83\n"
},
{
"input": "169 79\n4127820680853085792029730656808609037371898882875765629277699584259523684674321307751545375311931127593565910629995605232615333335597916968134403869036676265945118713450\n",
"output": "750991187\n"
},
{
"input": "18 15\n703140050361297985\n",
"output": "24010\n"
},
{
"input": "100 10\n9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n",
"output": "993802401\n"
},
{
"input": "7 1\n2178766\n",
"output": "509217\n"
},
{
"input": "100 50\n0009909900909009999909009909900090000990999909009909099990099990909000999009009000090099009009009900\n",
"output": "32857902\n"
},
{
"input": "20 9\n34540451546587567970\n",
"output": "64877692\n"
},
{
"input": "10 0\n3448688665\n",
"output": "448688644\n"
},
{
"input": "89 29\n77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\n",
"output": "206099915\n"
},
{
"input": "200 99\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n",
"output": "988919917\n"
},
{
"input": "6 3\n967181\n",
"output": "3506\n"
},
{
"input": "20 8\n99999999999999999999\n",
"output": "514450773\n"
}
] | code_contests | python | 0 | 90cb0c549f1651d0f653e7c1d8dbd4d5 |
A super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1 × 1 × 1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer number from 1 to n, the line number from 1 to m and the column number from 1 to k.
In the process of the Super Computer's work the CPUs can send each other messages by the famous turtle scheme: CPU (x, y, z) can send messages to CPUs (x + 1, y, z), (x, y + 1, z) and (x, y, z + 1) (of course, if they exist), there is no feedback, that is, CPUs (x + 1, y, z), (x, y + 1, z) and (x, y, z + 1) cannot send messages to CPU (x, y, z).
Over time some CPUs broke down and stopped working. Such CPUs cannot send messages, receive messages or serve as intermediates in transmitting messages. We will say that CPU (a, b, c) controls CPU (d, e, f) , if there is a chain of CPUs (xi, yi, zi), such that (x1 = a, y1 = b, z1 = c), (xp = d, yp = e, zp = f) (here and below p is the length of the chain) and the CPU in the chain with number i (i < p) can send messages to CPU i + 1.
Turtles are quite concerned about the denial-proofness of the system of communication between the remaining CPUs. For that they want to know the number of critical CPUs. A CPU (x, y, z) is critical, if turning it off will disrupt some control, that is, if there are two distinctive from (x, y, z) CPUs: (a, b, c) and (d, e, f), such that (a, b, c) controls (d, e, f) before (x, y, z) is turned off and stopped controlling it after the turning off.
Input
The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 100) — the dimensions of the Super Computer.
Then n blocks follow, describing the current state of the processes. The blocks correspond to the layers of the Super Computer in the order from 1 to n. Each block consists of m lines, k characters in each — the description of a layer in the format of an m × k table. Thus, the state of the CPU (x, y, z) is corresponded to the z-th character of the y-th line of the block number x. Character "1" corresponds to a working CPU and character "0" corresponds to a malfunctioning one. The blocks are separated by exactly one empty line.
Output
Print a single integer — the number of critical CPUs, that is, such that turning only this CPU off will disrupt some control.
Examples
Input
2 2 3
000
000
111
111
Output
2
Input
3 3 3
111
111
111
111
111
111
111
111
111
Output
19
Input
1 1 10
0101010101
Output
0
Note
In the first sample the whole first layer of CPUs is malfunctional. In the second layer when CPU (2, 1, 2) turns off, it disrupts the control by CPU (2, 1, 3) over CPU (2, 1, 1), and when CPU (2, 2, 2) is turned off, it disrupts the control over CPU (2, 2, 3) by CPU (2, 2, 1).
In the second sample all processors except for the corner ones are critical.
In the third sample there is not a single processor controlling another processor, so the answer is 0.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | def main():
s = input().split()
n, m, k = int(s[0]), int(s[1]), int(s[2])
processor = []
for x in range(n):
for y in range(m):
s = input()
for z in s:
processor.append(int(z) == 1)
if x < n - 1:
emptyLine = input()
counter = 0
mk = m * k
nmk = n * mk
for i in range(nmk):
if not processor[i]:
continue
# back
if i >= mk:
if processor[i - mk]:
# front
if i < (nmk - mk):
if processor[i + mk]:
counter += 1
continue
# right
if (i % k) < (k - 1):
if processor[i + 1]:
if not processor[i - mk + 1]:
counter += 1
continue
# down
if (i % mk) < (mk - k):
if processor[i + k]:
if not processor[i - mk + k]:
counter += 1
continue
# left
if (i % k) > 0:
if processor[i - 1]:
# front
if i < (nmk - mk):
if processor[i + mk]:
if not processor[i + mk - 1]:
counter += 1
continue
# right
if (i % k) < (k - 1):
if processor[i + 1]:
counter += 1
continue
# down
if (i % mk) < (mk - k):
if processor[i + k]:
if not processor[i + k - 1]:
counter += 1
continue
# up
if (i % mk) >= k:
if processor[i - k]:
# front
if i < (nmk - mk):
if processor[i + mk]:
if not processor[i + mk - k]:
counter += 1
continue
# right
if (i % k) < (k - 1):
if processor[i + 1]:
if not processor[i - k + 1]:
counter += 1
continue
# down
if (i % mk) < (mk - k):
if processor[i + k]:
counter += 1
continue
print(counter)
main()
| python | code_algorithm | [
{
"input": "1 1 10\n0101010101\n",
"output": "0\n"
},
{
"input": "2 2 3\n000\n000\n\n111\n111\n",
"output": "2\n"
},
{
"input": "3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111\n",
"output": "19\n"
},
{
"input": "1 1 3\n111\n",
"output": "1\n"
},
{
"input": "1 3 1\n1\n1\n1\n",
"output": "1\n"
},
{
"input": "3 1 1\n1\n\n1\n\n1\n",
"output": "1\n"
},
{
"input": "3 1 1\n1\n\n0\n\n1\n",
"output": "0\n"
},
{
"input": "1 1 3\n011\n",
"output": "0\n"
},
{
"input": "1 3 1\n1\n0\n1\n",
"output": "0\n"
},
{
"input": "6 8 3\n011\n001\n000\n100\n111\n110\n100\n100\n\n000\n100\n011\n001\n011\n000\n100\n111\n\n110\n111\n011\n110\n101\n001\n110\n000\n\n100\n000\n110\n001\n110\n010\n110\n011\n\n101\n111\n010\n110\n101\n111\n011\n110\n\n100\n111\n111\n011\n101\n110\n110\n110\n",
"output": "46\n"
},
{
"input": "1 1 100\n0000011111011101001100111010100111000100010100010110111110110011000000111111011111001111000011111010\n",
"output": "21\n"
},
{
"input": "1 1 1\n1\n",
"output": "0\n"
},
{
"input": "100 1 1\n0\n\n1\n\n1\n\n1\n\n0\n\n0\n\n0\n\n1\n\n1\n\n0\n\n0\n\n1\n\n0\n\n1\n\n1\n\n1\n\n1\n\n0\n\n0\n\n1\n\n1\n\n1\n\n0\n\n0\n\n0\n\n0\n\n0\n\n1\n\n1\n\n0\n\n1\n\n1\n\n1\n\n0\n\n1\n\n0\n\n0\n\n1\n\n0\n\n1\n\n1\n\n0\n\n0\n\n0\n\n0\n\n1\n\n0\n\n1\n\n0\n\n0\n\n1\n\n1\n\n1\n\n0\n\n1\n\n1\n\n0\n\n1\n\n1\n\n1\n\n0\n\n0\n\n0\n\n1\n\n0\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n0\n\n0\n\n1\n\n0\n\n0\n\n0\n\n0\n\n0\n\n1\n\n0\n\n1\n\n1\n\n0\n\n0\n\n0\n\n0\n\n0\n\n1\n\n1\n\n1\n\n1\n\n1\n\n0\n\n1\n\n1\n\n1\n\n1\n\n1\n\n0\n",
"output": "17\n"
},
{
"input": "1 1 100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
"output": "0\n"
},
{
"input": "1 1 3\n110\n",
"output": "0\n"
},
{
"input": "1 100 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n",
"output": "98\n"
},
{
"input": "100 1 1\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n",
"output": "98\n"
},
{
"input": "1 1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n",
"output": "98\n"
},
{
"input": "1 100 1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n0\n0\n0\n1\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n0\n0\n0\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n0\n0\n",
"output": "10\n"
},
{
"input": "1 1 1\n0\n",
"output": "0\n"
},
{
"input": "1 100 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n",
"output": "0\n"
},
{
"input": "100 1 1\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n",
"output": "0\n"
},
{
"input": "1 1 3\n101\n",
"output": "0\n"
}
] | code_contests | python | 0 | d222b94868f2974fc737679b9fbb1c8d |
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.
They will be N guests tonight: N - 1 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to N - 1, and Heidi, who still appears slightly different from the others, is attributed the highest rank, N. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure:
The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes – in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.)
You should know that zombies are very greedy and sly, and they know this too – basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order:
1. survive the event (they experienced death already once and know it is no fun),
2. get as many brains as possible.
Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself.
What is the smallest number of brains that have to be in the chest for this to be possible?
Input
The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home.
Examples
Input
1
Output
1
Input
4
Output
2
Note
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
print(n // 2 + n % 2) | python | code_algorithm | [
{
"input": "1\n",
"output": "1\n"
},
{
"input": "4\n",
"output": "2\n"
},
{
"input": "1000000000\n",
"output": "500000000\n"
},
{
"input": "536870912\n",
"output": "268435456\n"
},
{
"input": "16\n",
"output": "8\n"
},
{
"input": "6\n",
"output": "3\n"
},
{
"input": "18\n",
"output": "9\n"
},
{
"input": "13\n",
"output": "7\n"
},
{
"input": "20\n",
"output": "10\n"
},
{
"input": "7\n",
"output": "4\n"
},
{
"input": "10\n",
"output": "5\n"
},
{
"input": "8\n",
"output": "4\n"
},
{
"input": "2\n",
"output": "1\n"
},
{
"input": "21736\n",
"output": "10868\n"
},
{
"input": "12\n",
"output": "6\n"
},
{
"input": "9\n",
"output": "5\n"
},
{
"input": "9999\n",
"output": "5000\n"
},
{
"input": "873467\n",
"output": "436734\n"
},
{
"input": "536870910\n",
"output": "268435455\n"
},
{
"input": "17\n",
"output": "9\n"
},
{
"input": "4124980\n",
"output": "2062490\n"
},
{
"input": "15\n",
"output": "8\n"
},
{
"input": "5\n",
"output": "3\n"
},
{
"input": "876543210\n",
"output": "438271605\n"
},
{
"input": "987654321\n",
"output": "493827161\n"
},
{
"input": "3\n",
"output": "2\n"
},
{
"input": "14\n",
"output": "7\n"
},
{
"input": "100\n",
"output": "50\n"
},
{
"input": "19\n",
"output": "10\n"
},
{
"input": "11\n",
"output": "6\n"
}
] | code_contests | python | 0.7 | f9908f6609c1243354bd9f489510d444 |
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.
Soon, monsters became hungry and began to eat each other.
One monster can eat other monster if its weight is strictly greater than the weight of the monster being eaten, and they stand in the queue next to each other. Monsters eat each other instantly. There are no monsters which are being eaten at the same moment. After the monster A eats the monster B, the weight of the monster A increases by the weight of the eaten monster B. In result of such eating the length of the queue decreases by one, all monsters after the eaten one step forward so that there is no empty places in the queue again. A monster can eat several monsters one after another. Initially there were n monsters in the queue, the i-th of which had weight ai.
For example, if weights are [1, 2, 2, 2, 1, 2] (in order of queue, monsters are numbered from 1 to 6 from left to right) then some of the options are:
1. the first monster can't eat the second monster because a1 = 1 is not greater than a2 = 2;
2. the second monster can't eat the third monster because a2 = 2 is not greater than a3 = 2;
3. the second monster can't eat the fifth monster because they are not neighbors;
4. the second monster can eat the first monster, the queue will be transformed to [3, 2, 2, 1, 2].
After some time, someone said a good joke and all monsters recovered. At that moment there were k (k ≤ n) monsters in the queue, the j-th of which had weight bj. Both sequences (a and b) contain the weights of the monsters in the order from the first to the last.
You are required to provide one of the possible orders of eating monsters which led to the current queue, or to determine that this could not happen. Assume that the doctor didn't make any appointments while monsters were eating each other.
Input
The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters.
The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke.
The fourth line contains k integers b1, b2, ..., bk (1 ≤ bj ≤ 5·108) — the weights of the monsters after the joke.
Monsters are listed in the order from the beginning of the queue to the end.
Output
In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line.
Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, separated by space, the symbol 'L' if the monster which stays the x-th in the queue eats the monster in front of him, or 'R' if the monster which stays the x-th in the queue eats the monster behind him. After each eating the queue is enumerated again.
When one monster eats another the queue decreases. If there are several answers, print any of them.
Examples
Input
6
1 2 2 2 1 2
2
5 5
Output
YES
2 L
1 R
4 L
3 L
Input
5
1 2 3 4 5
1
15
Output
YES
5 L
4 L
3 L
2 L
Input
5
1 1 1 3 3
3
2 1 6
Output
NO
Note
In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue:
* the second monster eats the monster to the left (i.e. the first monster), queue becomes [3, 2, 2, 1, 2];
* the first monster (note, it was the second on the previous step) eats the monster to the right (i.e. the second monster), queue becomes [5, 2, 1, 2];
* the fourth monster eats the mosnter to the left (i.e. the third monster), queue becomes [5, 2, 3];
* the finally, the third monster eats the monster to the left (i.e. the second monster), queue becomes [5, 5].
Note that for each step the output contains numbers of the monsters in their current order in the queue.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | def main():
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
sum1, sum2 = 0, 0
for i in a:
sum1 += i
for i in b:
sum2 += i
# validar que podemos obtener solucion
if sum1 != sum2:
print('NO')
return
# guardar instrucciones
instructions = []
index = 0
for i in range(m):
# valor a conseguir
t = b[i]
p1 = index
p2 = index
while t > 0:
t -= a[index]
if a[p2] < a[index]:
p2 = index
index += 1
if t < 0:
print('NO')
return
if p2 == p1:
while p2 + 1 < index and a[p2] == a[p2 + 1]:
p2 = p2 + 1
flag = 0
if p2 - 1 >= p1 and a[p2] > a[p2 - 1]:
flag = 1
elif p2 + 1 < index and a[p2] > a[p2 + 1]:
flag = 2
elif index - p1 == 1:
continue
if flag == 0:
print('NO')
return
elif flag == 1:
for x in range(p2, p1, -1):
instructions.append('{0} L'.format(x - p1 + i + 1))
for x in range(p2, index - 1):
instructions.append('{0} R'.format(i + 1))
elif flag == 2:
for x in range(p2, index - 1):
instructions.append('{0} R'.format(p2 - p1 + i + 1))
for x in range(p2, p1, -1):
instructions.append('{0} L'.format(x - p1 + i + 1))
print('YES')
for x in instructions:
print(x)
main() | python | code_algorithm | [
{
"input": "5\n1 1 1 3 3\n3\n2 1 6\n",
"output": "NO\n"
},
{
"input": "6\n1 2 2 2 1 2\n2\n5 5\n",
"output": "YES\n2 L\n1 R\n2 R\n2 R\n"
},
{
"input": "5\n1 2 3 4 5\n1\n15\n",
"output": "YES\n5 L\n4 L\n3 L\n2 L\n"
},
{
"input": "3\n2 1 3\n1\n6\n",
"output": "YES\n3 L\n2 L\n"
},
{
"input": "3\n3 2 1\n1\n6\n",
"output": "YES\n1 R\n1 R\n"
},
{
"input": "3\n1 2 2\n1\n5\n",
"output": "YES\n2 L\n1 R\n"
},
{
"input": "2\n1 1\n1\n1\n",
"output": "NO\n"
},
{
"input": "5\n1 2 3 4 5\n3\n1 2 3\n",
"output": "NO\n"
},
{
"input": "5\n3 3 2 2 1\n2\n8 3\n",
"output": "YES\n2 R\n2 L\n2 R\n"
},
{
"input": "3\n3 2 5\n1\n10\n",
"output": "YES\n3 L\n2 L\n"
},
{
"input": "6\n2 1 2 2 1 2\n2\n5 5\n",
"output": "YES\n1 R\n1 R\n2 R\n2 R\n"
},
{
"input": "2\n5 5\n1\n5\n",
"output": "NO\n"
},
{
"input": "14\n5 5 5 5 4 4 4 3 3 3 4 4 4 4\n3\n32 21 4\n",
"output": "YES\n4 R\n4 R\n4 R\n4 L\n3 L\n2 L\n5 L\n4 L\n3 L\n2 R\n2 R\n"
},
{
"input": "4\n2 2 1 2\n1\n7\n",
"output": "YES\n2 R\n2 R\n2 L\n"
},
{
"input": "8\n2 5 3 1 4 2 3 4\n3\n10 6 8\n",
"output": "NO\n"
},
{
"input": "3\n2 1 3\n1\n3\n",
"output": "NO\n"
},
{
"input": "5\n1 2 3 4 5\n1\n10\n",
"output": "NO\n"
},
{
"input": "22\n3 2 3 3 3 1 1 2 1 2 1 1 1 2 2 3 1 2 3 3 3 3\n5\n5 16 5 5 15\n",
"output": "YES\n1 R\n4 R\n4 R\n4 R\n4 R\n4 R\n4 L\n3 L\n6 L\n5 L\n4 L\n5 L\n7 L\n6 L\n5 R\n5 R\n5 R\n"
},
{
"input": "3\n1 5 1\n1\n6\n",
"output": "NO\n"
},
{
"input": "2\n1 2\n1\n1\n",
"output": "NO\n"
},
{
"input": "5\n3 3 2 3 1\n2\n11 1\n",
"output": "YES\n2 R\n2 R\n2 L\n"
},
{
"input": "2\n5 3\n1\n5\n",
"output": "NO\n"
},
{
"input": "7\n2 2 2 1 2 2 2\n1\n13\n",
"output": "YES\n3 R\n3 R\n3 R\n3 R\n3 L\n2 L\n"
},
{
"input": "4\n3 2 1 4\n3\n3 2 1\n",
"output": "NO\n"
},
{
"input": "23\n3 2 1 3 3 3 1 1 2 1 2 1 1 1 2 2 3 1 2 3 3 3 3\n5\n6 16 5 5 15\n",
"output": "YES\n1 R\n1 R\n4 R\n4 R\n4 R\n4 R\n4 R\n4 L\n3 L\n6 L\n5 L\n4 L\n5 L\n7 L\n6 L\n5 R\n5 R\n5 R\n"
},
{
"input": "1\n959139\n1\n470888\n",
"output": "NO\n"
},
{
"input": "3\n5 5 4\n1\n14\n",
"output": "YES\n2 R\n2 L\n"
},
{
"input": "4\n1 2 3 4\n2\n1 2\n",
"output": "NO\n"
},
{
"input": "10\n30518 196518 274071 359971 550121 204862 843967 173607 619138 690754\n3\n171337 183499 549873\n",
"output": "NO\n"
},
{
"input": "3\n5 2 3\n1\n10\n",
"output": "YES\n1 R\n1 R\n"
},
{
"input": "3\n1 2 3\n2\n1 2\n",
"output": "NO\n"
},
{
"input": "5\n325539 329221 106895 882089 718673\n5\n699009 489855 430685 939232 282330\n",
"output": "NO\n"
},
{
"input": "3\n2 1 1\n1\n3\n",
"output": "NO\n"
},
{
"input": "3\n2 3 5\n1\n10\n",
"output": "YES\n3 L\n2 L\n"
},
{
"input": "4\n2 2 2 1\n3\n2 2 2\n",
"output": "NO\n"
},
{
"input": "4\n4 3 2 1\n3\n3 2 1\n",
"output": "NO\n"
},
{
"input": "8\n2 2 1 2 2 1 2 4\n2\n9 8\n",
"output": "NO\n"
},
{
"input": "5\n1 1 1 1 1\n4\n1 1 1 1\n",
"output": "NO\n"
},
{
"input": "8\n1 2 2 2 1 2 1 1\n2\n5 5\n",
"output": "NO\n"
},
{
"input": "5\n2 2 1 2 2\n1\n9\n",
"output": "YES\n2 R\n2 R\n2 R\n2 L\n"
},
{
"input": "16\n2 2 2 1 2 2 2 1 1 2 2 2 1 2 2 2\n4\n7 7 7 7\n",
"output": "YES\n3 R\n3 L\n2 L\n4 R\n4 L\n3 L\n4 L\n3 R\n3 R\n5 L\n4 R\n4 R\n"
},
{
"input": "3\n1 2 3\n1\n3\n",
"output": "NO\n"
},
{
"input": "3\n2 2 1\n1\n5\n",
"output": "YES\n2 R\n2 L\n"
},
{
"input": "5\n1 2 3 4 5\n2\n3 7\n",
"output": "NO\n"
},
{
"input": "5\n1 1 1 1 2\n3\n1 1 4\n",
"output": "YES\n5 L\n4 L\n"
},
{
"input": "5\n1 1 1 1 1\n4\n1 1 2 1\n",
"output": "NO\n"
},
{
"input": "3\n1 2 1\n2\n3 2\n",
"output": "NO\n"
},
{
"input": "1\n2\n1\n2\n",
"output": "YES\n"
},
{
"input": "4\n2 3 3 2\n2\n5 3\n",
"output": "NO\n"
},
{
"input": "3\n3 3 2\n1\n8\n",
"output": "YES\n2 R\n2 L\n"
},
{
"input": "4\n1 2 3 4\n3\n1 2 3\n",
"output": "NO\n"
},
{
"input": "2\n1 2\n2\n3 1\n",
"output": "NO\n"
}
] | code_contests | python | 0 | 19aec0c197f874ec691c45d0679623dc |
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5.
The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.
To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups.
Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.
Input
The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups.
The second line contains sequence of integer numbers a1, a2, ..., an (1 ≤ ai ≤ 5), where ai is academic performance of the i-th student of the group A.
The third line contains sequence of integer numbers b1, b2, ..., bn (1 ≤ bi ≤ 5), where bi is academic performance of the i-th student of the group B.
Output
Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.
Examples
Input
4
5 4 4 4
5 5 4 5
Output
1
Input
6
1 1 1 1 1 1
5 5 5 5 5 5
Output
3
Input
1
5
3
Output
-1
Input
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1
Output
4
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
linea = list(map(int, input().split()))
lineb = list(map(int, input().split()))
lines = linea + lineb
c1 = lines.count(1)
c2 = lines.count(2)
c3 = lines.count(3)
c4 = lines.count(4)
c5 = lines.count(5)
cc1 = linea.count(1)
cc2 = linea.count(2)
cc3 = linea.count(3)
cc4 = linea.count(4)
cc5 = linea.count(5)
if (c1 % 2 == 1 or c2 % 2 == 1 or c3 % 2 == 1 or c4 % 2 == 1 or c5 % 2 == 1):
print(-1)
else:
print(int(abs(c1 / 2 - cc1) + abs(c2 / 2 - cc2) + abs(c3 / 2 - cc3) + abs(c4 / 2 - cc4) + abs(c5 / 2 - cc5)) // 2) | python | code_algorithm | [
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"output": "3\n"
},
{
"input": "4\n5 4 4 4\n5 5 4 5\n",
"output": "1\n"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n",
"output": "4\n"
},
{
"input": "1\n5\n3\n",
"output": "-1\n"
},
{
"input": "100\n3 4 5 3 5 4 5 4 4 4 2 4 5 4 3 2 3 4 3 5 2 5 2 5 4 3 4 2 5 2 5 3 4 5 2 5 4 2 4 5 4 3 2 4 4 5 2 5 5 3 3 5 2 4 4 2 3 3 2 5 5 5 2 4 5 5 4 2 2 5 3 3 2 4 4 2 4 5 5 2 5 5 3 2 5 2 4 4 3 3 5 4 5 5 2 5 4 5 4 3\n4 3 5 5 2 4 2 4 5 5 5 2 3 3 3 3 5 5 5 5 3 5 2 3 5 2 3 2 2 5 5 3 5 3 4 2 2 5 3 3 3 3 5 2 4 5 3 5 3 4 4 4 5 5 3 4 4 2 2 4 4 5 3 2 4 5 5 4 5 2 2 3 5 4 5 5 2 5 4 3 2 3 2 5 4 5 3 4 5 5 3 5 2 2 4 4 3 2 5 2\n",
"output": "4\n"
},
{
"input": "6\n1 1 2 2 3 4\n1 2 3 3 4 4\n",
"output": "-1\n"
},
{
"input": "5\n5 5 5 5 5\n5 5 5 5 5\n",
"output": "0\n"
},
{
"input": "2\n1 1\n1 1\n",
"output": "0\n"
},
{
"input": "2\n1 3\n2 2\n",
"output": "-1\n"
},
{
"input": "10\n4 4 4 4 2 3 3 3 3 1\n2 2 2 2 4 1 1 1 1 3\n",
"output": "-1\n"
},
{
"input": "5\n4 4 1 4 2\n1 2 4 2 2\n",
"output": "1\n"
},
{
"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\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\n",
"output": "0\n"
},
{
"input": "5\n1 2 2 2 2\n1 1 1 1 3\n",
"output": "-1\n"
},
{
"input": "50\n1 1 1 4 1 1 4 1 4 1 1 4 1 1 4 1 1 4 1 1 4 1 4 4 4 1 1 4 1 4 4 4 4 4 4 4 1 4 1 1 1 1 4 1 4 4 1 1 1 4\n1 4 4 1 1 4 1 4 4 1 1 4 1 4 1 1 4 1 1 1 4 4 1 1 4 1 4 1 1 4 4 4 4 1 1 4 4 1 1 1 4 1 4 1 4 1 1 1 4 4\n",
"output": "0\n"
},
{
"input": "100\n2 4 5 2 1 5 5 2 1 5 1 5 1 1 1 3 4 5 1 1 2 3 3 1 5 5 4 4 4 1 1 1 5 2 3 5 1 2 2 1 1 1 2 2 1 2 4 4 5 1 3 2 5 3 5 5 3 2 2 2 1 3 4 4 4 4 4 5 3 1 4 1 5 4 4 5 4 5 2 4 4 3 1 2 1 4 5 3 3 3 3 2 2 2 3 5 3 1 3 4\n3 2 5 1 5 4 4 3 5 5 5 2 1 4 4 3 2 3 3 5 5 4 5 5 2 1 2 4 4 3 5 1 1 5 1 3 2 5 2 4 4 2 4 2 4 2 3 2 5 1 4 4 1 1 1 5 3 5 1 1 4 5 1 1 2 2 5 3 5 1 1 1 2 3 3 2 3 2 4 4 5 4 2 1 3 4 1 1 2 4 1 5 3 1 2 1 3 4 1 3\n",
"output": "0\n"
},
{
"input": "100\n3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5\n2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4\n",
"output": "50\n"
},
{
"input": "5\n3 3 3 3 1\n1 1 1 1 3\n",
"output": "-1\n"
},
{
"input": "100\n3 3 2 2 1 2 3 3 2 2 1 1 3 3 1 1 1 2 1 2 3 2 3 3 3 1 2 3 1 2 1 2 3 3 2 1 1 1 1 1 2 2 3 2 1 1 3 3 1 3 3 1 3 1 3 3 3 2 1 2 3 1 3 2 2 2 2 2 2 3 1 3 1 2 2 1 2 3 2 3 3 1 2 1 1 3 1 1 1 2 1 2 2 2 3 2 3 2 1 1\n1 3 1 2 1 1 1 1 1 2 1 2 1 3 2 2 3 2 1 1 2 2 2 1 1 3 2 3 2 1 2 2 3 2 3 1 3 1 1 2 3 1 2 1 3 2 1 2 3 2 3 3 3 2 2 2 3 1 3 1 1 2 1 3 1 3 1 3 3 3 1 3 3 2 1 3 3 3 3 3 2 1 2 2 3 3 2 1 2 2 1 3 3 1 3 2 2 1 1 3\n",
"output": "1\n"
},
{
"input": "50\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\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\n",
"output": "0\n"
},
{
"input": "2\n1 2\n2 1\n",
"output": "0\n"
},
{
"input": "1\n1\n1\n",
"output": "0\n"
},
{
"input": "50\n3 5 1 3 3 4 3 4 2 5 2 1 2 2 5 5 4 5 4 2 1 3 4 2 3 3 3 2 4 3 5 5 5 5 5 5 2 5 2 2 5 4 4 1 5 3 4 2 1 3\n3 5 3 2 5 3 4 4 5 2 3 4 4 4 2 2 4 4 4 3 3 5 5 4 3 1 4 4 5 5 4 1 2 5 5 4 1 2 3 4 5 5 3 2 3 4 3 5 1 1\n",
"output": "3\n"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n",
"output": "0\n"
},
{
"input": "100\n4 2 5 2 5 4 2 5 5 4 4 2 4 4 2 4 4 5 2 5 5 2 2 4 4 5 4 5 5 5 2 2 2 2 4 4 5 2 4 4 4 2 2 5 5 4 5 4 4 2 4 5 4 2 4 5 4 2 4 5 4 4 4 4 4 5 4 2 5 2 5 5 5 5 4 2 5 5 4 4 2 5 2 5 2 5 4 2 4 2 4 5 2 5 2 4 2 4 2 4\n5 4 5 4 5 2 2 4 5 2 5 5 5 5 5 4 4 4 4 5 4 5 5 2 4 4 4 4 5 2 4 4 5 5 2 5 2 5 5 4 4 5 2 5 2 5 2 5 4 5 2 5 2 5 2 4 4 5 4 2 5 5 4 2 2 2 5 4 2 2 4 4 4 5 5 2 5 2 2 4 4 4 2 5 4 5 2 2 5 4 4 5 5 4 5 5 4 5 2 5\n",
"output": "5\n"
},
{
"input": "5\n2 3 2 3 3\n2 3 2 2 2\n",
"output": "1\n"
},
{
"input": "4\n1 2 3 3\n3 3 3 3\n",
"output": "-1\n"
},
{
"input": "2\n1 1\n2 3\n",
"output": "-1\n"
},
{
"input": "4\n1 1 1 2\n3 3 3 3\n",
"output": "-1\n"
},
{
"input": "5\n5 5 5 3 5\n5 3 5 5 5\n",
"output": "0\n"
},
{
"input": "100\n5 3 3 2 5 3 2 4 2 3 3 5 3 4 5 4 3 3 4 3 2 3 3 4 5 4 2 4 2 4 5 3 3 4 5 3 5 3 5 3 3 2 5 3 4 5 2 5 2 2 4 2 2 2 2 5 4 5 4 3 5 4 2 5 5 3 4 5 2 3 2 2 2 5 3 2 2 2 3 3 5 2 3 2 4 5 3 3 3 5 2 3 3 3 5 4 5 5 5 2\n4 4 4 5 5 3 5 5 4 3 5 4 3 4 3 3 5 3 5 5 3 3 3 5 5 4 4 3 2 5 4 3 3 4 5 3 5 2 4 2 2 2 5 3 5 2 5 5 3 3 2 3 3 4 2 5 2 5 2 4 2 4 2 3 3 4 2 2 2 4 4 3 3 3 4 3 3 3 5 5 3 4 2 2 3 5 5 2 3 4 5 4 5 3 4 2 5 3 2 4\n",
"output": "3\n"
},
{
"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 1 4 4 4 4 4 4 4 4 4 4\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 1 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\n",
"output": "0\n"
},
{
"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\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\n",
"output": "50\n"
},
{
"input": "8\n1 1 2 2 3 3 4 4\n4 4 5 5 1 1 1 1\n",
"output": "2\n"
},
{
"input": "100\n2 4 5 2 5 5 4 4 5 4 4 5 2 5 5 4 5 2 5 2 2 4 5 4 4 4 2 4 2 2 4 2 4 2 2 2 4 5 5 5 4 2 4 5 4 4 2 5 4 2 5 4 5 4 5 4 5 5 5 4 2 2 4 5 2 5 5 2 5 2 4 4 4 5 5 2 2 2 4 4 2 2 2 5 5 2 2 4 5 4 2 4 4 2 5 2 4 4 4 4\n4 4 2 5 2 2 4 2 5 2 5 4 4 5 2 4 5 4 5 2 2 2 2 5 4 5 2 4 2 2 5 2 5 2 4 5 5 5 2 5 4 4 4 4 5 2 2 4 2 4 2 4 5 5 5 4 5 4 5 5 5 2 5 4 4 4 4 4 2 5 5 4 2 4 4 5 5 2 4 4 4 2 2 2 5 4 2 2 4 5 4 4 4 4 2 2 4 5 5 2\n",
"output": "0\n"
},
{
"input": "2\n1 2\n1 1\n",
"output": "-1\n"
},
{
"input": "100\n3 3 4 3 3 4 3 1 4 2 1 3 1 1 2 4 4 4 4 1 1 4 1 4 4 1 1 2 3 3 3 2 4 2 3 3 3 1 3 4 2 2 1 3 4 4 3 2 2 2 4 2 1 2 1 2 2 1 1 4 2 1 3 2 4 4 4 2 3 1 3 1 3 2 2 2 2 4 4 1 3 1 1 4 2 3 3 4 4 2 4 4 2 4 3 3 1 3 2 4\n3 1 4 4 2 1 1 1 1 1 1 3 1 1 3 4 3 2 2 4 2 1 4 4 4 4 1 2 3 4 2 3 3 4 3 3 2 4 2 2 2 1 2 4 4 4 2 1 3 4 3 3 4 2 4 4 3 2 4 2 4 2 4 4 1 4 3 1 4 3 3 3 3 1 2 2 2 2 4 1 2 1 3 4 3 1 3 3 4 2 3 3 2 1 3 4 2 1 1 2\n",
"output": "0\n"
},
{
"input": "3\n1 2 3\n1 1 4\n",
"output": "-1\n"
},
{
"input": "5\n3 3 3 2 2\n2 2 2 3 3\n",
"output": "-1\n"
},
{
"input": "100\n3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5\n3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1\n",
"output": "25\n"
},
{
"input": "2\n1 1\n2 2\n",
"output": "1\n"
},
{
"input": "5\n4 4 4 4 5\n4 5 5 5 5\n",
"output": "-1\n"
},
{
"input": "6\n1 2 3 3 4 4\n1 1 2 2 3 4\n",
"output": "-1\n"
},
{
"input": "2\n2 2\n1 3\n",
"output": "-1\n"
},
{
"input": "2\n2 2\n1 1\n",
"output": "1\n"
},
{
"input": "6\n1 1 2 2 3 4\n3 3 4 4 1 2\n",
"output": "-1\n"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 4 3 3 3 3 3 3 3 3 3 3 1 3 1 3 3 3 3 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 4 3 3 3 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 1 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3\n",
"output": "1\n"
},
{
"input": "2\n1 3\n4 5\n",
"output": "-1\n"
},
{
"input": "100\n3 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 4 4 3 3 3 3 3 3 4 3 3 4 3 3 3 3 4 3 3 3 4 4 4 3 3 4 4 4 3 4 4 3 3 4 3 3 3 4 4 4 3 4 3 3 3 3 3 3 3 4 4 3 3 3 3 4 3 3 3 3 3 4 4 3 3 3 3 3 4 3 4 4 4 4 3 4 3 4 4 4 4 3 3\n4 3 3 3 3 4 4 3 4 4 4 3 3 4 4 3 4 4 4 4 3 4 3 3 3 4 4 4 3 4 3 4 4 3 3 4 3 3 3 3 3 4 3 3 3 3 4 4 4 3 3 4 3 4 4 4 4 3 4 4 3 3 4 3 3 4 3 4 3 4 4 4 4 3 3 4 3 4 4 4 3 3 4 4 4 4 4 3 3 3 4 3 3 4 3 3 3 3 3 3\n",
"output": "5\n"
},
{
"input": "1\n1\n2\n",
"output": "-1\n"
},
{
"input": "100\n5 2 5 2 2 3 3 2 5 3 2 5 3 3 3 5 2 2 5 5 3 3 5 3 2 2 2 3 2 2 2 2 3 5 3 3 2 3 2 5 3 3 5 3 2 2 5 5 5 5 5 2 3 2 2 2 2 3 2 5 2 2 2 3 5 5 5 3 2 2 2 3 5 3 2 5 5 3 5 5 5 3 2 5 2 3 5 3 2 5 5 3 5 2 3 3 2 2 2 2\n5 3 5 3 3 5 2 5 3 2 3 3 5 2 5 2 2 5 2 5 2 5 3 3 5 3 2 2 2 3 5 3 2 2 3 2 2 5 5 2 3 2 3 3 5 3 2 5 2 2 2 3 3 5 3 3 5 2 2 2 3 3 2 2 3 5 3 5 5 3 3 2 5 3 5 2 3 2 5 5 3 2 5 5 2 2 2 2 3 2 2 5 2 5 2 2 3 3 2 5\n",
"output": "1\n"
},
{
"input": "6\n2 2 3 3 4 4\n2 3 4 5 5 5\n",
"output": "-1\n"
},
{
"input": "2\n1 2\n3 3\n",
"output": "-1\n"
},
{
"input": "6\n1 1 1 3 3 3\n2 2 2 4 4 4\n",
"output": "-1\n"
},
{
"input": "100\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3\n",
"output": "30\n"
},
{
"input": "100\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\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\n",
"output": "40\n"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
"output": "1\n"
},
{
"input": "100\n1 1 3 1 3 1 1 3 1 1 3 1 3 1 1 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 1 1 1 3 1 1 1 3 1 1 3 3 1 3 3 1 3 1 3 3 3 3 1 1 3 3 3 1 1 3 1 3 3 3 1 3 3 3 3 3 1 3 3 3 3 1 3 1 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 1 3 1 1 1\n1 1 1 3 3 3 3 3 3 3 1 3 3 3 1 3 3 3 3 3 3 1 3 3 1 3 3 1 1 1 3 3 3 3 3 3 3 1 1 3 3 3 1 1 3 3 1 1 1 3 3 3 1 1 3 1 1 3 3 1 1 3 3 3 3 3 3 1 3 3 3 1 1 3 3 3 1 1 3 3 1 3 1 3 3 1 1 3 3 1 1 3 1 3 3 3 1 3 1 3\n",
"output": "0\n"
},
{
"input": "3\n2 2 2\n4 4 4\n",
"output": "-1\n"
},
{
"input": "2\n1 2\n3 4\n",
"output": "-1\n"
},
{
"input": "10\n1 2 3 4 1 2 3 4 1 2\n1 2 3 4 1 2 3 4 3 4\n",
"output": "-1\n"
},
{
"input": "50\n1 3 1 3 3 3 1 3 3 3 3 1 1 1 3 3 3 1 3 1 1 1 3 1 3 1 3 3 3 1 3 1 1 3 3 3 1 1 1 1 3 3 1 1 1 3 3 1 1 1\n1 3 1 3 3 1 1 3 1 3 3 1 1 1 1 3 3 1 3 1 1 3 1 1 3 1 1 1 1 3 3 1 3 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 3 1\n",
"output": "0\n"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1\n2 2 2 2 2 2 2 2 2 2\n",
"output": "5\n"
},
{
"input": "2\n1 3\n2 4\n",
"output": "-1\n"
},
{
"input": "100\n1 4 4 1 4 4 1 1 4 1 1 1 1 4 4 4 4 1 1 1 1 1 1 4 4 4 1 1 4 4 1 1 1 1 4 4 4 4 4 1 1 4 4 1 1 1 4 1 1 1 1 4 4 4 4 4 4 1 4 4 4 4 1 1 1 4 1 4 1 1 1 1 4 1 1 1 4 4 4 1 4 4 1 4 4 4 4 4 1 4 1 1 4 1 4 1 1 1 4 4\n4 1 1 4 4 4 1 4 4 4 1 1 4 1 1 4 1 4 4 4 1 1 4 1 4 1 1 1 4 4 1 4 1 4 1 4 4 1 1 4 1 4 1 1 1 4 1 4 4 4 1 4 1 4 4 4 4 1 4 1 1 4 1 1 4 4 4 1 4 1 4 1 4 4 4 1 1 4 1 4 4 4 4 1 1 1 1 1 4 4 1 4 1 4 1 1 1 4 4 1\n",
"output": "1\n"
},
{
"input": "4\n1 1 1 1\n3 3 3 3\n",
"output": "2\n"
},
{
"input": "5\n1 1 1 3 3\n1 1 1 1 2\n",
"output": "-1\n"
},
{
"input": "100\n1 4 2 2 2 1 4 5 5 5 4 4 5 5 1 3 2 1 4 5 2 3 4 4 5 4 4 4 4 5 1 3 5 5 3 3 3 3 5 1 4 3 5 1 2 4 1 3 5 5 1 3 3 3 1 3 5 4 4 2 2 5 5 5 2 3 2 5 1 3 5 4 5 3 2 2 3 2 3 3 2 5 2 4 2 3 4 1 3 1 3 1 5 1 5 2 3 5 4 5\n1 2 5 3 2 3 4 2 5 1 2 5 3 4 3 3 4 1 5 5 1 3 3 1 1 4 1 4 2 5 4 1 3 4 5 3 2 2 1 4 5 5 2 3 3 5 5 4 2 3 3 5 3 3 5 4 4 5 3 5 1 1 4 4 4 1 3 5 5 5 4 2 4 5 3 2 2 2 5 5 5 1 4 3 1 3 1 2 2 4 5 1 3 2 4 5 1 5 2 5\n",
"output": "1\n"
},
{
"input": "100\n4 1 1 2 1 4 4 1 4 5 5 5 2 2 1 3 5 2 1 5 2 1 2 4 4 2 1 2 2 2 4 3 1 4 2 2 3 1 1 4 4 5 4 4 4 5 1 4 1 4 3 1 2 1 2 4 1 2 5 2 1 4 3 4 1 4 2 1 1 1 5 3 3 1 4 1 3 1 4 1 1 2 2 2 3 1 4 3 4 4 5 2 5 4 3 3 3 2 2 1\n5 1 4 4 3 4 4 5 2 3 3 4 4 2 3 2 3 1 3 1 1 4 1 5 4 3 2 4 3 3 3 2 3 4 1 5 4 2 4 2 2 2 5 3 1 2 5 3 2 2 1 1 2 2 3 5 1 2 5 3 2 1 1 2 1 2 4 3 5 4 5 3 2 4 1 3 4 1 4 4 5 4 4 5 4 2 5 3 4 1 4 2 4 2 4 5 4 5 4 2\n",
"output": "6\n"
},
{
"input": "100\n4 4 5 4 3 5 5 2 4 5 5 5 3 4 4 2 5 2 5 3 3 3 3 5 3 2 2 2 4 4 4 4 3 3 4 5 3 2 2 2 4 4 5 3 4 5 4 5 5 2 4 2 5 2 3 4 4 5 2 2 4 4 5 5 5 3 5 4 5 5 5 4 3 3 2 4 3 5 5 5 2 4 2 5 4 3 5 3 2 3 5 2 5 2 2 5 4 5 4 3\n5 4 2 4 3 5 2 5 5 3 4 5 4 5 3 3 5 5 2 3 4 2 3 5 2 2 2 4 2 5 2 4 4 5 2 2 4 4 5 5 2 3 4 2 4 5 2 5 2 2 4 5 5 3 5 5 5 4 3 4 4 3 5 5 3 4 5 3 2 3 4 3 4 4 2 5 3 4 5 5 3 5 3 3 4 3 5 3 2 2 4 5 4 5 5 2 3 4 3 5\n",
"output": "1\n"
},
{
"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\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\n",
"output": "0\n"
},
{
"input": "100\n5 2 2 2 5 2 5 5 5 2 5 2 5 5 5 5 5 5 2 2 2 5 5 2 5 2 2 5 2 5 5 2 5 2 5 2 5 5 5 5 5 2 2 2 2 5 5 2 5 5 5 2 5 5 5 2 5 5 5 2 2 2 5 2 2 2 5 5 2 5 5 5 2 5 2 2 5 2 2 2 5 5 5 5 2 5 2 5 2 2 5 2 5 2 2 2 2 5 5 2\n5 5 2 2 5 5 2 5 2 2 5 5 5 5 2 5 5 2 5 2 2 5 2 2 5 2 5 2 2 5 2 5 2 5 5 2 2 5 5 5 2 5 5 2 5 5 5 2 2 5 5 5 2 5 5 5 2 2 2 5 5 5 2 2 5 5 2 2 2 5 2 5 5 2 5 2 5 2 2 5 5 2 2 5 5 2 2 5 2 2 5 2 2 2 5 5 2 2 2 5\n",
"output": "1\n"
},
{
"input": "100\n5 3 4 4 2 5 1 1 4 4 3 5 5 1 4 4 2 5 3 2 1 1 3 2 4 4 4 2 5 2 2 3 1 4 1 4 4 5 3 5 1 4 1 4 1 5 5 3 5 5 1 5 3 5 1 3 3 4 5 3 2 2 4 5 2 5 4 2 4 4 1 1 4 2 4 1 2 2 4 3 4 1 1 1 4 3 5 1 2 1 4 5 4 4 2 1 4 1 3 2\n1 1 1 1 4 2 1 4 1 1 3 5 4 3 5 2 2 4 2 2 4 1 3 4 4 5 1 1 2 2 2 1 4 1 4 4 1 5 5 2 3 5 1 5 4 2 3 2 2 5 4 1 1 4 5 2 4 5 4 4 3 3 2 4 3 4 5 5 4 2 4 2 1 2 3 2 2 5 5 3 1 3 4 3 4 4 5 3 1 1 3 5 1 4 4 2 2 1 4 5\n",
"output": "2\n"
},
{
"input": "4\n3 4 4 4\n3 3 4 4\n",
"output": "-1\n"
},
{
"input": "2\n1 2\n4 4\n",
"output": "-1\n"
},
{
"input": "3\n1 2 3\n3 3 3\n",
"output": "-1\n"
},
{
"input": "4\n1 2 3 4\n5 5 5 5\n",
"output": "-1\n"
},
{
"input": "8\n1 1 2 2 3 3 3 3\n2 2 2 2 1 1 1 1\n",
"output": "2\n"
}
] | code_contests | python | 0.2 | 319b2b70ba6d6a51694118ce9a9499c1 |
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected.
You should assign labels to all vertices in such a way that:
* Labels form a valid permutation of length n — an integer sequence such that each integer from 1 to n appears exactly once in it.
* If there exists an edge from vertex v to vertex u then labelv should be smaller than labelu.
* Permutation should be lexicographically smallest among all suitable.
Find such sequence of labels to satisfy all the conditions.
Input
The first line contains two integer numbers n, m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105).
Next m lines contain two integer numbers v and u (1 ≤ v, u ≤ n, v ≠ u) — edges of the graph. Edges are directed, graph doesn't contain loops or multiple edges.
Output
Print n numbers — lexicographically smallest correct permutation of labels of vertices.
Examples
Input
3 3
1 2
1 3
3 2
Output
1 3 2
Input
4 5
3 1
4 1
2 3
3 4
2 4
Output
4 1 2 3
Input
5 4
3 1
2 1
2 3
4 5
Output
3 1 2 4 5
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | #!/usr/local/bin/python3
from collections import defaultdict
import heapq
num_nodes, num_edges = map(int, input().split())
ins = defaultdict(set)
out = defaultdict(int)
for _ in range(num_edges):
node_out, node_in = map(int, input().split())
ins[node_in].add(node_out)
out[node_out] += 1
zeros = [-node for node in range(num_nodes, 0, -1) if out[node] == 0]
final_mappings = {}
current_index = num_nodes
while current_index > 0:
node = -heapq.heappop(zeros)
final_mappings[node] = current_index
current_index -= 1
for node_out in ins[node]:
out[node_out] -= 1
if out[node_out] == 0:
heapq.heappush(zeros, -node_out)
print(' '.join(str(final_mappings[node]) for node in range(1, num_nodes + 1)))
| python | code_algorithm | [
{
"input": "3 3\n1 2\n1 3\n3 2\n",
"output": "1 3 2\n"
},
{
"input": "4 5\n3 1\n4 1\n2 3\n3 4\n2 4\n",
"output": "4 1 2 3\n"
},
{
"input": "5 4\n3 1\n2 1\n2 3\n4 5\n",
"output": "3 1 2 4 5\n"
},
{
"input": "2 1\n2 1\n",
"output": "2 1\n"
},
{
"input": "100 10\n73 55\n29 76\n15 12\n94 46\n77 67\n76 16\n72 50\n41 40\n89 75\n27 22\n",
"output": "1 2 3 4 5 6 7 8 9 10 11 13 14 15 12 18 19 20 21 22 23 25 26 27 28 29 24 30 16 31 32 33 34 35 36 37 38 39 40 42 41 43 44 45 46 48 49 50 51 53 54 55 56 57 59 60 61 62 63 64 65 66 67 68 69 70 72 73 74 75 76 52 58 77 79 17 71 80 81 82 83 84 85 86 87 88 89 90 78 91 92 93 94 47 95 96 97 98 99 100\n"
},
{
"input": "5 10\n5 2\n4 1\n2 1\n3 4\n2 4\n3 2\n5 4\n3 5\n3 1\n5 1\n",
"output": "5 3 1 4 2\n"
}
] | code_contests | python | 0 | ca6fbac70c6f64b0477a0b543e1abccd |
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the lengths of the first and the second lists, respectively.
The second line contains n distinct digits a1, a2, ..., an (1 ≤ ai ≤ 9) — the elements of the first list.
The third line contains m distinct digits b1, b2, ..., bm (1 ≤ bi ≤ 9) — the elements of the second list.
Output
Print the smallest pretty integer.
Examples
Input
2 3
4 2
5 7 6
Output
25
Input
8 8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
Output
1
Note
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | a,b=map(int,input().split())
s=input().split()
x=list(map(int,s))
s=input().split()
y=list(map(int,s))
o=10
for i in range(a):
for j in range(b):
if x[i]==y[j]:
if x[i]<o:
o=x[i]
x1=min(x)
y1=min(y)
if o<10:
print(o)
else:
print(min(y1,x1)*10+max(x1,y1))
| python | code_algorithm | [
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n",
"output": "1\n"
},
{
"input": "2 3\n4 2\n5 7 6\n",
"output": "25\n"
},
{
"input": "4 3\n1 3 5 9\n2 8 9\n",
"output": "9\n"
},
{
"input": "1 2\n5\n2 5\n",
"output": "5\n"
},
{
"input": "2 4\n8 9\n1 2 3 9\n",
"output": "9\n"
},
{
"input": "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1\n",
"output": "1\n"
},
{
"input": "2 2\n1 5\n2 5\n",
"output": "5\n"
},
{
"input": "3 2\n4 5 6\n1 5\n",
"output": "5\n"
},
{
"input": "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6\n",
"output": "1\n"
},
{
"input": "3 3\n3 5 6\n1 5 9\n",
"output": "5\n"
},
{
"input": "3 3\n2 4 9\n7 8 9\n",
"output": "9\n"
},
{
"input": "5 3\n3 4 5 6 7\n1 5 9\n",
"output": "5\n"
},
{
"input": "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7\n",
"output": "1\n"
},
{
"input": "1 1\n1\n2\n",
"output": "12\n"
},
{
"input": "4 4\n1 3 5 8\n2 4 6 8\n",
"output": "8\n"
},
{
"input": "1 1\n2\n1\n",
"output": "12\n"
},
{
"input": "5 5\n1 2 3 4 5\n9 2 1 7 5\n",
"output": "1\n"
},
{
"input": "2 2\n1 9\n9 2\n",
"output": "9\n"
},
{
"input": "4 5\n5 2 6 4\n8 9 1 3 7\n",
"output": "12\n"
},
{
"input": "1 1\n9\n1\n",
"output": "19\n"
},
{
"input": "3 3\n3 6 8\n2 6 9\n",
"output": "6\n"
},
{
"input": "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9\n",
"output": "1\n"
},
{
"input": "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9\n",
"output": "1\n"
},
{
"input": "5 4\n1 3 5 6 7\n2 4 3 9\n",
"output": "3\n"
},
{
"input": "3 2\n1 2 3\n2 3\n",
"output": "2\n"
},
{
"input": "3 3\n1 2 4\n3 4 5\n",
"output": "4\n"
},
{
"input": "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1\n",
"output": "1\n"
},
{
"input": "2 2\n1 4\n2 4\n",
"output": "4\n"
},
{
"input": "2 2\n1 8\n2 8\n",
"output": "8\n"
},
{
"input": "1 2\n9\n8 9\n",
"output": "9\n"
},
{
"input": "3 2\n1 4 9\n2 4\n",
"output": "4\n"
},
{
"input": "4 5\n3 2 4 5\n1 6 5 9 8\n",
"output": "5\n"
},
{
"input": "3 3\n1 3 5\n2 3 6\n",
"output": "3\n"
},
{
"input": "3 2\n1 2 4\n4 2\n",
"output": "2\n"
},
{
"input": "2 3\n4 5\n1 3 5\n",
"output": "5\n"
},
{
"input": "5 5\n5 6 7 8 9\n1 2 3 4 5\n",
"output": "5\n"
},
{
"input": "3 3\n5 6 7\n5 6 7\n",
"output": "5\n"
},
{
"input": "1 1\n1\n1\n",
"output": "1\n"
},
{
"input": "5 5\n1 3 5 7 9\n2 4 6 8 9\n",
"output": "9\n"
},
{
"input": "1 1\n9\n8\n",
"output": "89\n"
},
{
"input": "3 3\n1 5 3\n2 5 7\n",
"output": "5\n"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9\n",
"output": "12\n"
},
{
"input": "3 2\n1 2 4\n3 4\n",
"output": "4\n"
},
{
"input": "5 5\n1 2 3 4 5\n1 2 3 4 5\n",
"output": "1\n"
},
{
"input": "1 1\n9\n9\n",
"output": "9\n"
},
{
"input": "3 3\n3 2 1\n3 2 1\n",
"output": "1\n"
},
{
"input": "4 4\n1 2 3 4\n2 5 6 7\n",
"output": "2\n"
},
{
"input": "1 1\n8\n9\n",
"output": "89\n"
},
{
"input": "2 2\n1 3\n2 3\n",
"output": "3\n"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9\n",
"output": "9\n"
},
{
"input": "5 5\n1 2 3 4 5\n2 3 4 5 6\n",
"output": "2\n"
},
{
"input": "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1\n",
"output": "1\n"
}
] | code_contests | python | 0.3 | 56e49bc6adcc2f679e59fa41ef6d1a6e |
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters.
<image>
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the i-th letter of her name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n. Fibonacci sequence is the sequence f where
* f1 = 1,
* f2 = 1,
* fn = fn - 2 + fn - 1 (n > 2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input
The first and only line of input contains an integer n (1 ≤ n ≤ 1000).
Output
Print Eleven's new name on the first and only line of output.
Examples
Input
8
Output
OOOoOooO
Input
15
Output
OOOoOooOooooOoo
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n=int(input())
a,b,r=1,2,''
for i in range(1,n+1):
if i==a: r+='O';a,b=b,a+b
else: r+='o'
print(r) | python | code_algorithm | [
{
"input": "8\n",
"output": "OOOoOooO\n"
},
{
"input": "15\n",
"output": "OOOoOooOooooOoo\n"
},
{
"input": "381\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo\n"
},
{
"input": "1000\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooo\n"
},
{
"input": "5\n",
"output": "OOOoO\n"
},
{
"input": "781\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"
},
{
"input": "999\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooo\n"
},
{
"input": "805\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"
},
{
"input": "3\n",
"output": "OOO\n"
},
{
"input": "61\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo\n"
},
{
"input": "256\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo\n"
},
{
"input": "512\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"
},
{
"input": "1\n",
"output": "O\n"
},
{
"input": "17\n",
"output": "OOOoOooOooooOoooo\n"
},
{
"input": "2\n",
"output": "OO\n"
},
{
"input": "933\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n"
},
{
"input": "85\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo\n"
},
{
"input": "49\n",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo\n"
}
] | code_contests | python | 0.9 | 206cc25a2e3c8c7900126ba445d2389f |
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.
Diameter of multiset consisting of one point is 0.
You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?
Input
The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively.
The second line contains n space separated integers (1 ≤ xi ≤ 100) — the coordinates of the points.
Output
Output a single integer — the minimum number of points you have to remove.
Examples
Input
3 1
2 1 4
Output
1
Input
3 0
7 7 7
Output
0
Input
6 3
1 3 4 6 9 10
Output
3
Note
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n,d = map(int,input().split())
a=list(map(int,input().split()))
a.sort();
i=0
cnt=0
cnt1=0
if n==1:
print("0")
else:
for i in range(n):
cnt=0
for j in range(i+1,n):
d1=a[j]-a[i]
if d1>d:
break;
cnt+=1
if(cnt1<cnt):
cnt1=cnt
print(n-cnt1-1) | python | code_algorithm | [
{
"input": "6 3\n1 3 4 6 9 10\n",
"output": "3\n"
},
{
"input": "3 1\n2 1 4\n",
"output": "1\n"
},
{
"input": "3 0\n7 7 7\n",
"output": "0\n"
},
{
"input": "1 100\n22\n",
"output": "0\n"
},
{
"input": "3 2\n1 50 99\n",
"output": "2\n"
},
{
"input": "100 56\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\n",
"output": "43\n"
},
{
"input": "3 1\n25 26 27\n",
"output": "1\n"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"output": "0\n"
},
{
"input": "100 0\n14 17 18 22 19 18 19 21 19 19 22 22 19 21 24 23 24 19 25 24 24 21 20 13 26 18 17 15 25 13 17 20 20 21 13 22 27 15 18 27 19 15 16 25 18 17 18 22 19 17 18 24 14 16 18 16 22 16 17 27 18 17 18 24 22 13 14 20 23 19 16 21 19 13 14 14 25 15 27 24 26 22 16 20 16 14 21 27 15 23 23 24 27 14 24 17 19 24 15 27\n",
"output": "89\n"
},
{
"input": "100 100\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100\n",
"output": "0\n"
},
{
"input": "4 2\n1 4 7 9\n",
"output": "2\n"
},
{
"input": "2 0\n1 2\n",
"output": "1\n"
},
{
"input": "100 5\n51 56 52 60 52 53 52 60 56 54 55 50 53 51 57 53 52 54 54 52 51 55 50 56 60 51 58 50 60 59 50 54 60 55 55 57 54 59 59 55 55 52 56 57 59 54 53 57 52 50 50 55 59 54 54 56 51 58 52 51 56 56 58 56 54 54 57 52 51 58 56 57 54 59 58 53 50 52 50 60 57 51 54 59 54 54 52 55 53 55 51 53 52 54 51 56 55 53 58 56\n",
"output": "34\n"
},
{
"input": "7 4\n1 3 4 9 10 11 12\n",
"output": "3\n"
},
{
"input": "2 5\n67 23\n",
"output": "1\n"
},
{
"input": "1 100\n1\n",
"output": "0\n"
},
{
"input": "100 1\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100\n",
"output": "93\n"
},
{
"input": "5 1\n3 5 5 5 6\n",
"output": "1\n"
},
{
"input": "1 10\n25\n",
"output": "0\n"
},
{
"input": "3 0\n1 2 3\n",
"output": "2\n"
},
{
"input": "100 0\n14 13 14 13 14 13 13 13 13 14 13 13 14 14 13 14 14 14 14 13 13 13 14 13 13 14 14 14 14 14 14 13 13 13 13 14 13 14 13 14 13 14 14 14 14 13 13 14 14 13 13 13 13 14 13 14 13 14 13 14 13 13 13 14 13 13 14 13 14 14 13 13 13 14 14 14 14 13 13 14 14 14 14 14 14 14 13 14 13 13 13 14 14 13 13 13 13 13 14 14\n",
"output": "50\n"
},
{
"input": "100 11\n44 89 57 64 94 96 73 96 55 52 91 73 73 93 51 62 63 85 43 75 60 78 98 55 80 84 65 75 61 88 62 71 53 57 94 85 60 96 66 96 61 72 97 64 51 44 63 82 67 86 60 57 74 85 57 79 61 94 86 78 84 56 60 75 91 91 92 62 89 85 79 57 76 97 65 56 46 78 51 69 50 52 85 80 76 71 81 51 90 71 77 60 63 62 84 59 79 84 69 81\n",
"output": "70\n"
},
{
"input": "1 0\n22\n",
"output": "0\n"
},
{
"input": "100 0\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100\n",
"output": "96\n"
},
{
"input": "76 32\n50 53 69 58 55 39 40 42 40 55 58 73 55 72 75 44 45 55 46 60 60 42 41 64 77 39 68 51 61 49 38 41 56 57 64 43 78 36 39 63 40 66 52 76 39 68 39 73 40 68 54 60 35 67 69 52 58 52 38 63 69 38 69 60 73 64 65 41 59 55 37 57 40 34 35 35\n",
"output": "13\n"
},
{
"input": "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100\n",
"output": "84\n"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20\n",
"output": "5\n"
},
{
"input": "100 70\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100\n",
"output": "27\n"
},
{
"input": "100 5\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100\n",
"output": "89\n"
},
{
"input": "3 1\n10 20 30\n",
"output": "2\n"
},
{
"input": "1 5\n6\n",
"output": "0\n"
},
{
"input": "1 99\n99\n",
"output": "0\n"
},
{
"input": "70 80\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\n",
"output": "0\n"
},
{
"input": "8 1\n3 3 3 5 5 5 5 5\n",
"output": "3\n"
},
{
"input": "98 64\n2 29 36 55 58 15 25 33 7 16 61 1 4 24 63 26 36 16 16 3 57 39 56 7 11 24 20 12 22 10 56 5 11 39 61 52 27 54 21 6 61 36 40 52 54 5 15 52 58 23 45 39 65 16 27 40 13 64 47 24 51 29 9 18 49 49 8 47 2 64 7 63 49 10 20 26 34 3 45 66 8 46 16 32 16 38 3 6 15 17 35 48 36 5 57 29 61 15\n",
"output": "1\n"
}
] | code_contests | python | 1 | 4b78a93292fbc59136c7be6a04d61cb5 |
You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume.
You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up to one task at a time, and no more than two tasks total. The first task can be any, the second task on each computer must use strictly less power than the first. You will assign between 1 and 2 tasks to each computer. You will then first execute the first task on each computer, wait for all of them to complete, and then execute the second task on each computer that has two tasks assigned.
If the average compute power per utilized processor (the sum of all consumed powers for all tasks presently running divided by the number of utilized processors) across all computers exceeds some unknown threshold during the execution of the first tasks, the entire system will blow up. There is no restriction on the second tasks execution. Find the lowest threshold for which it is possible.
Due to the specifics of the task, you need to print the answer multiplied by 1000 and rounded up.
Input
The first line contains a single integer n (1 ≤ n ≤ 50) — the number of tasks.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 108), where ai represents the amount of power required for the i-th task.
The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 100), where bi is the number of processors that i-th task will utilize.
Output
Print a single integer value — the lowest threshold for which it is possible to assign all tasks in such a way that the system will not blow up after the first round of computation, multiplied by 1000 and rounded up.
Examples
Input
6
8 10 9 9 8 10
1 1 1 1 1 1
Output
9000
Input
6
8 10 9 9 8 10
1 10 5 5 1 10
Output
1160
Note
In the first example the best strategy is to run each task on a separate computer, getting average compute per processor during the first round equal to 9.
In the second task it is best to run tasks with compute 10 and 9 on one computer, tasks with compute 10 and 8 on another, and tasks with compute 9 and 8 on the last, averaging (10 + 10 + 9) / (10 + 10 + 5) = 1.16 compute power per processor during the first round.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | # Codeforces Round #488 by NEAR (Div. 2)
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
import math
import sys
def getIntList():
return list(map(int, input().split()))
import bisect
def makePair(z):
return [(z[i], z[i+1]) for i in range(0,len(z),2) ]
N, = getIntList()
za = getIntList()
zb = getIntList()
sa = set(za)
xa = list(sa)
xa.sort(reverse = True)
zz = [(t, sorted([zb[i] for i in range(N) if za[i] == t]) ) for t in xa ]
#print(zz)
lastdp = [[] for i in range(52)]
lastdp[0] = [(0,0)]
def addres(z, t):
if len(z) ==0:
z.append(t)
return
i = bisect.bisect_right(z,t)
if i>0 and z[i-1][1] >= t[1]: return
if i<len(z) and t[1] >= z[i][1]:
z[i] = t
return
z.insert(i,t)
for x in zz:
nowdp = [[] for i in range(52)]
for i in range(len(lastdp)):
tz = lastdp[i]
if len( tz ) ==0 : continue
num = len(x[1])
hide = min(i, num )
tb = sum(x[1])
acc =0;
for j in range(hide + 1):
la = x[0] * (num-j)
lb = tb - acc
if j<num: acc += x[1][j]
for t in tz:
# t = (0,0)
tr = (t[0] + la, t[1] + lb)
addres(nowdp[ i -j + num -j] ,tr)
lastdp = nowdp
#print(lastdp)
res = 10 ** 20
for x in lastdp:
for y in x:
t = math.ceil(y[0] *1000 / y[1] )
res = min( res,t)
print(res)
| python | code_algorithm | [
{
"input": "6\n8 10 9 9 8 10\n1 1 1 1 1 1\n",
"output": "9000\n"
},
{
"input": "6\n8 10 9 9 8 10\n1 10 5 5 1 10\n",
"output": "1160\n"
},
{
"input": "5\n21581303 73312811 99923326 93114466 53291492\n32 75 75 33 5\n",
"output": "1070425495\n"
},
{
"input": "10\n7 9 8 9 4 8 5 2 10 5\n6 6 7 8 9 7 10 1 1 7\n",
"output": "977\n"
},
{
"input": "50\n2 10 10 6 8 1 5 10 3 4 3 5 5 8 4 5 8 2 3 3 3 8 8 5 5 5 5 8 2 5 1 5 4 8 3 7 10 8 6 1 4 9 4 9 1 9 2 7 9 9\n10 6 2 2 3 6 5 5 4 1 3 1 2 3 10 10 6 8 7 2 8 5 2 5 4 9 7 5 2 8 3 6 9 8 2 5 8 3 7 3 3 6 3 7 6 10 9 2 9 7\n",
"output": "785\n"
},
{
"input": "10\n99999917 99999940 99999907 99999901 99999933 99999930 99999964 99999929 99999967 99999947\n93 98 71 41 13 7 24 70 52 70\n",
"output": "1305482246\n"
},
{
"input": "10\n99999983 99999982 99999945 99999989 99999981 99999947 99999941 99999987 99999965 99999914\n65 14 84 48 71 14 86 65 61 76\n",
"output": "1414140889\n"
},
{
"input": "1\n1\n100\n",
"output": "10\n"
},
{
"input": "10\n68 10 16 26 94 30 17 90 40 26\n36 3 5 9 60 92 55 10 25 27\n",
"output": "871\n"
},
{
"input": "5\n99999950 99999991 99999910 99999915 99999982\n99 55 71 54 100\n",
"output": "1181102060\n"
},
{
"input": "10\n99999954 99999947 99999912 99999920 99999980 99999928 99999908 99999999 99999927 99999957\n15 97 18 8 82 21 73 15 28 75\n",
"output": "1621620860\n"
},
{
"input": "10\n9 5 1 4 7 6 10 10 3 8\n40 84 53 88 20 33 55 41 34 55\n",
"output": "100\n"
},
{
"input": "5\n81372426 35955615 58387606 77143158 48265342\n9 8 1 6 3\n",
"output": "8455269522\n"
},
{
"input": "1\n100000000\n1\n",
"output": "100000000000\n"
},
{
"input": "50\n88 86 31 49 90 52 57 70 39 94 8 90 39 89 56 78 10 80 9 18 95 96 8 57 29 37 13 89 32 99 85 61 35 37 44 55 92 16 69 80 90 34 84 25 26 17 71 93 46 7\n83 95 7 23 34 68 100 89 8 82 36 84 52 42 44 2 25 6 40 72 19 2 75 70 83 3 92 58 51 88 77 75 75 52 15 20 77 63 6 32 39 86 16 22 8 83 53 66 39 13\n",
"output": "751\n"
},
{
"input": "10\n3 10 3 1 3 8 9 7 1 5\n11 18 35 41 47 38 51 68 85 58\n",
"output": "96\n"
},
{
"input": "5\n5 4 3 7 3\n7 7 14 57 94\n",
"output": "89\n"
},
{
"input": "50\n84 98 70 31 72 99 83 73 24 28 100 87 3 12 84 85 28 16 53 29 77 64 38 85 44 60 12 58 3 61 88 42 14 83 1 11 57 63 77 37 99 97 50 94 55 3 12 50 27 68\n9 1 4 6 10 5 3 2 4 6 6 9 8 6 1 2 2 1 8 5 8 1 9 1 2 10 2 7 5 1 7 4 7 1 3 6 10 7 3 5 1 3 4 8 4 7 3 3 10 7\n",
"output": "7265\n"
},
{
"input": "50\n83 43 73 75 11 53 6 43 67 38 83 12 70 27 60 13 9 79 61 30 29 71 10 11 95 87 26 26 19 99 13 47 66 93 91 47 90 75 68 3 22 29 59 12 44 41 64 3 99 100\n31 36 69 25 18 33 15 70 12 91 41 44 1 96 80 74 12 80 16 82 88 25 87 17 53 63 3 42 81 6 50 78 34 68 65 78 94 14 53 14 41 97 63 44 21 62 95 37 36 31\n",
"output": "705\n"
},
{
"input": "50\n5 6 10 7 3 8 5 1 5 3 10 7 9 3 9 5 5 4 8 1 6 10 6 7 8 2 2 3 1 4 10 1 2 9 6 6 10 10 2 7 1 6 1 1 7 9 1 8 5 4\n2 2 6 1 5 1 4 9 5 3 5 3 2 1 5 7 4 10 9 8 5 8 1 10 6 7 5 4 10 3 9 4 1 5 6 9 3 8 9 8 2 10 7 3 10 1 1 7 5 3\n",
"output": "736\n"
},
{
"input": "50\n1 2 7 8 4 9 1 8 3 6 7 2 10 10 4 2 1 7 9 10 10 1 4 7 5 6 1 6 6 2 5 4 5 10 9 9 7 5 5 7 1 3 9 6 2 3 9 10 6 3\n29 37 98 68 71 45 20 38 88 34 85 33 55 80 99 29 28 53 79 100 76 53 18 32 39 29 54 18 56 95 94 60 80 3 24 69 52 91 51 7 36 37 67 28 99 10 99 66 92 48\n",
"output": "78\n"
},
{
"input": "5\n99999948 99999931 99999946 99999958 99999965\n43 42 42 24 87\n",
"output": "1744185140\n"
},
{
"input": "10\n4 6 4 4 6 7 2 7 7 8\n35 50 93 63 8 59 46 97 50 88\n",
"output": "75\n"
},
{
"input": "5\n99999943 99999973 99999989 99999996 99999953\n2 6 5 2 1\n",
"output": "23076919847\n"
},
{
"input": "10\n46 29 60 65 57 95 82 52 39 21\n35 24 8 69 63 27 69 29 94 64\n",
"output": "918\n"
},
{
"input": "50\n95 86 10 54 82 42 64 88 14 62 2 31 10 80 18 47 73 81 42 98 30 86 65 77 45 28 39 9 88 58 19 70 41 6 33 7 50 34 22 69 37 65 98 89 46 48 9 76 57 64\n87 39 41 23 49 45 91 83 50 92 25 11 76 1 97 42 62 91 2 53 40 11 93 72 66 8 8 62 35 14 57 95 15 80 95 51 60 95 25 70 27 59 51 76 99 100 87 58 24 7\n",
"output": "637\n"
},
{
"input": "5\n99 65 93 94 17\n1 5 6 2 3\n",
"output": "18267\n"
},
{
"input": "5\n88535415 58317418 74164690 46139122 28946947\n3 9 3 1 4\n",
"output": "10987486250\n"
},
{
"input": "5\n61 56 77 33 13\n79 40 40 26 56\n",
"output": "863\n"
}
] | code_contests | python | 0 | 71b5212e05606199c16bcdf17c2fb7ab |
Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array.
The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0.
More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array.
After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained.
Output
If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1.
Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t.
Examples
Input
4
0 1 2 1
Output
-1
Input
3
1 0 1
Output
1
Input
4
0 1 2 239
Output
4
Note
In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed.
* 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0].
* 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1].
* 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2].
* 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1].
Thus, he can get the array without mistakes, so the answer is -1.
In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0.
In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
data = input().split()
max = 0
for i in range(n):
back = max
if max<int(data[i]):
max=int(data[i])
if i==0 and data[i]!="0":
print(1)
exit()
elif int(data[i])>back+1:
print(i+1)
exit()
if int(data[i])<=back+1:
print(-1)
| python | code_algorithm | [
{
"input": "3\n1 0 1\n",
"output": "1\n"
},
{
"input": "4\n0 1 2 1\n",
"output": "-1\n"
},
{
"input": "4\n0 1 2 239\n",
"output": "4\n"
},
{
"input": "2\n0 1\n",
"output": "-1\n"
},
{
"input": "3\n0 1 1000000000\n",
"output": "3\n"
},
{
"input": "3\n0 2 4\n",
"output": "2\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "2\n0 0\n",
"output": "-1\n"
},
{
"input": "2\n0 1000000000\n",
"output": "2\n"
},
{
"input": "2\n1 1\n",
"output": "1\n"
},
{
"input": "5\n0 0 0 0 0\n",
"output": "-1\n"
},
{
"input": "2\n1 2\n",
"output": "1\n"
},
{
"input": "1\n1000000000\n",
"output": "1\n"
},
{
"input": "5\n0 0 2 2 3\n",
"output": "3\n"
},
{
"input": "2\n0 2\n",
"output": "2\n"
},
{
"input": "4\n0 0 2 1\n",
"output": "3\n"
},
{
"input": "5\n0 0 2 3 4\n",
"output": "3\n"
},
{
"input": "3\n0 0 2\n",
"output": "3\n"
},
{
"input": "3\n3 4 5\n",
"output": "1\n"
},
{
"input": "1\n0\n",
"output": "-1\n"
}
] | code_contests | python | 1 | bea3702f4ca8b64d851c95726eb7ce9e |
You are given an integer number n. The following algorithm is applied to it:
1. if n = 0, then end algorithm;
2. find the smallest prime divisor d of n;
3. subtract d from n and go to step 1.
Determine the number of subtrations the algorithm will make.
Input
The only line contains a single integer n (2 ≤ n ≤ 10^{10}).
Output
Print a single integer — the number of subtractions the algorithm will make.
Examples
Input
5
Output
1
Input
4
Output
2
Note
In the first example 5 is the smallest prime divisor, thus it gets subtracted right away to make a 0.
In the second example 2 is the smallest prime divisor at both steps.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from collections import deque as de
import math
class My_stack():
def __init__(self):
self.data = []
def my_push(self, x):
return (self.data.append(x))
def my_pop(self):
return (self.data.pop())
def my_peak(self):
return (self.data[-1])
def my_contains(self, x):
return (self.data.count(x))
def my_show_all(self):
return (self.data)
def isEmpty(self):
return len(self.data)==0
arrStack = My_stack()
# A optimized school method based
# Python3 program to check
# if a number is prime
def isPrime(n) :
# Corner cases
if (n <= 1) :
return False
if (n <= 3) :
return True
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def get_prime_factors(number):
# create an empty list and later I will
# run a for loop with range() function using the append() method to add elements to the list.
prime_factors = []
# First get the number of two's that divide number
# i.e the number of 2's that are in the factors
while number % 2 == 0:
prime_factors.append(2)
number = number / 2
# After the above while loop, when number has been
# divided by all the 2's - so the number must be odd at this point
# Otherwise it would be perfectly divisible by 2 another time
# so now that its odd I can skip 2 ( i = i + 2) for each increment
for i in range(3, int(math.sqrt(number)) + 1, 2):
while number % i == 0:
prime_factors.append(int(i))
number = number / i
# Here is the crucial part.
# First quick refreshment on the two key mathematical conjectures of Prime factorization of any non-Prime number
# Which is - 1. If n is not a prime number AT-LEAST one Prime factor would be less than sqrt(n)
# And - 2. If n is not a prime number - There can be AT-MOST 1 prime factor of n greater than sqrt(n).
# Like 7 is a prime-factor for 14 which is greater than sqrt(14)
# But if the above loop DOES NOT go beyond square root of the initial n.
# Then how does that greater than sqrt(n) prime-factor
# will be captured in my prime factorization function.
# ANS to that is - in my first for-loop I am dividing n with the prime number if that prime is a factor of n.
# Meaning, after this first for-loop gets executed completely, the adjusted initial n should become
# either 1 or greater than 1
# And if n has NOT become 1 after the previous for-loop, that means that
# The remaining n is that prime factor which is greater that the square root of initial n.
# And that's why in the next part of my gorithm, I need to check whether n becomes 1 or not,
#This code is taken ny rohan paul's github
if number > 2:
prime_factors.append(int(number))
return prime_factors
n=int(input())
if isPrime(n):
print(1)
else:
if n%2:
l=get_prime_factors(n)
print(((n-l[0])//2)+1)
else:
print(n//2) | python | code_algorithm | [
{
"input": "4\n",
"output": "2\n"
},
{
"input": "5\n",
"output": "1\n"
},
{
"input": "9999999999\n",
"output": "4999999999\n"
},
{
"input": "10000000000\n",
"output": "5000000000\n"
},
{
"input": "9999999967\n",
"output": "1\n"
},
{
"input": "2\n",
"output": "1\n"
},
{
"input": "6969696\n",
"output": "3484848\n"
},
{
"input": "473\n",
"output": "232\n"
},
{
"input": "9998200081\n",
"output": "4999050046\n"
},
{
"input": "3000000021\n",
"output": "1500000010\n"
}
] | code_contests | python | 0 | b3c6d8752dd517c3e02dbfe17111e7b5 |
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero:
<image>
Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero.
This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again.
Input
The first line contains one integer n (1 ≤ n ≤ 15) — the number of rotations.
Each of the following n lines contains one integer a_i (1 ≤ a_i ≤ 180) — the angle of the i-th rotation in degrees.
Output
If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case.
You can print each letter in any case (upper or lower).
Examples
Input
3
10
20
30
Output
YES
Input
3
10
10
10
Output
NO
Input
3
120
120
120
Output
YES
Note
In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.
In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.
In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
a = [0]
for _ in range(n):
curr = int(input())
mods = []
for o in a:
mods.extend([o + curr, o - curr])
a = mods[:]
#print(a)
print("YES" if any(x%360 == 0 for x in a) else "NO")
| python | code_algorithm | [
{
"input": "3\n10\n10\n10\n",
"output": "NO\n"
},
{
"input": "3\n120\n120\n120\n",
"output": "YES\n"
},
{
"input": "3\n10\n20\n30\n",
"output": "YES\n"
},
{
"input": "5\n179\n179\n179\n179\n4\n",
"output": "YES\n"
},
{
"input": "5\n179\n170\n160\n111\n100\n",
"output": "YES\n"
},
{
"input": "4\n1\n178\n180\n1\n",
"output": "YES\n"
},
{
"input": "6\n180\n178\n157\n143\n63\n1\n",
"output": "YES\n"
},
{
"input": "5\n100\n100\n100\n100\n40\n",
"output": "YES\n"
},
{
"input": "9\n80\n80\n80\n80\n80\n80\n80\n80\n80\n",
"output": "YES\n"
},
{
"input": "5\n179\n179\n179\n92\n91\n",
"output": "YES\n"
},
{
"input": "5\n30\n30\n120\n120\n120\n",
"output": "YES\n"
},
{
"input": "9\n1\n2\n4\n8\n16\n32\n64\n128\n76\n",
"output": "NO\n"
},
{
"input": "5\n120\n120\n120\n40\n40\n",
"output": "YES\n"
},
{
"input": "1\n180\n",
"output": "NO\n"
},
{
"input": "15\n168\n168\n168\n168\n168\n168\n168\n168\n168\n168\n168\n168\n168\n168\n168\n",
"output": "YES\n"
},
{
"input": "10\n1\n1\n3\n3\n9\n9\n27\n27\n81\n81\n",
"output": "YES\n"
},
{
"input": "6\n125\n125\n125\n125\n125\n95\n",
"output": "YES\n"
},
{
"input": "8\n1\n2\n4\n8\n16\n32\n64\n128\n",
"output": "NO\n"
},
{
"input": "6\n100\n110\n125\n130\n140\n115\n",
"output": "YES\n"
},
{
"input": "15\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n",
"output": "YES\n"
},
{
"input": "9\n1\n2\n4\n8\n16\n32\n64\n128\n104\n",
"output": "NO\n"
},
{
"input": "5\n179\n178\n177\n176\n10\n",
"output": "YES\n"
},
{
"input": "2\n10\n10\n",
"output": "YES\n"
},
{
"input": "11\n70\n70\n70\n70\n70\n70\n70\n70\n70\n70\n20\n",
"output": "YES\n"
},
{
"input": "14\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n",
"output": "YES\n"
},
{
"input": "15\n49\n52\n58\n34\n40\n43\n49\n55\n34\n52\n43\n55\n55\n46\n55\n",
"output": "YES\n"
},
{
"input": "12\n16\n27\n65\n54\n154\n90\n23\n135\n102\n42\n17\n173\n",
"output": "YES\n"
},
{
"input": "11\n121\n62\n66\n177\n5\n173\n16\n31\n80\n31\n54\n",
"output": "YES\n"
},
{
"input": "5\n144\n144\n144\n144\n144\n",
"output": "YES\n"
},
{
"input": "15\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n180\n",
"output": "NO\n"
},
{
"input": "10\n145\n129\n125\n164\n164\n55\n98\n43\n157\n100\n",
"output": "YES\n"
},
{
"input": "1\n1\n",
"output": "NO\n"
},
{
"input": "11\n1\n1\n3\n3\n9\n9\n27\n27\n81\n81\n117\n",
"output": "NO\n"
},
{
"input": "15\n68\n97\n79\n11\n88\n144\n139\n77\n90\n157\n102\n170\n1\n147\n70\n",
"output": "YES\n"
},
{
"input": "6\n129\n156\n147\n174\n126\n138\n",
"output": "YES\n"
},
{
"input": "2\n180\n180\n",
"output": "YES\n"
},
{
"input": "13\n122\n12\n117\n71\n30\n87\n168\n145\n12\n134\n139\n57\n64\n",
"output": "YES\n"
},
{
"input": "12\n1\n1\n2\n5\n5\n10\n25\n25\n50\n125\n125\n110\n",
"output": "YES\n"
},
{
"input": "15\n100\n10\n14\n2\n3\n11\n10\n1\n3\n7\n6\n5\n4\n3\n1\n",
"output": "NO\n"
},
{
"input": "15\n22\n145\n26\n44\n142\n44\n83\n5\n44\n53\n66\n35\n13\n13\n35\n",
"output": "YES\n"
},
{
"input": "3\n11\n6\n7\n",
"output": "NO\n"
},
{
"input": "5\n40\n170\n170\n170\n170\n",
"output": "YES\n"
},
{
"input": "10\n1\n1\n2\n4\n8\n16\n32\n64\n128\n76\n",
"output": "YES\n"
},
{
"input": "15\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n",
"output": "NO\n"
},
{
"input": "10\n77\n92\n11\n84\n57\n126\n18\n146\n139\n54\n",
"output": "YES\n"
},
{
"input": "10\n151\n172\n68\n9\n8\n1\n18\n116\n59\n117\n",
"output": "NO\n"
}
] | code_contests | python | 0.7 | ff6b0220add66602900a0df63b40522f |
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland. Now Vadim wants to put them back on.
<image>
Vadim wants to put all bulb back on the garland. Vadim defines complexity of a garland to be the number of pairs of adjacent bulbs with numbers with different parity (remainder of the division by 2). For example, the complexity of 1 4 2 3 5 is 2 and the complexity of 1 3 5 7 6 4 2 is 1.
No one likes complexity, so Vadim wants to minimize the number of such pairs. Find the way to put all bulbs back on the garland, such that the complexity is as small as possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of light bulbs on the garland.
The second line contains n integers p_1,\ p_2,\ …,\ p_n (0 ≤ p_i ≤ n) — the number on the i-th bulb, or 0 if it was removed.
Output
Output a single number — the minimum complexity of the garland.
Examples
Input
5
0 5 0 2 3
Output
2
Input
7
1 0 0 5 0 0 2
Output
1
Note
In the first example, one should place light bulbs as 1 5 4 2 3. In that case, the complexity would be equal to 2, because only (5, 4) and (2, 3) are the pairs of adjacent bulbs that have different parity.
In the second case, one of the correct answers is 1 7 3 5 6 4 2.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | def ip():
n=int(input())
a=list(map(int,input().split()))
rem=set([i for i in range(1,n+1)])-set(a)
if n==1:
return 0
o=e=0
for i in rem:
if i%2==0:
e+=1
else:
o+=1
ct=0
i=0
while i<len(a) and a[i]==0:
i+=1
if i==len(a):
return 1
else:
startodd=starteven=endodd=endeven=0
es=[]
os=[]
if i!=0:
if a[i]%2==0:
starteven=i
else:
startodd=i
start=i
i=len(a)-1
end=0
while i>=0 and a[i]==0:
i-=1
end+=1
if end!=0:
if a[i]%2==0:
endeven=end
else:
endodd=end
end=i
prev=start
for i in range(start+1,end+1):
if a[i]==0:
continue
if i-prev>1:
if a[i]%2==0 and a[prev]%2==0:
es.append(i-prev-1)
elif a[i]%2!=0 and a[prev]%2!=0:
os.append(i-prev-1)
else:
ct+=1
elif i-prev==1:
if a[i]%2!=a[prev]%2:
ct+=1
prev=i
os.sort(reverse=True)
es.sort(reverse=True)
while os and os[-1]<=o:
o-=os[-1]
os.pop()
if startodd!=0 and o>=startodd:
o-=startodd
startodd=0
elif startodd!=0:
os.append(startodd)
if endodd!=0 and o>=endodd:
o-=endeven
endodd=0
elif endodd!=0:
os.append(endodd)
ct+=max((len(os))*2,0)
while es and es[-1]<=e:
e-=es[-1]
es.pop()
if starteven!=0 and e>=starteven:
e-=starteven
starteven=0
elif starteven!=0:
es.append(starteven)
if endeven!=0 and e>=endeven:
e-=endeven
endeven=0
elif endeven!=0:
es.append(endeven)
ct+=max((len(es))*2,0)
if startodd!=0 and startodd in os or startodd+o in os:
ct-=1
if starteven!=0 and starteven in es or starteven+e in es:
ct-=1
if endodd!=0 and endodd in os or endodd+o in os:
ct-=1
if endeven!=0 and endeven in es or endeven+e in es:
ct-=1
return ct
print(ip())
| python | code_algorithm | [
{
"input": "7\n1 0 0 5 0 0 2\n",
"output": "1\n"
},
{
"input": "5\n0 5 0 2 3\n",
"output": "2\n"
},
{
"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 48 69 63 77 67 28 7 23 97 99 20 42 50 43 27 81 18 76 87 79 52 37 29 24 65 85 83 68 25 10 45 75 33 15 66 71 6 21 64 47 22 8 39 57 4 1 19 35 12 34 13 9 53 40 62 94 44 90 31\n",
"output": "30\n"
},
{
"input": "1\n0\n",
"output": "0\n"
},
{
"input": "100\n63 0 0 20 0 0 47 0 0 28 0 0 0 19 0 98 0 0 7 0 0 12 0 0 59 0 0 4 0 0 21 0 0 36 0 0 0 65 0 84 0 0 91 0 0 78 0 25 0 0 0 90 0 0 41 0 0 44 0 0 77 0 0 26 0 0 45 0 0 58 0 0 95 0 0 24 0 0 83 0 0 42 0 61 0 0 0 2 0 0 11 0 70 0 0 0 89 0 0 66\n",
"output": "33\n"
},
{
"input": "100\n97 2 21 55 0 0 0 0 75 0 20 0 13 0 0 0 65 84 0 0 0 88 0 15 91 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 71 0 90 0 0 10 68 43 39 0 0 0 0 0 25 50 0 0 0 0 37 0 0 0 0 69 0 0 0 64 0 0 0 0 0 0 53 0 0 56 6 0 0 0 46 0 0 89 0 0 0 0 0 0 0 0 82\n",
"output": "17\n"
},
{
"input": "7\n0 0 0 7 0 0 0\n",
"output": "1\n"
},
{
"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 88 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 51 0 0 0 0 0 0 0 0 0 0 0 0 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "3\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 28 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "1\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 75 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "2\n"
},
{
"input": "100\n0 0 0 0 0 74 0 0 84 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "3\n"
},
{
"input": "20\n1 0 0 13 0 0 16 0 0 4 0 0 7 0 19 0 0 10 0 0\n",
"output": "3\n"
},
{
"input": "20\n13 0 0 12 14 0 19 0 15 0 8 0 7 0 9 0 20 0 0 10\n",
"output": "5\n"
},
{
"input": "100\n0 0 0 0 0 0 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 83 0 70 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "2\n"
},
{
"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 57 0 0 0 0 0 0 0 0 64 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "3\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 55 7 0 0 92 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "2\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 55 0 0 0 0 0 0 0 0 0 86 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 51 0 0 0 0 0 97 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 54 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "3\n"
},
{
"input": "100\n0 0 0 0 0 78 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "3\n"
},
{
"input": "100\n87 32 53 24 60 2 44 15 45 29 69 10 7 95 61 91 86 51 1 30 58 67 49 50 88 23 82 39 14 66 6 19 96 13 12 33 54 41 43 72 21 34 28 59 75 85 65 94 90 80 83 38 62 46 78 81 92 31 35 3 73 4 5 79 98 40 48 8 47 99 20 89 36 77 9 68 11 93 18 100 37 25 22 76 64 55 52 26 71 84 70 97 17 16 74 56 27 42 57 63\n",
"output": "54\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 82 0 0 0 78 0 76 0 0 73 0 0 70 68 0 0 66 0 0 0 0 0 0 0 0 0 0 55 0 53 52 0 50 0 0 0 46 45 44 0 43 0 0 0 0 37 36 0 0 0 0 0 30 0 28 0 26 0 0 22 0 21 20 0 18 0 0 15 0 13 0 0 0 9 0 0 6 0 0 3 0 1\n",
"output": "14\n"
},
{
"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 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "1\n"
},
{
"input": "100\n67 0 83 0 49 0 23 0 55 0 0 9 31 0 25 0 59 0 95 29 0 0 91 0 21 0 85 51 0 0 37 0 7 0 13 0 43 79 0 0 17 0 75 0 35 0 97 0 5 0 71 0 15 0 61 0 3 0 27 0 53 0 81 41 0 0 39 0 87 0 47 0 65 0 11 0 89 0 99 0 45 0 19 0 93 33 0 0 77 0 57 0 73 0 0 1 63 0 69 0\n",
"output": "85\n"
},
{
"input": "100\n100 99 98 97 96 0 0 93 92 0 90 0 0 87 86 85 84 0 0 81 80 79 0 76 0 75 74 0 72 71 0 0 68 67 0 0 64 63 62 61 60 59 58 0 56 55 54 0 52 51 49 0 48 0 46 45 0 43 42 41 0 39 38 37 36 35 0 0 32 31 30 29 28 27 26 0 0 23 22 21 20 19 18 17 0 16 14 0 12 11 10 0 8 0 6 0 0 2 3 1\n",
"output": "55\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "2\n"
},
{
"input": "77\n0 0 0 0 53 0 43 0 0 0 25 0 0 16 0 0 0 0 0 0 0 55 0 50 0 0 0 0 0 0 0 0 0 0 18 21 75 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 57 63 0 0 0 60 0 22 23 0 0 0 0 65 0 17 0 0 0 44 67 0 0 0 31\n",
"output": "10\n"
},
{
"input": "20\n7 0 9 0 5 0 15 0 0 1 17 0 11 19 0 0 3 0 13 0\n",
"output": "15\n"
},
{
"input": "100\n5 42 0 0 4 66 46 98 70 77 0 0 0 0 49 88 0 0 28 54 0 10 0 0 86 0 17 0 0 52 82 71 8 3 0 81 0 0 47 76 0 13 1 0 93 97 94 85 0 84 58 40 0 0 45 65 0 99 51 32 0 0 16 36 0 56 6 79 0 83 68 0 0 0 90 0 67 53 0 0 29 92 0 35 25 22 26 0 37 0 0 0 91 64 89 0 60 0 95 63\n",
"output": "26\n"
},
{
"input": "100\n13 0 0 52 40 62 0 0 0 0 0 82 0 0 98 0 36 75 0 27 0 0 0 4 79 74 46 70 65 0 60 67 18 69 0 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 0 0 77 0 0 76 59 0 91 11 0 0 0 29 0 0 0 54 15 0 0 0 57 0 96 0 0 0 28 0 0 72 44 89 0 95 0 0 99 64 0 90 0 0 0 0 0 0 10\n",
"output": "17\n"
},
{
"input": "100\n43 98 51 37 89 46 0 0 55 54 92 0 67 35 66 88 62 9 13 32 87 79 36 0 0 80 3 73 57 0 31 0 0 52 38 0 0 30 59 0 0 93 100 0 42 0 86 0 94 0 90 0 64 0 82 26 39 40 8 6 91 44 48 0 53 99 85 41 69 0 0 16 0 23 15 97 0 75 10 83 0 0 56 63 61 0 17 0 0 21 58 0 81 70 29 0 34 95 18 19\n",
"output": "34\n"
},
{
"input": "100\n80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "2\n"
},
{
"input": "100\n25 0 0 0 71 0 0 0 0 66 0 0 76 0 0 0 59 0 0 0 69 0 0 0 28 0 0 0 83 0 0 0 6 0 0 0 52 0 0 0 2 0 0 0 81 0 0 31 0 0 0 0 17 0 0 0 78 0 0 0 0 40 0 0 0 14 0 0 9 0 0 0 34 0 0 0 47 0 0 0 24 0 0 0 49 0 0 0 86 0 0 0 42 0 0 0 4 0 0 0\n",
"output": "13\n"
},
{
"input": "100\n0 0 0 78 67 0 0 0 7 20 0 0 0 66 0 0 1 0 0 0 0 0 0 0 0 36 0 0 57 0 0 55 0 34 13 2 0 0 0 0 0 91 0 32 0 0 0 0 0 87 0 0 0 40 0 0 15 0 0 0 0 0 75 0 0 0 0 0 0 35 0 17 0 0 0 71 48 0 0 0 97 0 69 64 0 80 0 0 25 0 9 0 0 6 0 0 0 0 85 0\n",
"output": "19\n"
},
{
"input": "100\n0 29 0 0 23 0 0 0 3 0 0 0 25 0 0 0 73 0 0 63 0 0 0 0 37 0 0 51 0 0 0 0 55 0 0 0 69 0 0 0 33 0 0 0 41 0 0 0 45 0 0 0 61 0 0 0 31 0 0 0 49 0 0 0 91 0 0 0 43 0 0 0 83 0 0 17 0 0 0 0 39 0 0 0 97 0 0 0 27 0 0 0 95 0 0 0 67 0 0 0\n",
"output": "31\n"
},
{
"input": "100\n55 0 0 19 0 0 13 0 0 58 0 73 0 0 0 22 0 0 97 0 0 1 0 0 10 0 0 25 0 0 52 0 0 0 61 0 28 0 0 67 0 0 46 0 0 0 85 0 0 88 0 16 0 0 4 0 0 37 0 0 34 0 0 40 0 43 0 0 0 91 0 0 79 0 0 82 0 0 0 94 0 31 0 0 76 0 0 70 0 0 49 0 0 100 0 0 64 0 0 7\n",
"output": "22\n"
},
{
"input": "100\n35 84 41 46 27 82 81 38 69 24 1 52 0 18 0 0 75 98 11 0 0 40 15 0 43 8 0 0 61 0 12 30 0 0 21 16 31 74 33 0 0 56 0 90 99 68 0 80 53 44 5 64 17 0 0 0 0 48 97 78 0 63 9 10 37 32 0 0 87 0 96 49 93 28 65 0 71 66 79 0 20 14 0 95 0 94 13 0 77 36 85 60 23 0 3 92 73 58 67 0\n",
"output": "58\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 84 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 59 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 0 0 0 0 55 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0\n",
"output": "4\n"
},
{
"input": "100\n0 0 0 4 5 0 0 0 9 0 0 0 0 0 0 0 17 0 0 21 0 23 22 24 0 26 27 28 0 30 0 0 0 0 0 0 0 38 39 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 55 0 57 0 59 60 61 62 0 0 65 0 0 0 0 0 71 72 0 0 0 0 77 78 79 0 0 0 0 0 0 0 0 0 0 90 0 0 93 94 0 0 0 0 98 0\n",
"output": "18\n"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 84 85 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 45 43 41 42 40 39 38 37 36 35 34 33 32 31 30 29 28 27 25 26 24 23 22 21 20 19 18 17 16 14 15 13 12 11 10 9 8 7 6 5 4 3 2 1\n",
"output": "89\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 86 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "1\n"
},
{
"input": "100\n0 15 61 36 45 40 76 56 86 60 42 0 19 11 0 94 0 0 65 32 35 27 54 18 72 4 99 30 95 10 9 81 79 0 0 13 2 66 0 62 77 58 100 50 87 17 41 6 70 78 82 0 89 0 96 0 0 0 51 33 68 55 21 1 24 91 7 0 69 8 0 85 0 0 0 71 28 49 84 48 20 5 14 63 59 73 0 57 52 3 46 31 34 97 0 67 80 23 53 25\n",
"output": "43\n"
},
{
"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 19 0 35 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 0 0 0 0 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "4\n"
},
{
"input": "20\n0 0 0 0 0 0 0 0 0 9 16 19 3 6 11 1 7 4 13 12\n",
"output": "8\n"
},
{
"input": "100\n67 0 54 0 62 0 37 29 0 25 0 0 59 0 2 0 0 11 74 0 12 0 64 0 24 0 94 0 3 26 0 0 41 0 32 0 20 0 16 100 0 0 76 0 82 0 30 0 27 0 49 0 86 0 92 0 90 0 61 0 1 0 72 0 63 0 23 0 48 0 70 0 96 0 33 0 14 0 38 0 9 0 0 47 17 0 0 66 43 0 22 0 97 0 58 0 0 13 39 0\n",
"output": "24\n"
},
{
"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 33 32 34 35 36 38 37 39 40 41 42 43 44 46 45 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 71 70 72 73 74 75 76 77 78 79 80 81 83 82 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"output": "89\n"
},
{
"input": "100\n0 0 41 0 0 0 0 0 0 0 58 30 0 0 0 93 0 0 0 0 0 0 0 0 0 0 0 0 40 12 0 0 0 0 0 0 0 0 0 0 0 85 0 51 0 0 0 0 39 0 0 62 0 0 0 0 20 0 0 0 0 0 0 0 75 27 0 0 0 0 72 0 0 0 0 98 0 0 0 0 0 0 50 0 0 0 0 0 0 38 37 0 0 0 0 0 0 32 0 100\n",
"output": "9\n"
},
{
"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 91 0 0 0 0 0 0 0 0 0 0 83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "1\n"
},
{
"input": "20\n0 0 0 0 0 0 0 0 0 2 0 0 0 0 1 0 19 9 6 0\n",
"output": "3\n"
},
{
"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 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 41 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "1\n"
},
{
"input": "100\n0 0 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "3\n"
},
{
"input": "100\n0 0 77 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 85 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 83 0 0 0 0 0 0 0 43 0 0 0\n",
"output": "4\n"
},
{
"input": "100\n13 92 99 100 89 6 64 32 36 40 62 30 53 31 60 4 54 83 10 59 15 67 47 93 70 41 78 34 20 69 1 74 39 16 95 48 25 80 21 85 50 33 88 71 75 73 77 87 7 5 90 28 14 96 49 57 68 22 8 27 37 86 51 94 11 66 55 29 63 91 45 65 97 23 52 17 81 42 46 35 24 19 44 43 9 84 26 82 2 18 76 56 3 38 72 61 58 98 12 79\n",
"output": "50\n"
},
{
"input": "100\n40 0 54 83 0 0 13 0 87 0 56 0 4 0 6 0 29 0 10 0 69 0 14 0 100 0 24 0 44 0 79 0 93 0 65 0 88 0 81 0 47 0 61 0 45 0 89 0 94 0 0 78 2 49 0 0 0 75 26 0 7 0 57 71 0 0 73 72 0 0 0 5 55 0 18 0 74 0 82 0 9 0 0 80 16 0 36 0 11 0 52 0 84 0 77 0 22 0 42 0\n",
"output": "22\n"
},
{
"input": "100\n57 0 0 0 0 0 41 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 0 0 0 0 0 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 87 0 0 0 0 0\n",
"output": "2\n"
},
{
"input": "100\n83 14 47 29 51 37 76 1 84 61 75 25 42 78 24 0 69 0 10 0 72 34 18 36 98 71 17 46 87 92 6 54 35 73 74 97 2 48 15 52 0 63 7 93 0 70 0 55 91 0 50 43 49 90 81 11 77 33 100 5 94 99 85 65 96 0 30 45 60 44 88 56 40 8 32 68 19 57 26 16 79 23 38 0 20 39 64 3 58 66 62 27 86 12 0 80 67 21 82 59\n",
"output": "48\n"
},
{
"input": "20\n9 0 0 0 18 0 11 0 0 4 0 15 0 0 0 14 0 0 5 0\n",
"output": "6\n"
},
{
"input": "100\n39 0 46 92 0 0 11 0 21 47 0 29 72 20 0 37 31 58 71 0 0 66 4 77 12 44 0 100 0 13 10 0 0 17 0 65 9 28 85 0 0 3 53 14 95 68 33 1 59 18 0 0 87 0 0 0 78 73 0 86 40 55 2 0 6 63 24 0 26 23 88 41 61 0 34 96 76 0 80 5 67 0 0 70 97 49 69 38 89 50 99 8 81 0 0 25 43 0 94 91\n",
"output": "42\n"
},
{
"input": "100\n19 14 13 62 53 48 33 6 65 67 26 50 75 68 7 73 16 86 51 36 93 80 27 40 5 43 52 30 89 44 29 56 1 60 91 58 63 82 31 78 77 8 57 64 97 20 23 22 72 37 83 46 81 28 9 88 3 12 85 54 11 59 66 61 98 100 79 96 69 70 15 18 39 35 34 10 49 21 2 76 41 24 71 99 92 90 47 74 95 42 45 4 25 87 94 84 55 32 17 38\n",
"output": "81\n"
},
{
"input": "100\n0 92 0 75 16 87 0 0 0 0 5 0 0 0 0 60 0 0 52 35 0 17 59 0 0 0 57 0 0 0 0 0 0 0 0 58 41 0 0 0 44 38 0 0 0 0 0 0 68 0 0 67 25 89 0 0 0 0 0 0 0 47 39 0 0 0 0 0 40 0 74 3 0 0 0 0 0 0 0 0 0 81 45 0 0 0 0 0 0 0 0 64 0 0 0 0 0 56 2 11\n",
"output": "13\n"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 55 0 0 0 0 0 0 27 0 0 0 0 0 0 88 0 0 0 0 0 15 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 75 0 0 0 0 0 0 0 0 0 0 0 0 47 0 0 0 0 0 0 71 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 59 0 0 0 6\n",
"output": "7\n"
},
{
"input": "100\n40 94 74 72 0 0 91 0 0 0 37 39 0 93 31 0 52 68 0 30 0 82 99 0 14 41 0 2 92 0 0 0 56 59 84 36 0 0 98 0 0 61 0 0 0 22 0 0 27 69 45 46 0 64 96 90 42 0 9 33 57 0 24 0 4 1 55 28 0 0 70 0 78 0 0 0 0 81 0 71 0 0 60 0 0 18 86 0 0 0 0 0 0 0 0 0 43 0 0 83\n",
"output": "19\n"
},
{
"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\n",
"output": "1\n"
},
{
"input": "100\n57 0 0 48 0 0 60 0 0 3 0 0 77 0 0 26 0 0 89 0 0 7 0 0 69 0 0 68 0 0 44 0 0 82 0 0 71 0 0 88 0 0 76 0 0 0 56 0 42 0 0 61 0 10 0 0 0 98 0 0 84 0 0 74 0 0 72 0 0 79 0 0 65 0 0 23 0 0 1 27 0 0 0 0 17 0 0 93 0 0 21 0 0 85 0 0 18 0 22 0\n",
"output": "11\n"
},
{
"input": "100\n1 0 0 4 5 0 7 0 9 10 11 12 13 0 0 15 17 0 19 20 21 22 23 0 25 26 27 0 0 30 31 0 33 0 0 0 0 39 0 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 0 0 59 60 61 62 0 64 65 0 67 68 69 0 71 72 0 73 75 0 76 79 0 80 0 82 83 0 85 0 0 88 89 90 91 0 93 94 95 0 97 98 99 100\n",
"output": "59\n"
},
{
"input": "100\n32 33 78 99 27 24 31 60 39 62 46 47 18 56 58 12 67 61 83 79 59 11 40 38 88 94 15 4 98 95 49 8 63 91 25 81 3 28 5 41 90 84 64 19 43 96 36 37 30 1 9 13 70 72 69 16 71 23 93 20 77 66 100 54 73 82 35 89 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "37\n"
}
] | code_contests | python | 0 | ee6bfc232475c52144302492db8e5427 |
Slime and his n friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random uniform player among n-1 players except himself. The game stops when one person will have all the biscuits.
As the host of the party, Slime wants to know the expected value of the time that the game will last, to hold the next activity on time.
For convenience, as the answer can be represented as a rational number p/q for coprime p and q, you need to find the value of (p ⋅ q^{-1})mod 998 244 353. You can prove that qmod 998 244 353 ≠ 0.
Input
The first line contains one integer n\ (2≤ n≤ 100 000): the number of people playing the game.
The second line contains n non-negative integers a_1,a_2,...,a_n\ (1≤ a_1+a_2+...+a_n≤ 300 000), where a_i represents the number of biscuits the i-th person own at the beginning.
Output
Print one integer: the expected value of the time that the game will last, modulo 998 244 353.
Examples
Input
2
1 1
Output
1
Input
2
1 2
Output
3
Input
5
0 0 0 0 35
Output
0
Input
5
8 4 2 0 1
Output
801604029
Note
For the first example, in the first second, the probability that player 1 will give the player 2 a biscuit is 1/2, and the probability that player 2 will give the player 1 a biscuit is 1/2. But anyway, the game will stop after exactly 1 second because only one player will occupy all biscuits after 1 second, so the answer is 1.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import os
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
# list(map(int, input().split()))
#####################################################################################
class CF(object):
def __init__(self):
self.mod = 998244353
self.n = int(input())
self.a = list(map(int, input().split()))
self.tot = sum(self.a)
self.dp = [[0,0] for _ in range(self.tot+1)]
def inv(self, x):
return pow(x, self.mod - 2, self.mod)
def gao(self):
self.dp[0] = [0,1]
self.dp[1] = [(1-self.n+self.mod)%self.mod, 1]
for k in range(1, self.tot):
temp = self.inv(self.tot-k)
self.dp[k+1][0] = -self.tot*(self.n - 1) - self.dp[k][0] * (2*k - self.tot- k*self.n) - self.dp[k-1][0] *k*(self.n-1)
self.dp[k+1][0] *= temp
self.dp[k+1][0] = (self.dp[k+1][0] %self.mod+self.mod)%self.mod
self.dp[k+1][1] = -self.dp[k][1]*(2*k - self.tot- k*self.n) - self.dp[k-1][1]*k*(self.n-1)
self.dp[k+1][1] *= temp
self.dp[k+1][1] = (self.dp[k+1][1] %self.mod+self.mod)%self.mod
alpha = -self.dp[self.tot][0]*self.inv(self.dp[self.tot][1])
alpha = (alpha%self.mod + self.mod)%self.mod
#print(alpha)
ans=0
for i in range(self.n):
ans += self.dp[self.a[i]][0] + self.dp[self.a[i]][1] * alpha
ans = (ans%self.mod+self.mod)%self.mod
ans -= alpha * (self.n - 1)
ans = (ans%self.mod+self.mod)%self.mod
ans *= self.inv(self.n)
ans = (ans%self.mod+self.mod)%self.mod
print(ans)
def main(self):
self.gao()
pass
if __name__ == "__main__":
cf = CF()
cf.main()
pass
'''
dp[k+1] *(tot-k) = -tot*(n-1) - dp[k]*(2*k - tot- k*n ) - dp[k-1] *k*(n-1)
''' | python | code_algorithm | [
{
"input": "2\n1 2\n",
"output": "3\n"
},
{
"input": "5\n8 4 2 0 1\n",
"output": "801604029\n"
},
{
"input": "2\n1 1\n",
"output": "1\n"
},
{
"input": "5\n0 0 0 0 35\n",
"output": "0\n"
},
{
"input": "36\n110 7 51 3 36 69 30 7 122 22 11 96 98 17 133 44 38 75 7 10 4 3 68 50 43 25 4 29 42 36 11 7 36 12 75 1\n",
"output": "420723999\n"
},
{
"input": "10\n7758 19921 15137 1138 90104 17467 82544 55151 3999 6781\n",
"output": "663099907\n"
},
{
"input": "100\n4364 698 1003 1128 1513 39 4339 969 7452 3415 1154 1635 6649 136 1442 50 834 1680 107 978 983 3176 4017 1692 1113 1504 1118 396 1975 2053 2366 3022 3007 167 610 4649 14659 2331 4565 318 7232 204 7131 6122 2885 5748 1998 3833 6799 4219 8454 8698 4964 1736 1554 1665 2425 4227 1967 534 2719 80 2865 652 1920 1577 658 1165 3222 1222 1238 560 12018 768 7144 2701 501 2520 9194 8052 13092 7366 2733 6050 2914 1740 5467 546 2947 186 1789 2658 2150 19 1854 1489 7590 990 296 1647\n",
"output": "301328767\n"
},
{
"input": "39\n79 194 29 36 51 363 57 446 559 28 41 34 98 168 555 26 111 97 167 121 749 21 719 20 207 217 226 63 168 248 478 1231 399 518 291 14 741 149 97\n",
"output": "918301015\n"
},
{
"input": "2\n300000 0\n",
"output": "0\n"
},
{
"input": "100\n9 0 2 8 3 6 55 1 11 12 3 8 32 18 38 16 0 27 6 3 3 4 25 2 0 0 7 3 6 16 10 26 5 4 2 38 13 1 7 4 14 8 1 9 5 26 4 8 1 11 3 4 18 2 6 11 5 6 13 9 1 1 1 2 27 0 25 3 2 6 9 5 3 17 17 2 5 1 15 41 2 2 4 4 22 64 10 31 17 7 0 0 3 5 17 20 5 1 1 4\n",
"output": "241327503\n"
},
{
"input": "5\n24348 15401 19543 206086 34622\n",
"output": "788526601\n"
},
{
"input": "2\n0 1\n",
"output": "0\n"
},
{
"input": "2\n184931 115069\n",
"output": "244559876\n"
}
] | code_contests | python | 0 | 095abeddd8f16768d6a4c85eccd435f6 |
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it).
It turned out that the operation does exist (however, it is called tor) and it works like this. Suppose that we need to calculate the value of the expression a tor b. Both numbers a and b are written in the ternary notation one under the other one (b under a). If they have a different number of digits, then leading zeroes are added to the shorter number until the lengths are the same. Then the numbers are summed together digit by digit. The result of summing each two digits is calculated modulo 3. Note that there is no carry between digits (i. e. during this operation the digits aren't transferred). For example: 1410 tor 5010 = 01123 tor 12123 = 10213 = 3410.
Petya wrote numbers a and c on a piece of paper. Help him find such number b, that a tor b = c. If there are several such numbers, print the smallest one.
Input
The first line contains two integers a and c (0 ≤ a, c ≤ 109). Both numbers are written in decimal notation.
Output
Print the single integer b, such that a tor b = c. If there are several possible numbers b, print the smallest one. You should print the number in decimal notation.
Examples
Input
14 34
Output
50
Input
50 34
Output
14
Input
387420489 225159023
Output
1000000001
Input
5 5
Output
0
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | def untor(a, c):
res = ''
while a or c:
a, ma = divmod(a, 3)
c, mc = divmod(c, 3)
x = 0
while (ma + x)%3 != mc:
x += 1
res = str(x) + res
try:
return int(res, 3)
except Exception as e:
return 0
a, c = map(int, input().split())
print(untor(a, c))
| python | code_algorithm | [
{
"input": "387420489 225159023\n",
"output": "1000000001\n"
},
{
"input": "14 34\n",
"output": "50\n"
},
{
"input": "50 34\n",
"output": "14\n"
},
{
"input": "5 5\n",
"output": "0\n"
},
{
"input": "976954722 548418041\n",
"output": "862925051\n"
},
{
"input": "4232 755480607\n",
"output": "755485882\n"
},
{
"input": "640735701 335933492\n",
"output": "992169746\n"
},
{
"input": "5341 813849430\n",
"output": "813850920\n"
},
{
"input": "23476 23875625\n",
"output": "23860906\n"
},
{
"input": "47229813 6200\n",
"output": "89081162\n"
},
{
"input": "657244587 28654748\n",
"output": "921153434\n"
},
{
"input": "278014879 3453211\n",
"output": "171855414\n"
},
{
"input": "5849 7211\n",
"output": "10146\n"
},
{
"input": "417584836 896784933\n",
"output": "481392203\n"
},
{
"input": "19079106 69880743\n",
"output": "56293527\n"
},
{
"input": "922263603 387506683\n",
"output": "1064907553\n"
},
{
"input": "937475611 769913258\n",
"output": "994719535\n"
},
{
"input": "1000000000 100000000\n",
"output": "650219958\n"
},
{
"input": "0 1000000000\n",
"output": "1000000000\n"
},
{
"input": "294567098 631452590\n",
"output": "745235571\n"
},
{
"input": "427471963 436868749\n",
"output": "67345761\n"
},
{
"input": "827112516 566664600\n",
"output": "908742057\n"
},
{
"input": "479225038 396637601\n",
"output": "47143216\n"
},
{
"input": "276659168 241268656\n",
"output": "358409486\n"
},
{
"input": "1000000000 0\n",
"output": "693711461\n"
},
{
"input": "264662333 6952\n",
"output": "141903557\n"
},
{
"input": "785233275 1523\n",
"output": "393767834\n"
},
{
"input": "168971531 697371009\n",
"output": "588009082\n"
},
{
"input": "227651149 379776728\n",
"output": "168088492\n"
},
{
"input": "6560 96330685\n",
"output": "96330968\n"
},
{
"input": "561666539 29904379\n",
"output": "1152454076\n"
},
{
"input": "960725158 342144655\n",
"output": "548529624\n"
},
{
"input": "406369748 625641695\n",
"output": "221459919\n"
},
{
"input": "440760623 316634331\n",
"output": "1052493562\n"
},
{
"input": "551731805 8515539\n",
"output": "1049769112\n"
},
{
"input": "948688087 38251290\n",
"output": "768385433\n"
},
{
"input": "345157805 719310676\n",
"output": "504894191\n"
},
{
"input": "702754885 762686553\n",
"output": "81198815\n"
},
{
"input": "987310001 827978268\n",
"output": "275919178\n"
},
{
"input": "523162963 922976263\n",
"output": "414184806\n"
},
{
"input": "7376 994270908\n",
"output": "994283218\n"
},
{
"input": "8389 172682371\n",
"output": "172696203\n"
},
{
"input": "5712 384487208\n",
"output": "384482225\n"
},
{
"input": "9150 823789822\n",
"output": "823781437\n"
},
{
"input": "2376234 0\n",
"output": "4732515\n"
},
{
"input": "6436017 645491133\n",
"output": "639142839\n"
},
{
"input": "268520356 1999\n",
"output": "135088146\n"
},
{
"input": "227927516 956217829\n",
"output": "872370713\n"
},
{
"input": "3545 6259\n",
"output": "3536\n"
},
{
"input": "460318555 440850074\n",
"output": "25179124\n"
},
{
"input": "532643581 213098335\n",
"output": "842718489\n"
},
{
"input": "581131733 1\n",
"output": "1162260467\n"
},
{
"input": "934045591 4156\n",
"output": "661009836\n"
},
{
"input": "260153932 138945442\n",
"output": "271056231\n"
},
{
"input": "154618752 504073566\n",
"output": "753527130\n"
},
{
"input": "630005197 848951646\n",
"output": "754665575\n"
},
{
"input": "9001 9662\n",
"output": "1390\n"
},
{
"input": "6347 7416\n",
"output": "10549\n"
},
{
"input": "237924125 573400957\n",
"output": "507664538\n"
},
{
"input": "1 23865354\n",
"output": "23865356\n"
},
{
"input": "893244884 654169485\n",
"output": "1095395095\n"
},
{
"input": "9925 9952\n",
"output": "27\n"
},
{
"input": "274842194 1000000000\n",
"output": "1162261466\n"
},
{
"input": "390 380875228\n",
"output": "380874919\n"
},
{
"input": "337894292 55\n",
"output": "243175169\n"
},
{
"input": "991084922 66\n",
"output": "690049933\n"
},
{
"input": "11111 10101010\n",
"output": "10116146\n"
},
{
"input": "1 0\n",
"output": "2\n"
},
{
"input": "364059865 346004232\n",
"output": "40934348\n"
},
{
"input": "336391083 911759145\n",
"output": "1135529718\n"
},
{
"input": "69272798 718909239\n",
"output": "668771236\n"
},
{
"input": "497129325 766959165\n",
"output": "276817557\n"
},
{
"input": "815932189 211656771\n",
"output": "562850021\n"
},
{
"input": "455705795 757666961\n",
"output": "303798597\n"
},
{
"input": "956747697 9487\n",
"output": "736688812\n"
},
{
"input": "931392186 677650263\n",
"output": "923604336\n"
},
{
"input": "621847819 8794\n",
"output": "1114556841\n"
},
{
"input": "44788825 4485\n",
"output": "89397617\n"
},
{
"input": "153749013 598457896\n",
"output": "444892699\n"
},
{
"input": "123256190 174927955\n",
"output": "243699845\n"
},
{
"input": "111174087 482024380\n",
"output": "430083082\n"
},
{
"input": "897312963 177161062\n",
"output": "620860447\n"
},
{
"input": "635318406 289972012\n",
"output": "950864476\n"
},
{
"input": "285938679 907528096\n",
"output": "1068058915\n"
},
{
"input": "783390583 7679\n",
"output": "399664540\n"
},
{
"input": "774578699 101087409\n",
"output": "940495066\n"
},
{
"input": "511307975 307916669\n",
"output": "1137612240\n"
},
{
"input": "847932562 1405\n",
"output": "488901051\n"
},
{
"input": "929361351 7373\n",
"output": "679915097\n"
},
{
"input": "0 0\n",
"output": "0\n"
},
{
"input": "830218526 438129941\n",
"output": "784719357\n"
},
{
"input": "359103580 852\n",
"output": "201115550\n"
},
{
"input": "460311350 820538776\n",
"output": "404875070\n"
},
{
"input": "229485033 8860\n",
"output": "308580772\n"
},
{
"input": "460645829 46697832\n",
"output": "792961330\n"
},
{
"input": "5573 8790\n",
"output": "13021\n"
},
{
"input": "581130733 0\n",
"output": "1162261466\n"
},
{
"input": "9099 3208\n",
"output": "14035\n"
},
{
"input": "5440 6647\n",
"output": "10711\n"
},
{
"input": "8727 702561605\n",
"output": "702556127\n"
},
{
"input": "237819544 904440360\n",
"output": "857959352\n"
}
] | code_contests | python | 0.5 | 784eb82d071bd2a8cf0833dc06c31b5d |
You are given n points on a plane. All points are different.
Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC.
The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are considered the same.
Input
The first line contains a single integer n (3 ≤ n ≤ 3000) — the number of points.
Next n lines contain the points. The i-th line contains coordinates of the i-th point: two space-separated integers xi, yi ( - 1000 ≤ xi, yi ≤ 1000).
It is guaranteed that all given points are different.
Output
Print the single number — the answer to the problem.
Examples
Input
3
1 1
2 2
3 3
Output
1
Input
3
0 0
-1 0
0 1
Output
0
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
points_array = []
cords = []
for i in range(2001):
cords.append([False] * 2001)
for i in range(n):
x, y = [a for a in input().split()]
points_array.append([int(x), int(y)])
cords[int(x)+1000][int(y)+1000] = True
count = 0
for i in range(n):
for j in range(i+1, n):
x1, y1 = points_array[i]
x3, y3 = points_array[j]
x2 = int((x1 + x3)/2)
y2 = int((y1 + y3)/2)
# print(p, q, r, s)
if ((x1 + x3)%2 == 0 and (y1+y3)%2 == 0) and cords[x2+1000][y2+1000]:
count += 1
print(count)
| python | code_algorithm | [
{
"input": "3\n0 0\n-1 0\n0 1\n",
"output": "0\n"
},
{
"input": "3\n1 1\n2 2\n3 3\n",
"output": "1\n"
},
{
"input": "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2 2\n0 2\n-1 -1\n1 -2\n",
"output": "4\n"
},
{
"input": "40\n-8 24\n2 -1\n1 -18\n72 -70\n5 -4\n-308 436\n-19 40\n36 -35\n-178 265\n-1 2\n-7 30\n-1 0\n3 -2\n200 -285\n17 -16\n-35 74\n0 -4\n-86 106\n-1 4\n-7 6\n0 1\n-5 4\n-2 3\n6 -5\n-4 5\n181 -262\n76 -118\n0 0\n-7 18\n-58 104\n-5 6\n-6 12\n-3 4\n1 0\n11 -10\n-86 130\n-3 6\n153 -236\n-183 270\n-33 64\n",
"output": "57\n"
},
{
"input": "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5\n",
"output": "4\n"
},
{
"input": "10\n0 1\n-1 -1\n1 1\n-1 0\n1 -1\n-2 -1\n-2 2\n-2 0\n0 -2\n0 -1\n",
"output": "5\n"
},
{
"input": "20\n-1 18\n-2 5\n-5 4\n2 -33\n9 -18\n0 0\n11 -22\n2 0\n-1 2\n-4 41\n1 6\n1 -2\n6 -12\n0 1\n-3 6\n3 -6\n3 -8\n-1 4\n2 -5\n1 0\n",
"output": "21\n"
},
{
"input": "10\n2 1\n-1 0\n-2 -1\n-1 1\n0 2\n2 -2\n0 0\n-2 -2\n0 -2\n-2 1\n",
"output": "4\n"
},
{
"input": "20\n-3 -3\n0 4\n-3 1\n1 1\n-1 2\n-4 4\n3 -1\n-3 0\n0 2\n4 0\n2 3\n2 4\n4 -3\n-4 3\n-1 1\n1 3\n-2 4\n1 -2\n1 -1\n3 0\n",
"output": "10\n"
},
{
"input": "3\n0 0\n0 -1\n0 1\n",
"output": "1\n"
},
{
"input": "10\n2 1\n-1 1\n0 0\n-3 1\n-2 -3\n-1 -2\n-1 -1\n1 2\n3 -2\n0 -2\n",
"output": "1\n"
},
{
"input": "3\n3 3\n1 2\n1 1\n",
"output": "0\n"
},
{
"input": "4\n0 0\n1 0\n2 0\n3 0\n",
"output": "2\n"
},
{
"input": "9\n1 1\n1 0\n0 1\n0 0\n-1 0\n-1 1\n-1 -1\n1 -1\n0 -1\n",
"output": "8\n"
},
{
"input": "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 0\n",
"output": "3\n"
}
] | code_contests | python | 0.3 | 5202b99edc40630c3d073f26bdcc9c5b |
The Little Elephant has found a ragged old black-and-white string s on the attic.
The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the length of the string. Let's denote the i-th character of string s as si. As the string is black-and-white, each character of the string is either letter "B", or letter "W". Unfortunately, the string is very old and some characters are damaged. The damaged positions are denoted as "X".
The Little Elephant in determined to restore the string and hang it on the wall. For that he needs to replace each character "X" by a "B" or a "W". The string must look good on the wall, so it must be beautiful. The Little Elephant considers a string beautiful if it has two non-intersecting substrings of a given length k, such that the left one fully consists of characters "B", and the right one fully consists of characters "W". More formally, there are four integers a, b, c, d (1 ≤ a ≤ b < c ≤ d ≤ |s|; b - a + 1 = d - c + 1 = k) such that si = "B" (a ≤ i ≤ b) and sj = "W" (c ≤ j ≤ d).
Help the Little Elephant find the number of different beautiful strings he can obtain from string s. Two strings are considered different if there is such position, where the character in the first string differs from the corresponding character in the second string. If this string doesn't contain characters «X» and it is already beautiful — the answer is 1.
As the answer can be rather large, print it modulo 1000000007 (109 + 7).
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 106). The second line contains string s. String s has length n and only consists of characters "W", "B" and "X".
Output
On a single line print an integer — the answer to the problem modulo 1000000007 (109 + 7).
Examples
Input
3 2
XXX
Output
0
Input
4 2
XXXX
Output
1
Input
10 2
XXBXXWXXXX
Output
166
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | Mod=1000000007
n,k=map(int,input().split(' '))
s=' '+input()
f,fs,g,gs,w=[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005
qx,qw,qb=[0]*1000005,[0]*1000005,[0]*1000005
q=0
f[0]=fs[0]=1
for i in range(1,n+1):
lg=(i-k if i-k>=q else q)
if s[i]!='B':
f[i]=fs[i-1]-fs[lg-1]+Mod
f[i]-=(Mod if f[i]>=Mod else 0)
else:
f[i]=0
fs[i]=fs[i-1]+f[i]
fs[i]-=(Mod if fs[i]>=Mod else 0)
if s[i]=='W':
q=i;
g[n+1]=gs[n+1]=1
q=n+1
for i in range(n,0,-1):
rg=(i+k if i+k<=q else q)
if s[i]!='W':
g[i]=gs[i+1]-gs[rg+1]+Mod
g[i]-=(Mod if g[i]>=Mod else 0)
else:
g[i]=0
gs[i]=gs[i+1]+g[i]
gs[i]-=(Mod if gs[i]>=Mod else 0)
if s[i]=='B':
q=i;
for i in range(1,n+1):
qx[i],qb[i],qw[i]=qx[i-1]+(s[i]=='X'),qb[i-1]+(s[i]=='B'),qw[i-1]+(s[i]=='W')
for i in range(n,0,-1):
w[i]=w[i+1]
if s[i]=='X':
w[i]*=2
w[i]-=(Mod if w[i]>=Mod else 0)
if i+k-1<=n:
if qb[i+k-1]-qb[i-1]==0:
w[i]+=g[i+k]
w[i]-=(Mod if w[i]>=Mod else 0)
ans=0
for i in range(k,n+1):
if qw[i]-qw[i-k]==0:
ans=(ans+f[i-k]*w[i+1])%Mod
print(ans) | python | code_algorithm | [
{
"input": "10 2\nXXBXXWXXXX\n",
"output": "166\n"
},
{
"input": "3 2\nXXX\n",
"output": "0\n"
},
{
"input": "4 2\nXXXX\n",
"output": "1\n"
},
{
"input": "4 2\nXXBW\n",
"output": "0\n"
},
{
"input": "2 1\nWB\n",
"output": "0\n"
},
{
"input": "128 100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",
"output": "0\n"
},
{
"input": "25 7\nXWBXWBXWXWBWXBWWXBWXXXXBB\n",
"output": "0\n"
},
{
"input": "1 1\nX\n",
"output": "0\n"
},
{
"input": "2 1\nXW\n",
"output": "1\n"
},
{
"input": "20 6\nXXBXBXXBWWWWXWWXBBBW\n",
"output": "10\n"
},
{
"input": "100 3\nXXXXXWXXXXBXXWXXBXXBXXXXXXXXXXXXXXXXWWXXWXXWXXXXWWXXXXXWXXXXBWXXXXWXBXXXWXXXBWXXWXXXWXXXXWWWXXXXXWXX\n",
"output": "951778854\n"
},
{
"input": "100 21\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",
"output": "135234318\n"
},
{
"input": "3 1\nWBX\n",
"output": "1\n"
},
{
"input": "100 20\nWWXWWXXXXBBXWBXXXXWXXWXXXXXXXBBXXXXXXXWWXXWXXXXBWBXXXXXXXXXXWXWXXXXWXXXWXXWXXXXBXBXXBXXXXXWBXWBXXXXB\n",
"output": "0\n"
},
{
"input": "20 5\nXBBXXXXXXXBWWXBWBWWX\n",
"output": "4\n"
},
{
"input": "3 2\nXWW\n",
"output": "0\n"
},
{
"input": "20 7\nBWXBXBWWXXBBXBBWXWBW\n",
"output": "0\n"
},
{
"input": "300 200\nWXWWWWXWWBXXXBWWXXXWBWWXXWXXXXWWXXXWXXXXWWWXWBWXWWXWXBWXWWWWBWBBWWWWXWXXXXWWXBXWXWWWWWXXXXXWBXWBXWWWWXXXWXBWXBWXWXXXWXWXXWWXXWXWWWWWXWXWWXWWXXWXWXWWXWXXXXWWWXWWWXXWWWBXXWXWWWXWBWXWWXWWXXXWWXXXWXWXXBWXXXBBWWWXXXXWWXWWXWXWWWWWWWXXWXXWWWWBWWWBWWWWXBXWWWWXXXXWXXXXWBXBXWWWXBWXWXXXWXXXXWWXXWXWWXWBXWXBXWWW\n",
"output": "0\n"
},
{
"input": "100 20\nWXWXWWBWBBXXXWWBBXXWBWWWWXXBWXXBXXBXXBXXWXXXXWBBWWWBXWWBXWXWWBXXWXWXWWXXWWWXXXBXBWXWXBXXXWXXWWXWWBWW\n",
"output": "0\n"
},
{
"input": "17 3\nBBBWXXWBXBXWXBXBW\n",
"output": "28\n"
},
{
"input": "2 1\nBW\n",
"output": "1\n"
},
{
"input": "256 100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",
"output": "817953325\n"
},
{
"input": "2 2\nXX\n",
"output": "0\n"
},
{
"input": "100 25\nBXWWXWBWWWWWBXBBWXWWXBBWBWWWWWWWXWXWXXXWWWXXXXBXBBXWXWWXBBXWBXWXWXXXXXWBBXWXXWXWWWBXXWBXWWXBWWBXBXXB\n",
"output": "0\n"
},
{
"input": "3 1\nWWW\n",
"output": "0\n"
},
{
"input": "10 3\nXBXBXWXBXW\n",
"output": "4\n"
},
{
"input": "101 18\nWXXBXXWXXXXXXXXXXXXBBXXBBXXWXBXXBXXXXXXXXBXXXXWBBBXWXXWXWXWXWXWXBXBXXXXXWBXXWXBXXXXXXWXBBXXXXWWXXBWBW\n",
"output": "0\n"
},
{
"input": "4 2\nXBXW\n",
"output": "1\n"
},
{
"input": "4 1\nXXXX\n",
"output": "11\n"
},
{
"input": "100 1\nWBWWWXWWWXWBWXWXWXXWWBWBXWWBBWWWXXWBWWBWWXWWXBBBWBWWWWXBWWWWWXXWWWWBBBWBBBWWWXWWXWBWWBWWWBWWWBWXXWXX\n",
"output": "1048576\n"
},
{
"input": "100 1\nXWXWXWWXXWWXWXXWWXXBXBXWWXXXXWBWWXWXWWXBXWXBWXWWWBWXXWXBBXWXWXWWBXXWBBBWWWXXXWBWXWXWBWBWBWXXWXBXXWWX\n",
"output": "23240159\n"
},
{
"input": "10 1\nXXXWXBXBXX\n",
"output": "126\n"
},
{
"input": "20 4\nWWWWXWBXBBXWWXWXBWWW\n",
"output": "8\n"
},
{
"input": "300 7\nXXWXWWXXWWWBBXXXWWBWBWXWWWXXWBXXBXWWXXXWXWXBXWBWWWXBBWBXBXWXWBBBBXWBXWBBBXBXXXXBWXXXWBBXWXXBBWBBXBBXWXBXWBWXBWXXXXWXBWBBWXWXWXWWBWWWXXWWBBBXBXBWXBXXWWWBWWWBXWWXXWXWBWWWBWWWXXBBWXWXWXXWXXXXBWBXXBXBBBXBBWWXWBBXXWBBXBBXXBWXXWBWWBXWXXWWXXBXBWBWXWBBBWXXWXXWBWBBXWWBBWXXXBBWWXXXXBBBBBBWWBBWBWBXXWWXXBWXWWBB\n",
"output": "469056403\n"
},
{
"input": "3 1\nXBW\n",
"output": "2\n"
},
{
"input": "4 1\nXXXW\n",
"output": "7\n"
},
{
"input": "100 20\nWBBXWBBWWWXBXWWWWWBBBWWBWWBWWWWXWXXBWWBWXWBBXWBWBXWXWXWWBWWWBBXWWBXBBBWBXXWWBXXWWXWXWXBBBWXXWWBWBWXW\n",
"output": "0\n"
},
{
"input": "4 1\nXXWW\n",
"output": "3\n"
},
{
"input": "20 1\nXBBBWBXXBWXWWWBWWXXW\n",
"output": "64\n"
},
{
"input": "2 1\nWX\n",
"output": "0\n"
},
{
"input": "3 1\nXBX\n",
"output": "2\n"
},
{
"input": "20 2\nXXXBXWBBBBWXWWWXWWXB\n",
"output": "128\n"
},
{
"input": "20 3\nBWWWWWXBWXXXXBBWBBWX\n",
"output": "0\n"
},
{
"input": "10 3\nBXBWBWWWWX\n",
"output": "2\n"
},
{
"input": "10 3\nWWXBWXXWWW\n",
"output": "0\n"
}
] | code_contests | python | 0 | b722da3cd56845526cd24b13e9200a99 |
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.
A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is string slsl + 1... sr.
String x = x1x2... xp is lexicographically smaller than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there exists such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The string characters are compared by their ASCII codes.
Input
The first line contains integer n (1 ≤ n ≤ 30) — the number of titles you've got to consider. Then follow n problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive.
Output
Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title.
Examples
Input
5
threehorses
goodsubstrings
secret
primematrix
beautifulyear
Output
j
Input
4
aa
bdefghijklmn
opqrstuvwxyz
c
Output
ab
Note
In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.
In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from itertools import *
alphabet="abcdefghijklmnopqrstuvwxyz";
def isValid(s, names):
for name in names:
if name.find(s)!=-1:
return False
return True
def newProblem(names):
for i in range(1,3):
for s in product(alphabet, repeat=i):
st=""
for c in s:
st+=c
if isValid(st, names):
return st
n=int(input())
names=[]
for i in range(0,n):
name= input()
names.append(name)
print(newProblem(names))
| python | code_algorithm | [
{
"input": "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n",
"output": "ab\n"
},
{
"input": "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n",
"output": "j\n"
},
{
"input": "3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng\n",
"output": "a\n"
},
{
"input": "1\nz\n",
"output": "a\n"
},
{
"input": "30\nb\nu\np\nn\nf\nm\nt\ni\nj\nk\np\nh\na\nc\nw\nz\nz\np\nt\nd\no\nw\nu\nq\nl\ny\ni\no\na\nu\n",
"output": "e\n"
},
{
"input": "5\nsplt\nohqykk\nxqpz\nknojbur\npmfm\n",
"output": "a\n"
},
{
"input": "2\nhk\nobsp\n",
"output": "a\n"
},
{
"input": "5\nzzxpfk\nabcdefghijklmnopqrst\nuvwxz\nsrgkjaskldfkln\nvgnsdfdgfh\n",
"output": "y\n"
},
{
"input": "2\nrxscdzkkezud\nwjehahqgouqvjienq\n",
"output": "b\n"
},
{
"input": "5\nojdfhi\nabcdefghijklmnopqrst\nuvwxyz\nddfhdfhlasjt\nqqq\n",
"output": "aa\n"
},
{
"input": "1\nepkotfpkkrhhmuipmtdk\n",
"output": "a\n"
},
{
"input": "10\nkpmwcdoysw\ngtpr\nkuzoxmiixxbl\ncrgqtuo\njhbplhpklrgwnaugdf\nzuxdaat\naycv\nqwghrkqwkobrgevsjrk\ntdxgc\nlxyzgcmbzulcst\n",
"output": "ab\n"
},
{
"input": "5\ndfijdfhi\nabcdefghijklmnopqrst\nuvwxy\nkopsdfgiopjipw\njty\n",
"output": "z\n"
},
{
"input": "2\nxlaxwpjabtpwddc\ntxwdjmohrrszorrnomc\n",
"output": "e\n"
},
{
"input": "1\na\n",
"output": "b\n"
},
{
"input": "30\nwaiphwcqrrinr\no\nqiqehzmgsjdoqd\nkjexeesevrlowxhghq\njudikhzkj\nz\nxo\nlsdzypkfqro\nsshgcxsky\ngecntpcmoojfwp\nsvmytmcfhc\njrsrvsvbaiumlmkptn\ns\nwpcsovfjlyspviflk\nktvyzvddgllht\nszahigtmklglrcocbo\nznligfxkgxzkcfeu\nliryvzmqwhr\nxgrxkgiehxztv\netrjxdczppafly\njrdgajschhwsci\ndoxnxbjwptnimjmsuijx\nzciwkbvrhgsjhrr\nehh\nbzlnmd\nxpbtbpftimnn\nkhbknqbvdkdd\nmldj\nskrvnyz\navptgpjmenfzfxwckmt\n",
"output": "aa\n"
},
{
"input": "30\ne\nx\nitaubd\nxcn\nv\nx\ni\nci\naqs\nzbi\nq\ncvdu\na\njos\nqy\nfjf\nnayke\nge\ns\nq\nqwad\ngvz\no\nubn\nnzoc\nh\nwnjwjrf\nt\nbq\nbw\n",
"output": "l\n"
},
{
"input": "1\nb\n",
"output": "a\n"
}
] | code_contests | python | 0.6 | d3c8d01bc01bf8532ec18706605d5a89 |
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:
* the Euclidean distance between A and B is one unit and neither A nor B is blocked;
* or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B.
Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick?
Input
The first line contains an integer n (0 ≤ n ≤ 4·107).
Output
Print a single integer — the minimum number of points that should be blocked.
Examples
Input
1
Output
4
Input
2
Output
8
Input
3
Output
16
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from math import sqrt
n = int(input())
if n == 0:
print(1)
else:
print(4 * int(n * sqrt(2)))
| python | code_algorithm | [
{
"input": "2\n",
"output": "8\n"
},
{
"input": "3\n",
"output": "16\n"
},
{
"input": "1\n",
"output": "4\n"
},
{
"input": "11\n",
"output": "60\n"
},
{
"input": "0\n",
"output": "1\n"
},
{
"input": "17\n",
"output": "96\n"
},
{
"input": "18855321\n",
"output": "106661800\n"
},
{
"input": "34609610\n",
"output": "195781516\n"
},
{
"input": "25\n",
"output": "140\n"
},
{
"input": "9\n",
"output": "48\n"
},
{
"input": "40000000\n",
"output": "226274168\n"
},
{
"input": "17464436\n",
"output": "98793768\n"
},
{
"input": "38450759\n",
"output": "217510336\n"
},
{
"input": "395938\n",
"output": "2239760\n"
},
{
"input": "39099999\n",
"output": "221182992\n"
},
{
"input": "8\n",
"output": "44\n"
},
{
"input": "4\n",
"output": "20\n"
},
{
"input": "30426905\n",
"output": "172120564\n"
},
{
"input": "7\n",
"output": "36\n"
},
{
"input": "17082858\n",
"output": "96635236\n"
},
{
"input": "46341\n",
"output": "262144\n"
},
{
"input": "46340\n",
"output": "262136\n"
},
{
"input": "39999996\n",
"output": "226274144\n"
},
{
"input": "6\n",
"output": "32\n"
},
{
"input": "12823666\n",
"output": "72541608\n"
},
{
"input": "39999999\n",
"output": "226274164\n"
},
{
"input": "5\n",
"output": "28\n"
},
{
"input": "5626785\n",
"output": "31829900\n"
},
{
"input": "22578061\n",
"output": "127720800\n"
},
{
"input": "3766137\n",
"output": "21304488\n"
},
{
"input": "13\n",
"output": "72\n"
},
{
"input": "19863843\n",
"output": "112366864\n"
},
{
"input": "24562258\n",
"output": "138945112\n"
},
{
"input": "17590047\n",
"output": "99504332\n"
},
{
"input": "33146037\n",
"output": "187502300\n"
},
{
"input": "2870141\n",
"output": "16235968\n"
},
{
"input": "10\n",
"output": "56\n"
},
{
"input": "14\n",
"output": "76\n"
},
{
"input": "25329968\n",
"output": "143287936\n"
},
{
"input": "39999997\n",
"output": "226274152\n"
},
{
"input": "31975828\n",
"output": "180882596\n"
},
{
"input": "31988776\n",
"output": "180955840\n"
},
{
"input": "31416948\n",
"output": "177721092\n"
},
{
"input": "39268638\n",
"output": "222136960\n"
},
{
"input": "614109\n",
"output": "3473924\n"
},
{
"input": "24483528\n",
"output": "138499748\n"
},
{
"input": "39999998\n",
"output": "226274156\n"
},
{
"input": "15012490\n",
"output": "84923464\n"
},
{
"input": "3107977\n",
"output": "17581372\n"
},
{
"input": "2346673\n",
"output": "13274784\n"
},
{
"input": "34714265\n",
"output": "196373536\n"
},
{
"input": "12\n",
"output": "64\n"
},
{
"input": "15\n",
"output": "84\n"
},
{
"input": "16\n",
"output": "88\n"
},
{
"input": "1059264\n",
"output": "5992100\n"
},
{
"input": "743404\n",
"output": "4205328\n"
}
] | code_contests | python | 0 | 735dd1dcd8428468109a1a076dd40a85 |
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.
Polycarpus believes that if he writes out the population of the capital for several consecutive years in the sequence a1, a2, ..., an, then it is convenient to consider the array as several arithmetic progressions, written one after the other. For example, sequence (8, 6, 4, 2, 1, 4, 7, 10, 2) can be considered as a sequence of three arithmetic progressions (8, 6, 4, 2), (1, 4, 7, 10) and (2), which are written one after another.
Unfortunately, Polycarpus may not have all the data for the n consecutive years (a census of the population doesn't occur every year, after all). For this reason, some values of ai may be unknown. Such values are represented by number -1.
For a given sequence a = (a1, a2, ..., an), which consists of positive integers and values -1, find the minimum number of arithmetic progressions Polycarpus needs to get a. To get a, the progressions need to be written down one after the other. Values -1 may correspond to an arbitrary positive integer and the values ai > 0 must be equal to the corresponding elements of sought consecutive record of the progressions.
Let us remind you that a finite sequence c is called an arithmetic progression if the difference ci + 1 - ci of any two consecutive elements in it is constant. By definition, any sequence of length 1 is an arithmetic progression.
Input
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Output
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
Examples
Input
9
8 6 4 2 1 4 7 10 2
Output
3
Input
9
-1 6 -1 2 -1 4 7 -1 2
Output
3
Input
5
-1 -1 -1 -1 -1
Output
1
Input
7
-1 -1 4 5 1 2 3
Output
2
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
ans += 1
i1 = i
while i1 < n and a[i1] == -1:
i1 += 1
if i1 == n:
break
i2 = i1 + 1
while i2 < n and a[i2] == -1:
i2 += 1
if i2 == n:
break
dist = i2 - i1
step = (a[i2] - a[i1]) // dist
if (a[i2] - a[i1]) % dist != 0 or (step > 0 and a[i1] - (i1 - i) * step <= 0):
i = i2
continue
i3 = i2 + 1
while i3 < n:
nxt = a[i2] + step * (i3 - i2)
if nxt <= 0 or (a[i3] != -1 and a[i3] != nxt):
break
i3 += 1
i = i3
print(ans)
| python | code_algorithm | [
{
"input": "9\n-1 6 -1 2 -1 4 7 -1 2\n",
"output": "3\n"
},
{
"input": "5\n-1 -1 -1 -1 -1\n",
"output": "1\n"
},
{
"input": "7\n-1 -1 4 5 1 2 3\n",
"output": "2\n"
},
{
"input": "9\n8 6 4 2 1 4 7 10 2\n",
"output": "3\n"
},
{
"input": "3\n-1 1 -1\n",
"output": "1\n"
},
{
"input": "4\n45 -1 41 -1\n",
"output": "1\n"
},
{
"input": "1\n-1\n",
"output": "1\n"
},
{
"input": "5\n40 -1 44 46 48\n",
"output": "1\n"
},
{
"input": "6\n43 40 37 34 -1 -1\n",
"output": "1\n"
},
{
"input": "7\n-1 2 4 -1 4 1 5\n",
"output": "3\n"
},
{
"input": "19\n23 26 -1 -1 35 38 41 -1 -1 -1 53 -1 59 62 6 7 8 9 -1\n",
"output": "2\n"
},
{
"input": "6\n-1 2 6 -1 -1 6\n",
"output": "2\n"
},
{
"input": "16\n3 8 13 18 23 -1 -1 -1 43 48 53 45 -1 -1 -1 -1\n",
"output": "2\n"
},
{
"input": "13\n25 24 23 22 24 27 -1 33 -1 2 2 2 -1\n",
"output": "3\n"
},
{
"input": "12\n-1 17 -1 54 -1 64 -1 74 79 84 -1 94\n",
"output": "2\n"
},
{
"input": "8\n-1 12 14 16 18 20 -1 -1\n",
"output": "1\n"
},
{
"input": "13\n2 -1 3 1 3 1 -1 1 3 -1 -1 1 1\n",
"output": "6\n"
},
{
"input": "5\n-1 40 42 -1 46\n",
"output": "1\n"
},
{
"input": "2\n1000000000 -1\n",
"output": "1\n"
},
{
"input": "14\n-1 5 3 -1 -1 31 31 31 -1 31 -1 -1 4 7\n",
"output": "3\n"
},
{
"input": "3\n-1 1000000000 999999999\n",
"output": "1\n"
},
{
"input": "7\n32 33 34 -1 -1 37 38\n",
"output": "1\n"
},
{
"input": "1\n1000000000\n",
"output": "1\n"
},
{
"input": "10\n29 27 -1 23 42 -1 -1 45 -1 -1\n",
"output": "2\n"
},
{
"input": "3\n39 42 -1\n",
"output": "1\n"
},
{
"input": "15\n-1 28 -1 32 34 26 -1 26 -1 -1 26 26 26 -1 -1\n",
"output": "2\n"
},
{
"input": "3\n1000000000 999999999 1000000000\n",
"output": "2\n"
},
{
"input": "17\n-1 -1 -1 -1 64 68 72 -1 45 46 47 48 49 50 51 52 53\n",
"output": "2\n"
},
{
"input": "3\n-1 1 1000000000\n",
"output": "2\n"
},
{
"input": "2\n-1 1000000000\n",
"output": "1\n"
},
{
"input": "3\n999999999 -1 1000000000\n",
"output": "2\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "2\n1000000000 1000000000\n",
"output": "1\n"
},
{
"input": "3\n999999999 1000000000 -1\n",
"output": "1\n"
},
{
"input": "7\n11 8 5 -1 -1 -1 -1\n",
"output": "2\n"
},
{
"input": "3\n-1 1 2\n",
"output": "2\n"
},
{
"input": "2\n-1 21\n",
"output": "1\n"
},
{
"input": "8\n-1 -1 1 7 -1 9 5 2\n",
"output": "3\n"
},
{
"input": "11\n9 21 17 13 -1 -1 -1 -1 -1 -1 -1\n",
"output": "3\n"
},
{
"input": "3\n-1 1000000000 -1\n",
"output": "1\n"
},
{
"input": "6\n-1 6 1 -1 -1 -1\n",
"output": "2\n"
},
{
"input": "1\n65\n",
"output": "1\n"
},
{
"input": "20\n-1 32 37 -1 -1 -1 57 -1 -1 40 31 33 -1 -1 39 47 43 -1 35 32\n",
"output": "5\n"
},
{
"input": "5\n-1 1 7 -1 5\n",
"output": "2\n"
},
{
"input": "18\n21 19 -1 -1 -1 48 50 -1 54 -1 5 1 -1 -1 -1 37 36 35\n",
"output": "4\n"
},
{
"input": "9\n42 39 36 33 -1 -1 -1 34 39\n",
"output": "2\n"
},
{
"input": "2\n-1 -1\n",
"output": "1\n"
}
] | code_contests | python | 0 | e12299c658e08ea2930c63ccc22d6339 |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
Input
The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.
Output
Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.
Examples
Input
aaba
2
Output
6
Input
aaabbbb
2
Output
6
Input
abracadabra
10
Output
20
Note
A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.
In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | s=input()
k=int(input())
n=len(s)
if k>=n:
print(int(2*((n+k)//2)))
raise SystemExit
ll=0
for i in range(k+1):
for l in range((n+i)//2,i-1,-1):
if s[n-(l-i):n]==s[n+i-2*l:n-l]:
if l>ll:
ll=l
break
j=ll
while 2*j<=n:
j=j+1
for i in range(n-2*j):
if s[i:i+j]==s[i+j:i+2*j]:
ll=j
break
print(int(2*ll))
| python | code_algorithm | [
{
"input": "aaabbbb\n2\n",
"output": "6\n"
},
{
"input": "aaba\n2\n",
"output": "6\n"
},
{
"input": "abracadabra\n10\n",
"output": "20\n"
},
{
"input": "jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddhzayvouwhumzhcphocqyfcddayfakoxofjgusuonehbxbokjsdlktqrcdurogxltsysyjbiagrvhky\n32\n",
"output": "64\n"
},
{
"input": "kbxuunznjtxutlauuuipifggjjkequbpvbagmxojhgxtakxioxsmrmoatlyzwsygibhafspqnfbycyztxmtpirqcyhalluhhubne\n100\n",
"output": "200\n"
},
{
"input": "zwvrx\n3\n",
"output": "6\n"
},
{
"input": "wccknxhbqzjwaseubvizxuisnzneatgjhaatrfydssgzufyztesrxnjlbhckybqlbncvqgjcoupirpqnnmacejicjzhattqolmclqnotctcsliyvjwutvrtrhichssehtlwbrq\n123\n",
"output": "246\n"
},
{
"input": "cznjenwypyeulxzdxfhalfbyefhhgieybtzjmbdirrpybxnftpcqfhrhiifsfkllztwejdvhvtnxecnfgwwxhhcsjsqzhrjddauttbxphfzljgbvcqshateqeulxzdxfhalfbyefhhgieybtzjmbdirrpybxnftpcqfhrhiifsfkllztwejdvhvtnxecnfgwwxhhcsjs\n41\n",
"output": "220\n"
},
{
"input": "ezlrqvaeekbnkqqjcijtkaoisqpbguqfsqxtzjotdhtrnaoxutybbqzzhrqvaeekbnkqqjcijtkaoisqpbguqfsqxtzjotdhtrnaoxutybbqzzhzoeptxwaunvarfcapxsnamwjyqpxbiegizqotuqen\n15\n",
"output": "108\n"
},
{
"input": "zumtumtlitf\n2\n",
"output": "6\n"
},
{
"input": "wqlvwkiiqfmesejedhyjjfgzqfmiqyaiqefzaywrdundcmbfvhdflrpvkitbltbrzedvozltptkaanbpmjvsdnpthcepfydrdlscexczxwzyatupzlxdhnezdsipeyjqmbvoavsgeuulkqkexpwpttvxeovcjrqnzdeiaatzglvwkiiqfmesejedhyjjfgzqfmiqyaiq\n141\n",
"output": "334\n"
},
{
"input": "nemtbujbscvkgxnbqboeohzfozihjvhcllfseiouggzojhqcoqrvtdsgkubiophnhahgplhtjxblicnavkayzsydmxphgfvhlllontqfpqitrpjiadpmogtqyjhqfpqitrpjiadpmogtqyjhvaopbzglvdmwzsrhtsszyengbihrrzljvofgugmjedgujhzvlebpprue\n140\n",
"output": "280\n"
},
{
"input": "skllmtqzajnzjkuflkazjku\n10\n",
"output": "20\n"
},
{
"input": "ngkdgsdxouojadjqzgxewuuyxdlxulgrblxpkyzhgmkeatmhvbdelmxxrqtsarfvotcxfuiqsxbnczbadelhxtlfwrnbisayeveiejvycllhkictyyriqseznziyurlgiejvycllhkictyyriqseznziyurlgwiubyvqfmabhstqalicamyholkqlvtjfhcfbyr\n133\n",
"output": "266\n"
},
{
"input": "uzfvkgoaimitrlfjn\n43\n",
"output": "60\n"
},
{
"input": "ijtvifbuajod\n5\n",
"output": "10\n"
},
{
"input": "cxpleheyfwu\n132\n",
"output": "142\n"
},
{
"input": "lfydqwrwevvvclkkainwxwvqf\n33\n",
"output": "58\n"
},
{
"input": "kitxizqtbzwjqldmhwpmznaoddtgqzithwvyeyuixxhlnmksmsysikftzrskbnriebbwzermgcxalwpmznaoddtgqzithwvyeyuixxhlnmksmsy\n32\n",
"output": "120\n"
},
{
"input": "uqytussdzppiuwxterrfyrwtsrkdpfzhjpeuuulopnnjtltdtlkzwixouxteuheqaxhaicoeveggwkcnkamluxykyktmvafajfnxmeuuulopnnjtltdtlkzwixouxteuheqaxhaicoeveggwkcnkamluxykyktmvafajfnxmefkurbbcbesiwcauwmlhmfslcavsreea\n41\n",
"output": "134\n"
},
{
"input": "xaxgnvphqavbuxzkcsptsih\n150\n",
"output": "172\n"
},
{
"input": "zonkpassuptcnpeoogztfpaspwdwnmiwsxeskfajlpfswzrdcxhlzxrgddtgmnngevbiybdnwelkzonhrzgldriyymrzduulifphxypcaqurgeqitkxxnsqdpsxattjoncmhihgxdaxixkmockynyjefvhrzgldriyymrzduulifphxypcaqurgeqitkxxnsqdpsxatt\n200\n",
"output": "400\n"
},
{
"input": "ifglyzxttgfpcgvpfmfmjhuzmgmaiivnbrzjevgxosclwqfewklzstkjmnjmqgpeshndmzrtthpjbhuqoldgvkkmkqinkptatpytrchkvjyeimsfmjhuzmgmaiivnbrzjevgxosclwqfewklzstkjmnjmqgpeshndmzrtthpjbhuqoldgvkkmkqinkptatpytrchkvjy\n15\n",
"output": "186\n"
},
{
"input": "mklxokaoaxzccddmsxzc\n41\n",
"output": "60\n"
},
{
"input": "eluswgbaoqmkfymoidkripnpgmbvhydcuupfhecefgosemhverqwzxklzzacdgcrrlzdnocxmzxtiamqpxspfogqhrlsnfzdexamrkowqpqggolnrvxfhenedmfzngnavgnjkzsnkjjjfcgfqjuywmrt\n115\n",
"output": "230\n"
},
{
"input": "xbmrxbmrkzovhb\n3\n",
"output": "8\n"
},
{
"input": "ktkkckrzvjhdspjmtljrmwgfoxeuadhajkfjpcmquqldlkutwyqaupnypwqfbxbuaaywcflplmqxnvwmkzpdvvkgxkmsggxmdangeyudqrgrihgbljrmwgfoxeuadhajkfjpcmquqldlkutwyqaupnypwqfbxbuaaywcflplmqxnvwmkzpdvvkgxkmsggxmdangeyudq\n57\n",
"output": "190\n"
},
{
"input": "thdnszfpaznmjlzacpovjcvybdkynhnvkaxvncfpofvnfpkggyfvqbklvrnbwpjswbrvjvqyzheslzxvuuqpbrvjvqyzheslzxvuuqprxasesuweenacripkyevplccdlxocfuqklypxactpajkmhcsgbxwgznizwndthualdbbgxhrtdrodoiddzdmxtatssfsuksqz\n23\n",
"output": "46\n"
},
{
"input": "fonwebmlwaxthdwche\n57\n",
"output": "74\n"
},
{
"input": "pdgrwrozhkrwwgebwvuilwm\n32\n",
"output": "54\n"
},
{
"input": "jhfwjyyzwrjiyrrgveiqkoltivghgkontrqragikttxxuwszjwqhwxindyrdqhucnbwgwrppgqmsasrzohezjlfmkzsqptwpratprcrxyxecnlsaiqrvimihmhjfgzwdtvmfhgbuonpsblphyoxzclkrwbwrkasahiirzqlfjdoomlosltldbpomyyhmdwfchzxnmwlh\n200\n",
"output": "400\n"
},
{
"input": "ayi\n10\n",
"output": "12\n"
},
{
"input": "eexlzphiay\n1\n",
"output": "2\n"
},
{
"input": "auxrkguktewrcwwklhmuxkgdialidacmjinwcsrtfrtdsvqsbwuqtsrmsyizsvdkbqwrbuphqqvzktqkskylnnqbezibqnaytuuqddrigdkbqwrbuphqqvzktqkskylnnqbezi\n23\n",
"output": "86\n"
}
] | code_contests | python | 0 | 43d946a1e3e722734967c0dc2fd9f267 |
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill.
Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
Output
Print a single number — the required maximum possible number of pairs.
Examples
Input
4
1 4 6 2
5
5 1 5 7 9
Output
3
Input
4
1 2 3 4
4
10 11 12 13
Output
0
Input
5
1 1 1 1 1
3
1 2 3
Output
2
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))
b.sort()
g.sort()
res = 0
i = 0
j = 0
while i < n and j < m:
if abs(b[i]-g[j]) <= 1:
res += 1
i += 1
j += 1
elif b[i] > g[j]:
j += 1
else:
i += 1
print(res)
| python | code_algorithm | [
{
"input": "4\n1 2 3 4\n4\n10 11 12 13\n",
"output": "0\n"
},
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9\n",
"output": "3\n"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3\n",
"output": "2\n"
},
{
"input": "1\n4\n3\n4 4 4\n",
"output": "1\n"
},
{
"input": "3\n7 7 7\n4\n2 7 2 4\n",
"output": "1\n"
},
{
"input": "3\n5 4 5\n2\n2 1\n",
"output": "0\n"
},
{
"input": "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\n1\n58\n",
"output": "0\n"
},
{
"input": "1\n3\n2\n2 3\n",
"output": "1\n"
},
{
"input": "1\n4\n5\n2 5 5 3 1\n",
"output": "1\n"
},
{
"input": "2\n2 2\n1\n2\n",
"output": "1\n"
},
{
"input": "1\n2\n4\n3 1 4 2\n",
"output": "1\n"
},
{
"input": "5\n5 2 3 1 4\n4\n1 3 1 7\n",
"output": "3\n"
},
{
"input": "2\n2 7\n2\n6 8\n",
"output": "1\n"
},
{
"input": "2\n4 3\n4\n5 5 5 6\n",
"output": "1\n"
},
{
"input": "2\n3 1\n2\n2 4\n",
"output": "2\n"
},
{
"input": "2\n5 6\n3\n1 5 100\n",
"output": "1\n"
},
{
"input": "4\n4 4 6 6\n2\n2 1\n",
"output": "0\n"
},
{
"input": "2\n2 3\n2\n2 1\n",
"output": "2\n"
},
{
"input": "3\n3 2 1\n3\n1 2 3\n",
"output": "3\n"
},
{
"input": "10\n20 87 3 39 20 20 8 40 70 51\n100\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\n",
"output": "6\n"
},
{
"input": "3\n6 3 4\n3\n4 5 2\n",
"output": "3\n"
},
{
"input": "4\n2 5 1 2\n4\n2 3 3 1\n",
"output": "3\n"
},
{
"input": "4\n4 5 4 4\n5\n5 3 4 2 4\n",
"output": "4\n"
},
{
"input": "2\n4 5\n2\n5 3\n",
"output": "2\n"
},
{
"input": "4\n4 10 15 17\n4\n3 12 16 16\n",
"output": "3\n"
},
{
"input": "4\n4 3 2 1\n4\n1 2 3 4\n",
"output": "4\n"
},
{
"input": "1\n2\n1\n1\n",
"output": "1\n"
},
{
"input": "2\n5 5\n4\n1 1 1 5\n",
"output": "1\n"
},
{
"input": "3\n3 1 1\n3\n2 4 4\n",
"output": "2\n"
},
{
"input": "2\n2 4\n3\n3 1 8\n",
"output": "2\n"
},
{
"input": "1\n3\n2\n3 2\n",
"output": "1\n"
},
{
"input": "3\n3 2 1\n3\n2 4 3\n",
"output": "3\n"
},
{
"input": "5\n1 6 5 5 6\n1\n2\n",
"output": "1\n"
},
{
"input": "2\n4 2\n2\n4 4\n",
"output": "1\n"
},
{
"input": "3\n2 7 5\n3\n2 4 8\n",
"output": "3\n"
},
{
"input": "2\n5 7\n5\n4 6 7 2 5\n",
"output": "2\n"
},
{
"input": "4\n9 1 7 1\n5\n9 9 9 8 4\n",
"output": "2\n"
},
{
"input": "5\n9 8 10 9 10\n5\n2 1 5 4 6\n",
"output": "0\n"
},
{
"input": "3\n2 3 5\n3\n3 4 6\n",
"output": "3\n"
},
{
"input": "2\n7 5\n2\n6 8\n",
"output": "2\n"
},
{
"input": "2\n1 10\n1\n9\n",
"output": "1\n"
},
{
"input": "3\n1 2 3\n1\n1\n",
"output": "1\n"
},
{
"input": "2\n2 3\n2\n1 2\n",
"output": "2\n"
},
{
"input": "100\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\n100\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\n",
"output": "76\n"
},
{
"input": "5\n5 2 4 5 6\n2\n7 4\n",
"output": "2\n"
},
{
"input": "100\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\n100\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\n",
"output": "100\n"
},
{
"input": "4\n3 3 5 5\n4\n4 4 2 2\n",
"output": "4\n"
},
{
"input": "2\n1 3\n2\n2 1\n",
"output": "2\n"
},
{
"input": "1\n1\n1\n1\n",
"output": "1\n"
},
{
"input": "4\n1 2 1 3\n1\n4\n",
"output": "1\n"
},
{
"input": "1\n48\n100\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\n",
"output": "1\n"
},
{
"input": "3\n1 3 4\n3\n2 1 5\n",
"output": "3\n"
},
{
"input": "2\n5 4\n2\n4 6\n",
"output": "2\n"
},
{
"input": "100\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\n10\n66 74 40 67 28 82 99 57 93 64\n",
"output": "9\n"
},
{
"input": "2\n10 12\n2\n11 9\n",
"output": "2\n"
},
{
"input": "2\n3 2\n2\n3 4\n",
"output": "2\n"
},
{
"input": "4\n3 1 1 1\n3\n1 6 7\n",
"output": "1\n"
},
{
"input": "5\n1 2 3 4 5\n5\n2 3 4 5 1\n",
"output": "5\n"
},
{
"input": "4\n1 6 9 15\n2\n5 8\n",
"output": "2\n"
},
{
"input": "2\n2 3\n2\n3 1\n",
"output": "2\n"
},
{
"input": "2\n2 4\n2\n3 1\n",
"output": "2\n"
},
{
"input": "5\n4 1 3 1 4\n3\n6 3 6\n",
"output": "1\n"
},
{
"input": "3\n1 2 3\n3\n3 2 1\n",
"output": "3\n"
},
{
"input": "2\n5 3\n2\n4 6\n",
"output": "2\n"
},
{
"input": "2\n4 1\n3\n2 3 2\n",
"output": "2\n"
},
{
"input": "4\n1 1 3 3\n4\n2 2 1 1\n",
"output": "4\n"
},
{
"input": "3\n1 3 3\n5\n1 3 4 1 2\n",
"output": "3\n"
}
] | code_contests | python | 0.9 | 1caed8bba9439bff7c343d1d6fb33035 |
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.
Input
The first line contains four integers n1, n2, k1, k2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output
Output "First" if the first player wins and "Second" otherwise.
Examples
Input
2 2 1 2
Output
Second
Input
2 1 1 1
Output
First
Note
Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n1 , n2 , k1 , k2 = map(int , (input().split(" ")))
if n1 <= n2:
print('Second')
else:
print('First') | python | code_algorithm | [
{
"input": "2 1 1 1\n",
"output": "First\n"
},
{
"input": "2 2 1 2\n",
"output": "Second\n"
},
{
"input": "50 50 50 50\n",
"output": "Second\n"
},
{
"input": "49 49 4 1\n",
"output": "Second\n"
},
{
"input": "48 50 12 11\n",
"output": "Second\n"
},
{
"input": "5 7 1 10\n",
"output": "Second\n"
},
{
"input": "1 50 50 50\n",
"output": "Second\n"
},
{
"input": "5 7 1 4\n",
"output": "Second\n"
},
{
"input": "32 4 17 3\n",
"output": "First\n"
},
{
"input": "1 50 1 50\n",
"output": "Second\n"
},
{
"input": "50 1 1 1\n",
"output": "First\n"
},
{
"input": "32 31 10 9\n",
"output": "First\n"
},
{
"input": "5 7 4 1\n",
"output": "Second\n"
},
{
"input": "49 49 3 3\n",
"output": "Second\n"
},
{
"input": "50 49 1 2\n",
"output": "First\n"
},
{
"input": "50 48 3 1\n",
"output": "First\n"
},
{
"input": "50 1 1 50\n",
"output": "First\n"
},
{
"input": "5 7 10 10\n",
"output": "Second\n"
},
{
"input": "1 1 1 1\n",
"output": "Second\n"
},
{
"input": "49 50 11 12\n",
"output": "Second\n"
}
] | code_contests | python | 0 | 76cc9bdca78d6d780d48e4a2bdc51229 |
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
Input
The first line contains a single integer n (1 ≤ n ≤ 106).
Output
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
Examples
Input
9
Output
9
1 1 1 1 1 1 1 1 1
Input
32
Output
3
10 11 11
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import math
a = input()
d = int(max(a))
print(d)
dec = math.ceil(math.log10(int(a)))
c = [0]*d
if int(a) != 10**dec:
for i in a:
for j in range(int(i)):
c[j] = c[j]+10**(dec-1)
dec = dec - 1
d=''
for i in c:
d += str(i)+' '
if int(a) == 10**dec:
print(a)
else:
print(d.strip()) | python | code_algorithm | [
{
"input": "32\n",
"output": "3\n11 11 10\n"
},
{
"input": "9\n",
"output": "9\n1 1 1 1 1 1 1 1 1\n"
},
{
"input": "111111\n",
"output": "1\n111111\n"
},
{
"input": "100009\n",
"output": "9\n100001 1 1 1 1 1 1 1 1\n"
},
{
"input": "10011\n",
"output": "1\n10011\n"
},
{
"input": "1000000\n",
"output": "1\n1000000\n"
},
{
"input": "8\n",
"output": "8\n1 1 1 1 1 1 1 1\n"
},
{
"input": "10201\n",
"output": "2\n10101 100\n"
},
{
"input": "102030\n",
"output": "3\n101010 1010 10\n"
},
{
"input": "908172\n",
"output": "9\n101111 101011 101010 101010 101010 101010 101010 101000 100000\n"
},
{
"input": "123456\n",
"output": "6\n111111 11111 1111 111 11 1\n"
},
{
"input": "415\n",
"output": "5\n111 101 101 101 1\n"
},
{
"input": "900000\n",
"output": "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000\n"
},
{
"input": "21\n",
"output": "2\n11 10\n"
},
{
"input": "909090\n",
"output": "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010\n"
},
{
"input": "314159\n",
"output": "9\n111111 101011 101011 1011 11 1 1 1 1\n"
},
{
"input": "999999\n",
"output": "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111\n"
},
{
"input": "909823\n",
"output": "9\n101111 101111 101101 101100 101100 101100 101100 101100 101000\n"
},
{
"input": "987654\n",
"output": "9\n111111 111111 111111 111111 111110 111100 111000 110000 100000\n"
},
{
"input": "1453\n",
"output": "5\n1111 111 111 110 10\n"
},
{
"input": "1435\n",
"output": "5\n1111 111 111 101 1\n"
},
{
"input": "98\n",
"output": "9\n11 11 11 11 11 11 11 11 10\n"
},
{
"input": "10\n",
"output": "1\n10\n"
},
{
"input": "2\n",
"output": "2\n1 1\n"
},
{
"input": "1\n",
"output": "1\n1\n"
}
] | code_contests | python | 0.8 | 1ed4789aad00947c02a7a7ed89600e69 |
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them — those with biggest ti.
Your task is to handle queries of two types:
* "1 id" — Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" — Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 ≤ n, q ≤ 150 000, 1 ≤ k ≤ min(6, n)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 ≤ typei ≤ 2, 1 ≤ idi ≤ n) — the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" — Friend 3 becomes online.
2. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" — We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" — Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" — Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" — Print "NO".
7. "2 2" — Print "YES".
8. "2 3" — Print "YES".
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | str1 = input().split()
n = int(str1[0])
k = int(str1[1])
q = int(str1[2])
friends = list(map(lambda x: int(x), input().split()))
online = set()
for i in range(q):
str1 = input().split()
if str1[0] == '2':
if int(str1[1]) in online:
print("YES")
else:
print("NO")
else:
online.add(int(str1[1]))
if len(online) > k:
minelem = int(str1[1])
for on in online:
if friends[on - 1] < friends[minelem - 1]:
minelem = on
online.remove(minelem)
| python | code_algorithm | [
{
"input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n",
"output": "NO\nYES\nNO\nYES\n"
},
{
"input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n",
"output": "NO\nYES\nNO\nYES\nYES\n"
},
{
"input": "1 1 1\n1000000000\n2 1\n",
"output": "NO\n"
},
{
"input": "20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 552903993 633087286 656092270 671535141 714291344 717660646 846508634 879748146 937368929\n2 7\n1 2\n2 4\n1 19\n1 12\n1 5\n2 18\n2 11\n1 16\n2 1\n2 3\n2 19\n1 17\n2 9\n2 6\n",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\n"
},
{
"input": "6 3 10\n62417580 78150524 410053501 582708235 630200761 760672946\n2 2\n1 5\n1 2\n1 4\n2 4\n2 1\n2 1\n1 6\n2 5\n2 6\n",
"output": "NO\nYES\nNO\nNO\nYES\nYES\n"
}
] | code_contests | python | 0.8 | f6150e392f463db467c2695e2591077c |
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.
A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3.
Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X.
Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.
Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.
Input
The only line of the input contains one integer m (1 ≤ m ≤ 1015), meaning that Limak wants you to choose X between 1 and m, inclusive.
Output
Print two integers — the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks.
Examples
Input
48
Output
9 42
Input
6
Output
6 6
Note
In the first sample test, there will be 9 blocks if you choose X = 23 or X = 42. Limak wants to maximize X secondarily so you should choose 42.
In more detail, after choosing X = 42 the process of building a tower is:
* Limak takes a block with side 3 because it's the biggest block with volume not greater than 42. The remaining volume is 42 - 27 = 15.
* The second added block has side 2, so the remaining volume is 15 - 8 = 7.
* Finally, Limak adds 7 blocks with side 1, one by one.
So, there are 9 blocks in the tower. The total volume is is 33 + 23 + 7·13 = 27 + 8 + 7 = 42.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | #!/usr/bin/env python3
import sys
# 1 8 27 64 125 216 343 512 729 1000
# 1-7: blocks of size 1
# 8-15: 1 block of size 2, blocks of size 1
# 16-23: 2 blocks of size 2, blocks of size 1
# 24-26: 3 blocks of size 2, blocks of size 1
# 27-34: 1 block of size 3, blocks of size 1
# Maximum will always be when you have the max number of size 1 blocks
def cube_root(x):
v = max(int(x ** (1.0 / 3.0)) - 1, 0)
while (v + 1) ** 3 <= x:
v += 1
return v
def solution(x):
# returns (n_blocks, volume)
#print("solution {}".format(x))
if x <= 7:
return (x, x)
next_smaller = cube_root(x) ** 3
candidate = solution(x - next_smaller)
candidate = (candidate[0] + 1, candidate[1] + next_smaller)
prenext_smaller = cube_root(next_smaller - 1) ** 3
if next_smaller - prenext_smaller > x - next_smaller:
candidate2 = solution(next_smaller - 1)
else:
candidate2 = candidate
if candidate >= candidate2:
return candidate
else:
return candidate2
n = int(input())
s = solution(n)
print(s[0], s[1])
| python | code_algorithm | [
{
"input": "6\n",
"output": "6 6\n"
},
{
"input": "48\n",
"output": "9 42\n"
},
{
"input": "1000000000000000\n",
"output": "18 999999993541753\n"
},
{
"input": "994\n",
"output": "12 941\n"
},
{
"input": "200385\n",
"output": "14 200355\n"
},
{
"input": "3842529393411\n",
"output": "17 3842529383076\n"
},
{
"input": "8\n",
"output": "7 7\n"
},
{
"input": "409477218238717\n",
"output": "17 409477218238717\n"
},
{
"input": "2\n",
"output": "2 2\n"
},
{
"input": "419477218238718\n",
"output": "18 419466459294818\n"
},
{
"input": "909383000\n",
"output": "16 909381874\n"
},
{
"input": "7\n",
"output": "7 7\n"
},
{
"input": "999088000000000\n",
"output": "18 999087986204952\n"
},
{
"input": "265\n",
"output": "11 212\n"
},
{
"input": "415000000238718\n",
"output": "18 414993991790735\n"
},
{
"input": "780869426483087\n",
"output": "18 780869407920631\n"
},
{
"input": "9\n",
"output": "7 7\n"
},
{
"input": "850085504652042\n",
"output": "18 850085504652042\n"
},
{
"input": "567000123\n",
"output": "16 566998782\n"
},
{
"input": "980123123123123\n",
"output": "18 980123123116482\n"
},
{
"input": "409477218238719\n",
"output": "18 409477218238718\n"
},
{
"input": "385925923480002\n",
"output": "17 385925923479720\n"
},
{
"input": "999998169714888\n",
"output": "18 999998150030846\n"
},
{
"input": "936302451686999\n",
"output": "18 936302448662019\n"
},
{
"input": "114\n",
"output": "11 114\n"
},
{
"input": "999999993700000\n",
"output": "18 999999993541753\n"
},
{
"input": "108000000057\n",
"output": "17 107986074062\n"
},
{
"input": "409477218238716\n",
"output": "17 409477218238710\n"
},
{
"input": "112\n",
"output": "10 106\n"
},
{
"input": "1\n",
"output": "1 1\n"
},
{
"input": "409477218238718\n",
"output": "18 409477218238718\n"
},
{
"input": "999971000299999\n",
"output": "18 999969994441746\n"
},
{
"input": "409477318238718\n",
"output": "18 409477218238718\n"
},
{
"input": "735412349812385\n",
"output": "18 735409591249436\n"
},
{
"input": "113\n",
"output": "10 113\n"
},
{
"input": "999999999999999\n",
"output": "18 999999993541753\n"
},
{
"input": "123830583943\n",
"output": "17 123830561521\n"
},
{
"input": "899990298504716\n",
"output": "18 899973747835553\n"
},
{
"input": "936302451687000\n",
"output": "18 936302448662019\n"
},
{
"input": "995\n",
"output": "12 995\n"
},
{
"input": "990000000000000\n",
"output": "18 989983621692990\n"
},
{
"input": "936302451687001\n",
"output": "18 936302448662019\n"
},
{
"input": "999986542686123\n",
"output": "18 999969994441746\n"
},
{
"input": "850085504652041\n",
"output": "18 850085504650655\n"
}
] | code_contests | python | 0 | 79fd8a7e83559f23b4de4e35ccef6434 |
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.
It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to perform it, and di — the time needed to perform this task in seconds. All ti are distinct.
To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored.
Write the program that determines which tasks will be performed and which will be ignored.
Input
The first line contains two positive integers n and q (1 ≤ n ≤ 100, 1 ≤ q ≤ 105) — the number of servers and the number of tasks.
Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≤ ti ≤ 106, 1 ≤ ki ≤ n, 1 ≤ di ≤ 1000) — the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.
Output
Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.
Examples
Input
4 3
1 3 2
2 2 1
3 4 3
Output
6
-1
10
Input
3 2
3 2 3
5 1 2
Output
3
3
Input
8 6
1 3 20
4 2 1
6 5 5
10 1 1
15 3 6
21 8 8
Output
6
9
30
-1
15
36
Note
In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).
In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, q = map(int, input().split())
servers = [i for i in range(1, n+1)]
res, used = [], {}
for i in range(q):
t, s, d = map(int, input().split())
finish = t + d
for i in list(used.keys()):
if t >= i:
servers += used[i]
servers.sort()
del used[i]
if s > len(servers):
res.append(-1)
continue
if not used.get(finish):
used[finish] = servers[:s]
else:
used[finish] += servers[:s]
res.append(sum(servers[:s]))
servers = servers[s:]
for i in res:
print(i)
| python | code_algorithm | [
{
"input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n",
"output": "6\n9\n30\n-1\n15\n36\n"
},
{
"input": "4 3\n1 3 2\n2 2 1\n3 4 3\n",
"output": "6\n-1\n10\n"
},
{
"input": "3 2\n3 2 3\n5 1 2\n",
"output": "3\n3\n"
},
{
"input": "100 1\n1000000 100 1000\n",
"output": "5050\n"
},
{
"input": "5 3\n1 4 10\n2 2 5\n3 1 6\n",
"output": "10\n-1\n5\n"
},
{
"input": "10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100\n",
"output": "15\n40\n-1\n1\n"
},
{
"input": "5 3\n1 3 4\n4 3 4\n6 4 1\n",
"output": "6\n-1\n10\n"
},
{
"input": "4 1\n6 1 1\n",
"output": "1\n"
},
{
"input": "8 6\n1 3 20\n4 2 1\n6 6 5\n9 1 1\n15 3 6\n21 8 8\n",
"output": "6\n9\n-1\n4\n15\n36\n"
},
{
"input": "4 5\n1 2 3\n2 1 3\n3 1 2\n4 3 3\n5 4 1\n",
"output": "3\n3\n4\n-1\n10\n"
},
{
"input": "8 4\n1 3 2\n2 3 100\n10 6 20\n11 5 20\n",
"output": "6\n15\n-1\n21\n"
},
{
"input": "4 10\n1 1 1\n3 1 2\n4 1 2\n6 1 2\n8 1 2\n13 1 2\n16 1 1\n17 1 2\n19 3 1\n20 1 1\n",
"output": "1\n1\n2\n1\n1\n1\n1\n1\n6\n1\n"
},
{
"input": "5 3\n1 4 4\n4 2 2\n5 5 2\n",
"output": "10\n-1\n15\n"
},
{
"input": "4 3\n1 3 10\n2 2 15\n12 4 1\n",
"output": "6\n-1\n10\n"
},
{
"input": "5 4\n1 1 4\n2 4 4\n5 2 20\n11 5 2\n",
"output": "1\n14\n-1\n15\n"
},
{
"input": "1 10\n4 1 1\n9 1 1\n10 1 1\n12 1 1\n13 1 1\n15 1 1\n16 1 1\n18 1 1\n19 1 1\n20 1 1\n",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"
}
] | code_contests | python | 0.2 | 59caba36a8b66c6e49e33a419559bd07 |
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s1s2...sm is called lexicographically smaller than a string t = t1t2...tm (where s ≠ t) if si < ti where i is the smallest index such that si ≠ ti. (so sj = tj for all j < i)
Input
The first line of input contains a string s of length n (1 ≤ n ≤ 3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
Output
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
Examples
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
Note
One way to play optimally in the first sample is as follows :
* Initially, the company name is ???????.
* Oleg replaces the first question mark with 'f'. The company name becomes f??????.
* Igor replaces the second question mark with 'z'. The company name becomes fz?????.
* Oleg replaces the third question mark with 'f'. The company name becomes fzf????.
* Igor replaces the fourth question mark with 's'. The company name becomes fzfs???.
* Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??.
* Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?.
* Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from sys import *
f = lambda: sorted(stdin.readline()[:-1])
a, b = f(), f()
n = len(a)
u = v = ''
i, j = 0, -1
x, y = n - 1 >> 1, n - 2 >> 1
while x != -1:
if a[i] < b[j]:
u += a[i]
i += 1
else: v += a[i + x]
x -= 1
if y == -1: break
elif a[i] < b[j]:
u += b[j]
j -= 1
else: v += b[j - y]
y -= 1
print(u + v[::-1]) | python | code_algorithm | [
{
"input": "xxxxxx\nxxxxxx\n",
"output": "xxxxxx\n"
},
{
"input": "tinkoff\nzscoder\n",
"output": "fzfsirk\n"
},
{
"input": "ioi\nimo\n",
"output": "ioi\n"
},
{
"input": "bcdef\nabbbc\n",
"output": "bccdb\n"
},
{
"input": "z\ny\n",
"output": "z\n"
},
{
"input": "reddit\nabcdef\n",
"output": "dfdeed\n"
},
{
"input": "abc\naaa\n",
"output": "aab\n"
},
{
"input": "y\nz\n",
"output": "y\n"
},
{
"input": "cbxz\naaaa\n",
"output": "abac\n"
}
] | code_contests | python | 0 | 6101d01668be5113f177d437c3850ee1 |
Absent-minded Masha got set of n cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.
To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.
The number can't contain leading zeros. It's not required to use all cubes to build a number.
Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.
Input
In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday.
Each of next n lines contains 6 integers aij (0 ≤ aij ≤ 9) — number on j-th face of i-th cube.
Output
Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1.
Examples
Input
3
0 1 2 3 4 5
6 7 8 9 0 1
2 3 4 5 6 7
Output
87
Input
3
0 1 3 5 6 8
1 2 4 5 7 8
2 3 4 6 7 9
Output
98
Note
In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
lst = []
for i in range(n):
a = list(map(int,input().split()))
lst.append(a)
cnt = 0
ans = 0
if n == 1:
i = 1
while 1:
if i == 10: break
if i in lst[0]:
i += 1
else:
print(i - 1)
break
elif n == 2:
i = 1
f = 0
while 1:
if i == 10: break
if i in lst[0] or i in lst[1]:
i += 1
else:
print(i - 1)
f = 1
break
if f == 0:
i = 10
while 1:
n1 = int(str(i)[0])
n2 = int(str(i)[1])
if i == 100: break
if n1 in lst[0] and n2 in lst[1] or n1 in lst[1] and n2 in lst[0]:
i += 1
else:
break
print(i - 1)
else:
i = 1
f = 0
while 1:
if i == 10:break
if i in lst[0] or i in lst[1] or i in lst[2]:
i += 1
else:
print(i - 1)
f = 1
break
if f == 0:
i = 10
while 1:
n1 = int(str(i)[0])
n2 = int(str(i)[1])
if i == 100:
print("1")
break
if (n1 in lst[0] and n2 in lst[1]) or (n1 in lst[1] and n2 in lst[0]) or (n1 in lst[0] and n2 in lst[2]) or (n1 in lst[1] and n2 in lst[2]) or (n1 in lst[2] and n2 in lst[1]) or (n1 in lst[2] and n2 in lst[0]) or (n1 in lst[2] and n2 in lst[0]):
i += 1
else:
print(i - 1)
f = 1
break
if f == 0:
i = 100
while 1:
n1 = int(str(i)[0])
n2 = int(str(i)[1])
n3 = int(str(i)[2])
if i == 1000: break
if n1 in lst[0] and n2 in lst[1] and n3 in lst[2] or n1 in lst[1] and n2 in lst[0] and n3 in lst[2] or n1 in lst[1] and n2 in lst[2] and n3 in lst[0] or n1 in lst[2] and n2 in lst[1] and n3 in lst[0] or n1 in lst[2] and n2 in lst[0] and n3 in lst[1] or n1 in lst[0] and n2 in lst[2] and n3 in lst[1]:
i += 1
else:
break
print(i - 1)
| python | code_algorithm | [
{
"input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n",
"output": "98\n"
},
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n",
"output": "87\n"
},
{
"input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n",
"output": "3\n"
},
{
"input": "2\n1 8 9 1 1 0\n2 3 4 5 6 7\n",
"output": "9\n"
},
{
"input": "2\n0 2 9 8 1 7\n6 7 4 3 2 5\n",
"output": "9\n"
},
{
"input": "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n",
"output": "4\n"
},
{
"input": "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 7\n",
"output": "2\n"
},
{
"input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 3 7\n",
"output": "10\n"
},
{
"input": "3\n1 1 1 0 2 3\n4 5 6 7 8 9\n0 0 0 0 0 0\n",
"output": "10\n"
},
{
"input": "1\n1 9 8 3 7 8\n",
"output": "1\n"
},
{
"input": "3\n2 6 3 7 1 0\n9 1 2 4 7 6\n1 4 8 7 6 2\n",
"output": "4\n"
},
{
"input": "1\n4 6 9 8 2 7\n",
"output": "0\n"
},
{
"input": "2\n1 7 6 9 2 5\n1 6 7 0 9 2\n",
"output": "2\n"
},
{
"input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n7 7 2 7 2 2\n",
"output": "5\n"
},
{
"input": "1\n7 6 5 8 9 0\n",
"output": "0\n"
},
{
"input": "3\n3 8 3 5 5 5\n3 0 1 6 6 3\n0 4 3 7 2 4\n",
"output": "8\n"
},
{
"input": "1\n8 1 9 2 9 7\n",
"output": "2\n"
},
{
"input": "2\n2 0 5 7 0 8\n4 5 1 5 4 9\n",
"output": "2\n"
},
{
"input": "3\n1 1 1 1 1 1\n0 2 3 4 5 6\n7 8 9 2 3 4\n",
"output": "10\n"
},
{
"input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 1\n",
"output": "19\n"
},
{
"input": "1\n0 8 7 1 3 2\n",
"output": "3\n"
},
{
"input": "2\n9 3 3 6 7 2\n6 2 9 1 5 9\n",
"output": "3\n"
},
{
"input": "1\n8 2 7 4 1 0\n",
"output": "2\n"
},
{
"input": "2\n3 6 8 9 5 0\n6 7 0 8 2 3\n",
"output": "0\n"
},
{
"input": "1\n0 1 2 3 4 5\n",
"output": "5\n"
},
{
"input": "3\n3 4 5 6 8 9\n1 1 1 1 1 1\n1 2 4 5 7 0\n",
"output": "19\n"
},
{
"input": "2\n2 3 5 1 9 6\n1 6 8 7 3 9\n",
"output": "3\n"
},
{
"input": "2\n0 9 5 7 6 2\n8 6 2 7 1 4\n",
"output": "2\n"
},
{
"input": "2\n4 3 8 6 0 1\n4 7 1 8 9 0\n",
"output": "1\n"
},
{
"input": "1\n6 2 8 4 5 1\n",
"output": "2\n"
},
{
"input": "1\n4 0 9 6 3 1\n",
"output": "1\n"
},
{
"input": "2\n6 0 1 7 2 9\n1 3 4 6 7 0\n",
"output": "4\n"
},
{
"input": "3\n5 0 7 6 2 1\n2 7 4 6 1 9\n0 2 6 1 7 5\n",
"output": "2\n"
},
{
"input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 8\n",
"output": "9\n"
},
{
"input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5\n",
"output": "5\n"
},
{
"input": "2\n2 4 0 3 7 6\n3 2 8 7 1 5\n",
"output": "8\n"
},
{
"input": "1\n7 3 6 9 8 1\n",
"output": "1\n"
},
{
"input": "3\n1 1 2 3 4 5\n6 7 8 9 0 2\n3 4 5 6 7 8\n",
"output": "10\n"
},
{
"input": "3\n9 4 3 0 2 6\n7 0 5 3 3 9\n1 0 7 4 6 7\n",
"output": "7\n"
},
{
"input": "1\n3 7 7 6 4 2\n",
"output": "0\n"
},
{
"input": "3\n2 5 7 4 2 7\n1 5 5 9 0 3\n8 2 0 1 5 1\n",
"output": "5\n"
},
{
"input": "2\n1 7 8 6 0 9\n3 2 1 7 4 9\n",
"output": "4\n"
},
{
"input": "2\n0 8 6 2 1 3\n5 2 7 1 0 9\n",
"output": "3\n"
},
{
"input": "2\n5 3 2 9 8 2\n0 7 4 8 1 8\n",
"output": "5\n"
},
{
"input": "3\n3 8 5 1 5 5\n1 5 7 2 6 9\n4 3 4 8 8 9\n",
"output": "9\n"
},
{
"input": "2\n5 1 2 3 0 8\n3 6 7 4 9 2\n",
"output": "9\n"
},
{
"input": "2\n0 1 2 3 4 5\n6 7 8 9 1 2\n",
"output": "29\n"
},
{
"input": "1\n5 3 8 0 2 6\n",
"output": "0\n"
},
{
"input": "1\n0 7 6 3 2 4\n",
"output": "0\n"
},
{
"input": "2\n8 0 6 5 1 4\n7 1 0 8 3 4\n",
"output": "1\n"
},
{
"input": "2\n7 8 6 1 4 5\n8 6 4 3 2 5\n",
"output": "8\n"
},
{
"input": "2\n0 1 2 3 4 5\n6 6 6 7 8 9\n",
"output": "9\n"
},
{
"input": "3\n9 3 1 8 4 6\n6 9 1 2 0 7\n8 9 1 5 0 3\n",
"output": "21\n"
},
{
"input": "3\n0 6 2 9 5 4\n3 8 0 1 6 9\n6 9 0 1 5 2\n",
"output": "6\n"
},
{
"input": "3\n0 1 2 2 4 5\n6 7 8 9 0 1\n3 3 4 5 6 7\n",
"output": "21\n"
},
{
"input": "1\n1 4 5 7 0 5\n",
"output": "1\n"
},
{
"input": "2\n8 6 4 1 2 0\n7 8 5 3 2 1\n",
"output": "8\n"
},
{
"input": "3\n5 6 2 9 3 5\n5 4 1 5 9 8\n4 4 2 0 3 5\n",
"output": "6\n"
},
{
"input": "1\n9 8 1 6 5 7\n",
"output": "1\n"
},
{
"input": "3\n7 2 1 3 6 9\n0 3 8 4 7 6\n1 4 5 8 7 0\n",
"output": "21\n"
},
{
"input": "3\n9 4 3 3 9 3\n1 0 3 4 5 3\n2 9 6 2 4 1\n",
"output": "6\n"
},
{
"input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8\n",
"output": "3\n"
},
{
"input": "3\n8 1 8 2 7 1\n9 1 9 9 4 7\n0 0 9 0 4 0\n",
"output": "2\n"
},
{
"input": "1\n2 5 9 6 7 9\n",
"output": "0\n"
},
{
"input": "3\n4 6 0 3 9 2\n8 6 9 0 7 2\n6 9 3 2 5 7\n",
"output": "0\n"
},
{
"input": "3\n8 6 0 5 4 9\n1 8 5 3 9 7\n7 4 5 1 6 8\n",
"output": "1\n"
},
{
"input": "1\n8 6 0 9 4 2\n",
"output": "0\n"
},
{
"input": "1\n7 9 2 5 0 4\n",
"output": "0\n"
},
{
"input": "1\n6 0 7 5 4 8\n",
"output": "0\n"
},
{
"input": "2\n5 8 4 7 1 2\n0 8 6 2 4 9\n",
"output": "2\n"
},
{
"input": "1\n5 2 2 5 6 7\n",
"output": "0\n"
},
{
"input": "2\n6 5 2 7 1 3\n3 7 8 1 0 9\n",
"output": "3\n"
},
{
"input": "1\n8 3 5 4 2 9\n",
"output": "0\n"
},
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 1 2\n3 4 5 6 7 8\n",
"output": "98\n"
},
{
"input": "2\n6 6 4 7 9 0\n2 1 2 8 6 4\n",
"output": "2\n"
},
{
"input": "3\n2 3 4 5 6 7\n3 4 5 6 7 8\n9 1 2 3 4 5\n",
"output": "9\n"
},
{
"input": "2\n0 1 2 3 4 5\n4 5 6 7 8 9\n",
"output": "9\n"
},
{
"input": "3\n2 7 3 6 4 5\n0 2 1 9 4 8\n8 6 9 5 4 0\n",
"output": "10\n"
},
{
"input": "2\n0 1 2 3 4 5\n6 7 8 9 6 6\n",
"output": "9\n"
},
{
"input": "2\n1 7 2 0 4 3\n5 2 3 6 1 0\n",
"output": "7\n"
},
{
"input": "1\n6 2 8 5 1 3\n",
"output": "3\n"
},
{
"input": "3\n5 4 8 1 6 7\n0 9 3 5 8 6\n2 4 7 8 1 3\n",
"output": "21\n"
},
{
"input": "1\n6 3 1 9 4 9\n",
"output": "1\n"
},
{
"input": "3\n0 1 9 1 0 8\n9 9 3 5 6 2\n9 3 9 9 7 3\n",
"output": "3\n"
},
{
"input": "3\n8 1 6 8 6 8\n7 0 2 5 8 4\n5 2 0 3 1 9\n",
"output": "32\n"
},
{
"input": "3\n2 0 1 3 4 5\n6 7 8 9 1 1\n3 4 5 6 6 7\n",
"output": "19\n"
},
{
"input": "3\n4 4 5 0 6 6\n7 1 6 9 5 4\n5 0 4 0 3 9\n",
"output": "1\n"
},
{
"input": "2\n0 1 2 3 4 5\n9 8 7 6 5 4\n",
"output": "9\n"
},
{
"input": "2\n0 2 9 1 8 5\n0 7 4 3 2 5\n",
"output": "5\n"
},
{
"input": "2\n2 3 9 1 6 7\n2 5 4 3 0 6\n",
"output": "7\n"
},
{
"input": "2\n5 7 4 2 1 9\n2 2 7 1 1 8\n",
"output": "2\n"
},
{
"input": "1\n3 9 1 7 4 5\n",
"output": "1\n"
},
{
"input": "3\n7 7 2 5 3 2\n3 0 0 6 4 4\n1 2 1 1 9 1\n",
"output": "7\n"
},
{
"input": "1\n7 9 5 0 4 6\n",
"output": "0\n"
},
{
"input": "3\n7 1 3 0 2 4\n2 4 3 0 9 5\n1 9 8 0 6 5\n",
"output": "65\n"
},
{
"input": "1\n4 3 8 9 2 3\n",
"output": "0\n"
}
] | code_contests | python | 0 | a730d56f00277cd47d410b89e3ea0de8 |
An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.
When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.
You are suggested to solve an African crossword and print the word encrypted there.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.
Output
Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.
Examples
Input
3 3
cba
bcd
cbc
Output
abcd
Input
5 5
fcofd
ooedo
afaoa
rdcdf
eofsf
Output
codeforces
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, m = [int(x) for x in input().split()]
lr = []
lc = []
lst = []
for i in range(n):
l = list(input())
lr.append(l)
for i in range(m):
l = []
for j in range(n):
s = lr[j][i]
l.append(s)
lc.append(l)
for i in range(n):
for j in range(m):
s = lr[i][j]
if lr[i].count(s) == 1 and lc[j].count(s) == 1:
lst.append(s)
print("".join(lst)) | python | code_algorithm | [
{
"input": "3 3\ncba\nbcd\ncbc\n",
"output": "abcd\n"
},
{
"input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n",
"output": "codeforces\n"
},
{
"input": "1 2\nfg\n",
"output": "fg\n"
},
{
"input": "3 2\nxe\ner\nwb\n",
"output": "xeerwb\n"
},
{
"input": "7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv\n",
"output": "eklgximpzgfvwcmrrqedoiqptdeiokuorv\n"
},
{
"input": "9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt\n",
"output": "elwtabvyokgmplabqbxlt\n"
},
{
"input": "100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\noc\now\nvh\nqp\nin\neh\npj\nat\nnn\nbr\nij\nco\nlv\nsa\ntb\nbl\nsr\nxa\nbz\nrp\nsz\noi\nec\npw\nhf\njm\nwu\nhq\nra\npv\ntc\ngv\nik\nux\ntz\nbf\nty\ndk\nwo\nor\nza\nkv\nqt\nfa\njy\nbk\nuv\ngk\ncz\nds\nie\noq\nmf\nxn\nql\nxs\nfb\niv\ncj\nkn\nns\nlg\nji\nha\naj\ndg\nfj\nut\nsg\nju\noc\nov\nhe\nnw\nbl\nlp\nbx\nnm\nyq\ncw\nov\nxk\npg\noh\npl\nuo\ngf\nul\n",
"output": "dvy\n"
},
{
"input": "2 2\nzx\nxz\n",
"output": "zxxz\n"
},
{
"input": "100 3\nruy\nmye\njgp\nscn\nktq\nalx\nmvk\nlpm\nkry\norb\nmpu\nzcv\nlge\nkft\ndzp\ntfb\nhqz\nuur\nhry\nzjx\ncuo\nqqc\ntih\nenj\nvnp\nbwi\nzzh\nhkc\nwdr\nldh\nvel\nizj\nfhb\nqrn\nqpp\nvzs\nlhg\nkee\nlbq\nzhy\nwcl\nyaa\nton\nfly\nkyw\nept\ngwq\ncoe\nopd\neez\nnmx\nnjg\nwhy\nvel\nafq\nnbq\nulx\noxs\nbbo\nyhx\nfmz\nnrg\nnfm\njek\nbeu\ntya\nxgs\nsgg\nnkq\nbbv\nwkd\ntns\nfdt\neox\nobc\neab\nkkj\noub\ngji\nrht\nozv\nysk\nsbt\nflf\npbu\nlxb\npzs\nrzh\ncea\nkmi\nuea\nncc\nzng\nvkn\njhn\njqw\nlqc\nmbt\nlov\ngam\n",
"output": "tvdiixs\n"
},
{
"input": "3 1\nk\np\nk\n",
"output": "p\n"
},
{
"input": "5 4\nuzvs\namfz\nwypl\nxizp\nfhmf\n",
"output": "uzvsamfzwyplxizphm\n"
},
{
"input": "3 100\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo\n",
"output": "blkck\n"
},
{
"input": "2 100\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg\n",
"output": "rbe\n"
},
{
"input": "100 1\na\nm\nn\nh\na\nx\nt\na\no\np\nj\nz\nr\nk\nq\nl\nb\nr\no\ni\ny\ni\np\ni\nt\nn\nd\nc\nz\np\nu\nn\nw\ny\ng\ns\nt\nm\nz\ne\nv\ng\ny\nj\nd\nz\ny\na\nn\nx\nk\nd\nq\nn\nv\ng\nk\ni\nk\nf\na\nb\nw\no\nu\nw\nk\nk\nb\nz\nu\ni\nu\nv\ng\nv\nx\ng\np\ni\nz\ns\nv\nq\ns\nb\nw\ne\np\nk\nt\np\nd\nr\ng\nd\nk\nm\nf\nd\n",
"output": "hlc\n"
},
{
"input": "3 7\nnutuvjg\ntgqutfn\nyfjeiot\n",
"output": "ntvjggqfnyfjeiot\n"
},
{
"input": "10 10\naaaaaaaaaa\nbccceeeeee\ncdfffffffe\ncdfiiiiile\ncdfjjjjile\ndddddddile\nedfkkkkile\nedddddddde\ngggggggggg\nhhhhhhhhhe\n",
"output": "b\n"
},
{
"input": "2 1\nh\nj\n",
"output": "hj\n"
},
{
"input": "17 19\nbmzbmweyydiadtlcoue\ngmdbyfwurpwbpuvhifn\nuapwyndmhtqvkgkbhty\ntszotwflegsjzzszfwt\nzfpnscguemwrczqxyci\nvdqnkypnxnnpmuduhzn\noaquudhavrncwfwujpc\nmiggjmcmkkbnjfeodxk\ngjgwxtrxingiqquhuwq\nhdswxxrxuzzfhkplwun\nfagppcoildagktgdarv\neusjuqfistulgbglwmf\ngzrnyxryetwzhlnfewc\nzmnoozlqatugmdjwgzc\nfabbkoxyjxkatjmpprs\nwkdkobdagwdwxsufees\nrvncbszcepigpbzuzoo\n",
"output": "lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs\n"
},
{
"input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz\n",
"output": "bcdeghjlmnprsuvwz\n"
},
{
"input": "1 3\niji\n",
"output": "j\n"
},
{
"input": "1 100\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu\n",
"output": "g\n"
},
{
"input": "1 1\na\n",
"output": "a\n"
},
{
"input": "15 3\njhg\njkn\njui\nfth\noij\nyuf\nyfb\nugd\nhgd\noih\nhvc\nugg\nyvv\ntdg\nhgf\n",
"output": "hkniftjfbctd\n"
},
{
"input": "8 9\ntjqrtgrem\nrwjcfuoey\nywrjgpzca\nwabzggojv\najqmmcclh\nozilebskd\nqmgnbmtcq\nwakptzkjr\n",
"output": "mrjcfuyyrjpzabzvalhozilebskdgnbtpzr\n"
},
{
"input": "4 4\nusah\nusha\nhasu\nsuha\n",
"output": "ahhasusu\n"
},
{
"input": "2 3\nmhw\nbfq\n",
"output": "mhwbfq\n"
},
{
"input": "14 27\npzoshpvvjdpmwfoeojapmkxjrnk\nitoojpcorxjdxrwyewtmmlhjxhx\ndoyopbwusgsmephixzcilxpskxh\nygpvepeuxjbnezdrnjfwdhjwjka\nrfjlbypoalbtjwrpjxzenmeipfg\nkhjhrtktcnajrnbefhpavxxfnlx\nvwlwumqpfegjgvoezevqsolaqhh\npdrvrtzqsoujqfeitkqgtxwckrl\nxtepjflcxcrfomhqimhimnzfxzg\nwhkfkfvvjwkmwhfgeovwowshyhw\nolchgmhiehumivswgtfyhqfagbp\ntdudrkttpkryvaiepsijuejqvmq\nmuratfqqdbfpefmhjzercortroh\nwxkebkzchupxumfizftgqvuwgau\n",
"output": "zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva\n"
}
] | code_contests | python | 0.6 | 30c5492e64669b47b66dc2a7c34c7acd |
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that:
* Each pencil belongs to exactly one box;
* Each non-empty box has at least k pencils in it;
* If pencils i and j belong to the same box, then |ai - aj| ≤ d, where |x| means absolute value of x. Note that the opposite is optional, there can be pencils i and j such that |ai - aj| ≤ d and they belong to different boxes.
Help Mishka to determine if it's possible to distribute all the pencils into boxes. Print "YES" if there exists such a distribution. Otherwise print "NO".
Input
The first line contains three integer numbers n, k and d (1 ≤ k ≤ n ≤ 5·105, 0 ≤ d ≤ 109) — the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively.
The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — saturation of color of each pencil.
Output
Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO".
Examples
Input
6 3 10
7 2 7 7 4 2
Output
YES
Input
6 2 3
4 5 3 13 4 10
Output
YES
Input
3 2 5
10 16 22
Output
NO
Note
In the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10.
In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and put the remaining ones into another box.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, k, d = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
b = [0] * n
i = j = 0
for i in range(n):
while a[i] - a[j] > d:
j += 1
b[i] = j
c = [0] * n
for i in range(k - 1, n):
c[i] = c[i - 1] + int(i - b[i] + 1 >= k and (b[i] == 0 or c[i - k] > c[b[i] - 2] or (b[i] == 1 and c[i-k]> c[0])))
print('YES' if n < 2 or c[n - 1] > c[n - 2] else 'NO') | python | code_algorithm | [
{
"input": "6 3 10\n7 2 7 7 4 2\n",
"output": "YES\n"
},
{
"input": "3 2 5\n10 16 22\n",
"output": "NO\n"
},
{
"input": "6 2 3\n4 5 3 13 4 10\n",
"output": "YES\n"
},
{
"input": "4 2 12\n10 16 22 28\n",
"output": "YES\n"
},
{
"input": "10 3 1\n5 5 5 6 6 7 8 8 8 9\n",
"output": "YES\n"
},
{
"input": "8 7 13\n52 85 14 52 92 33 80 85\n",
"output": "NO\n"
},
{
"input": "10 5 293149357\n79072863 760382815 358896034 663269192 233367425 32795628 837363300 46932461 179556769 763342555\n",
"output": "NO\n"
},
{
"input": "10 3 0\n1 1 2 2 2 2 2 2 2 2\n",
"output": "NO\n"
},
{
"input": "10 4 28\n5 5 6 6 30 30 32 33 50 55\n",
"output": "YES\n"
},
{
"input": "6 2 1\n1 1 2 3 4 5\n",
"output": "YES\n"
},
{
"input": "6 3 3\n1 1 1 1 1 5\n",
"output": "NO\n"
},
{
"input": "4 2 1\n1 1 2 3\n",
"output": "YES\n"
},
{
"input": "6 3 2\n1 2 3 3 4 5\n",
"output": "YES\n"
},
{
"input": "5 2 3\n8 9 11 12 16\n",
"output": "NO\n"
},
{
"input": "10 3 3\n1 1 2 4 5 6 9 10 11 12\n",
"output": "YES\n"
},
{
"input": "6 3 3\n2 2 2 4 7 7\n",
"output": "YES\n"
},
{
"input": "3 2 257816048\n1 999999999 999999999\n",
"output": "NO\n"
},
{
"input": "6 3 2\n1 2 2 3 4 5\n",
"output": "YES\n"
},
{
"input": "9 3 2\n1 2 2 3 4 5 6 7 7\n",
"output": "YES\n"
},
{
"input": "4 2 100\n1 2 3 200\n",
"output": "NO\n"
},
{
"input": "7 3 3\n6 8 9 10 12 13 14\n",
"output": "NO\n"
},
{
"input": "10 3 3\n1 2 3 3 3 3 3 3 3 5\n",
"output": "YES\n"
},
{
"input": "10 4 9\n47 53 33 48 35 51 18 47 33 11\n",
"output": "NO\n"
},
{
"input": "13 2 86\n841 525 918 536 874 186 708 553 770 268 138 529 183\n",
"output": "YES\n"
},
{
"input": "7 3 3\n1 2 4 6 7 8 10\n",
"output": "NO\n"
},
{
"input": "10 3 3\n1 1 1 2 2 5 6 7 8 9\n",
"output": "YES\n"
},
{
"input": "6 2 2\n1 2 3 4 6 7\n",
"output": "YES\n"
},
{
"input": "9 3 3\n1 2 3 4 5 6 7 8 9\n",
"output": "YES\n"
},
{
"input": "18 2 86\n665 408 664 778 309 299 138 622 229 842 498 389 140 976 456 265 963 777\n",
"output": "YES\n"
},
{
"input": "10 4 1\n2 2 2 3 3 10 10 10 11 11\n",
"output": "YES\n"
},
{
"input": "3 2 76\n44 5 93\n",
"output": "NO\n"
},
{
"input": "6 3 3\n1 2 3 4 5 6\n",
"output": "YES\n"
},
{
"input": "8 4 5\n1 1 1 1 1 9 9 9\n",
"output": "NO\n"
},
{
"input": "12 3 2\n1 2 3 9 10 11 12 13 14 15 15 15\n",
"output": "YES\n"
},
{
"input": "8 3 6\n1 2 3 3 4 7 11 11\n",
"output": "YES\n"
},
{
"input": "6 3 3\n1 2 3 4 7 8\n",
"output": "NO\n"
},
{
"input": "10 4 15\n20 16 6 16 13 11 13 1 12 16\n",
"output": "YES\n"
},
{
"input": "4 2 3\n1 2 3 6\n",
"output": "YES\n"
},
{
"input": "7 3 3\n1 1 3 4 4 4 7\n",
"output": "YES\n"
},
{
"input": "6 3 3\n1 1 4 3 3 6\n",
"output": "YES\n"
},
{
"input": "6 3 4\n1 2 3 4 6 7\n",
"output": "YES\n"
},
{
"input": "8 2 3\n1 2 3 4 10 11 12 13\n",
"output": "YES\n"
},
{
"input": "6 2 2\n2 3 4 5 6 8\n",
"output": "YES\n"
},
{
"input": "8 3 3\n1 1 1 2 2 3 3 5\n",
"output": "YES\n"
},
{
"input": "18 3 1\n1 1 1 2 2 3 5 5 5 6 6 7 9 9 9 10 10 11\n",
"output": "YES\n"
},
{
"input": "1 1 1\n1\n",
"output": "YES\n"
},
{
"input": "16 2 2\n3 3 3 4 5 6 7 9 33 33 33 32 31 30 29 27\n",
"output": "YES\n"
},
{
"input": "4 2 4\n9 1 2 3\n",
"output": "NO\n"
},
{
"input": "3 2 2\n6 7 7\n",
"output": "YES\n"
},
{
"input": "5 2 7\n1 3 4 5 10\n",
"output": "YES\n"
},
{
"input": "5 2 9\n3 8 9 14 20\n",
"output": "YES\n"
},
{
"input": "3 2 15\n1 18 19\n",
"output": "NO\n"
},
{
"input": "5 2 3\n1 2 3 4 100\n",
"output": "NO\n"
},
{
"input": "14 2 75\n105 300 444 610 238 62 767 462 17 728 371 578 179 166\n",
"output": "YES\n"
},
{
"input": "7 3 3\n1 2 3 4 4 5 5\n",
"output": "YES\n"
},
{
"input": "10 4 7\n4 3 6 5 4 3 1 8 10 5\n",
"output": "YES\n"
},
{
"input": "6 3 4\n1 1 3 5 8 10\n",
"output": "NO\n"
},
{
"input": "7 2 2\n1 2 3 4 5 6 7\n",
"output": "YES\n"
},
{
"input": "15 8 57\n40 36 10 6 17 84 57 9 55 37 63 75 48 70 53\n",
"output": "NO\n"
},
{
"input": "11 3 4\n1 1 1 5 5 5 10 12 14 16 18\n",
"output": "NO\n"
},
{
"input": "8 3 6\n1 2 3 3 7 4 11 11\n",
"output": "YES\n"
},
{
"input": "6 4 0\n1 3 2 4 2 1\n",
"output": "NO\n"
},
{
"input": "5 2 3\n5 7 7 7 10\n",
"output": "YES\n"
},
{
"input": "9 3 1\n1 2 2 2 2 3 4 4 5\n",
"output": "YES\n"
},
{
"input": "11 3 1\n1 1 2 2 3 3 3 4 4 5 5\n",
"output": "YES\n"
}
] | code_contests | python | 0.1 | a36e6dde64bbeab8cf4b5fdf1498aef7 |
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!
Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and sees his creation demolished, he'll get extremely upset.
To not let that happen, Dima has to recover the binary search tree. Luckily, he noticed that any two vertices connected by a direct edge had their greatest common divisor value exceed 1.
Help Dima construct such a binary search tree or determine that it's impossible. The definition and properties of a binary search tree can be found [here.](https://en.wikipedia.org/wiki/Binary_search_tree)
Input
The first line contains the number of vertices n (2 ≤ n ≤ 700).
The second line features n distinct integers a_i (2 ≤ a_i ≤ 10^9) — the values of vertices in ascending order.
Output
If it is possible to reassemble the binary search tree, such that the greatest common divisor of any two vertices connected by the edge is greater than 1, print "Yes" (quotes for clarity).
Otherwise, print "No" (quotes for clarity).
Examples
Input
6
3 6 9 18 36 108
Output
Yes
Input
2
7 17
Output
No
Input
9
4 8 10 12 15 18 33 44 81
Output
Yes
Note
The picture below illustrates one of the possible trees for the first example.
<image>
The picture below illustrates one of the possible trees for the third example.
<image>
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from math import gcd
import random,time,sys
input=sys.stdin.buffer.readline
def main():
n=int(input())
a=list(map(int,input().split()))
#a=[2*random.randint(1,10**9) for i in range(n)]
start=time.time()
a+=[0]
dp=[[False for j in range(n)] for i in range(n)]
GCD=[0 for i in range(n+1)]
for i in range(n+1):
for j in range(n+1):
if gcd(a[i],a[j])>1:
GCD[i]+=1<<j
check1=[1<<j for j in range(n+1)]
check2=[1<<j for j in range(n+1)]
for i in range(n):
for j in range(n-i):
dp[j][i+j]=bool(check1[j]&check2[i+j])
check1[j]|=int(bool(check1[j]&check2[i+j]&GCD[j+i+1]))*(1<<(i+j+1))
if j!=0:
check2[j+i]|=int(bool(check1[j]&check2[i+j]&GCD[j-1]))*(1<<(j-1))
print("Yes" if dp[0][n-1] else "No")
#print(time.time()-start)
if __name__=="__main__":
main()
| python | code_algorithm | [
{
"input": "9\n4 8 10 12 15 18 33 44 81\n",
"output": "Yes\n"
},
{
"input": "6\n3 6 9 18 36 108\n",
"output": "Yes\n"
},
{
"input": "2\n7 17\n",
"output": "No\n"
},
{
"input": "4\n3 5 7 105\n",
"output": "No\n"
},
{
"input": "13\n2 12 60 300 900 6300 44100 176400 352800 705600 3528000 21168000 148176000\n",
"output": "Yes\n"
},
{
"input": "11\n2 6 15 35 77 143 221 323 437 667 899\n",
"output": "Yes\n"
},
{
"input": "4\n2 3 5 30\n",
"output": "No\n"
},
{
"input": "27\n5 10 29 58 116 174 2297 4594 9188 18376 36752 43643 415757 831514 1663028 2494542 6236355 12472710 22450878 44901756 47396298 68344938 114906990 229813980 306418640 612837280 919255920\n",
"output": "Yes\n"
},
{
"input": "4\n3 7 14 99\n",
"output": "No\n"
},
{
"input": "4\n30 34 57 115\n",
"output": "No\n"
},
{
"input": "14\n122501 245002 367503 735006 1225010 4287535 8575070 21437675 42875350 85750700 171501400 343002800 531654340 823206720\n",
"output": "Yes\n"
},
{
"input": "4\n3 7 13 273\n",
"output": "No\n"
},
{
"input": "9\n2 3 5 7 9 11 13 17 9699690\n",
"output": "No\n"
},
{
"input": "2\n4 6\n",
"output": "Yes\n"
},
{
"input": "6\n2 3 5 7 11 2310\n",
"output": "No\n"
},
{
"input": "25\n2 4 8 10 25 50 100 107903 215806 431612 863224 1726448 3452896 4316120 8632240 17264480 21580600 32370900 64741800 86322400 172644800 193362176 302128400 604256800 841824100\n",
"output": "Yes\n"
},
{
"input": "2\n2 4\n",
"output": "Yes\n"
},
{
"input": "22\n2 4 8 16 32 96 288 576 1728 3456 10368 20736 62208 186624 559872 1119744 3359232 10077696 30233088 90699264 181398528 544195584\n",
"output": "Yes\n"
},
{
"input": "27\n17 34 68 85 170 340 510 1020 1105 22621 45242 90484 113105 226210 452420 565525 2284721 11423605 15993047 47979141 79965235 114236050 124981025 199969640 299954460 599908920 999848200\n",
"output": "Yes\n"
},
{
"input": "4\n14 15 35 39\n",
"output": "No\n"
},
{
"input": "21\n2 1637 8185 16370 32740 49110 98220 106405 532025 671170 1225010 5267543 10535086 21070172 42140344 63210516 94815774 189631548 379263096 568894644 632105160\n",
"output": "Yes\n"
},
{
"input": "36\n3 41 82 123 174 216 432 864 1080 1228 2149 4298 8596 11052 22104 33156 35919 71838 179595 359190 431028 862056 994680 1315440 1753920 3507840 7015680 10523520 21047040 26500200 53000400 106000800 132501000 176668000 353336000 530004000\n",
"output": "Yes\n"
},
{
"input": "5\n3 4 5 7 420\n",
"output": "No\n"
},
{
"input": "5\n11 18 33 44 81\n",
"output": "No\n"
},
{
"input": "6\n5 11 18 33 44 81\n",
"output": "No\n"
},
{
"input": "29\n2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912\n",
"output": "Yes\n"
},
{
"input": "5\n2 3 210 485 707\n",
"output": "No\n"
},
{
"input": "8\n2 3 5 14 33 65 119 187\n",
"output": "No\n"
},
{
"input": "29\n2 4 8 16 24 449 898 1796 3592 5388 16613 33226 66452 132904 199356 398712 689664 1375736 2751472 3439340 6878680 13757360 27514720 52277968 86671368 132501000 265002000 530004000 795006000\n",
"output": "Yes\n"
},
{
"input": "4\n2 3 4 9\n",
"output": "No\n"
},
{
"input": "4\n3 5 6 105\n",
"output": "No\n"
},
{
"input": "4\n2 4 8 16\n",
"output": "Yes\n"
},
{
"input": "5\n2 6 9 10 81\n",
"output": "No\n"
},
{
"input": "4\n23 247 299 703\n",
"output": "No\n"
},
{
"input": "8\n3 7 16 18 36 57 84 90\n",
"output": "No\n"
},
{
"input": "23\n5 10 149 298 397 794 1588 3176 6352 12704 20644 30966 61932 103220 118306 208600 312900 625800 1225010 13107607 249044533 498089066 917532490\n",
"output": "Yes\n"
},
{
"input": "7\n7 38 690 717 11165 75361 104117\n",
"output": "Yes\n"
},
{
"input": "9\n2 3 4 5 7 9 25 49 210\n",
"output": "No\n"
},
{
"input": "5\n2 3 5 7 210\n",
"output": "No\n"
},
{
"input": "7\n2 6 15 35 77 85 143\n",
"output": "No\n"
},
{
"input": "4\n7 12 24 77\n",
"output": "No\n"
},
{
"input": "30\n5 10 14 28 42 3709 7418 11127 14836 29672 44508 55635 74180 148360 222540 445080 778890 1557780 2039646 5778997 11557994 23115988 46231976 92463952 138695928 208043892 312065838 624131676 832175568 928038930\n",
"output": "Yes\n"
},
{
"input": "4\n2 3 4 6\n",
"output": "No\n"
},
{
"input": "27\n13 26 52 104 208 221 442 884 1105 4211 12633 25266 63165 126330 130541 261082 522164 1044328 1305410 1697033 12426661 37279983 111839949 223679898 298239864 385226491 721239025\n",
"output": "Yes\n"
},
{
"input": "24\n13 26 52 104 130 260 520 728 1105 238529 477058 954116 1908232 3816464 4293522 6440283 12880566 20274965 40549930 60824895 121649790 243299580 263574545 527149090\n",
"output": "Yes\n"
},
{
"input": "5\n3 5 7 11 1155\n",
"output": "No\n"
},
{
"input": "30\n3 5 15 30 55 77 154 231 462 770 1540 2310 4569 13707 41121 123363 246726 424917 662505 1987515 5962545 7950060 15900120 23850180 35775270 71550540 132501000 265002000 397503000 795006000\n",
"output": "Yes\n"
},
{
"input": "21\n2 6 18 54 216 432 1296 5184 10368 31104 124416 248832 746496 1492992 2985984 5971968 17915904 53747712 107495424 214990848 644972544\n",
"output": "Yes\n"
},
{
"input": "4\n3 4 9 12\n",
"output": "No\n"
}
] | code_contests | python | 0 | 15693c9a15f9103bc5b486b6de3b0838 |
There are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next d days. There is a coding competition every day in the technical fest.
Every day, in the morning, exactly one student of the college leaves their club. Once a student leaves their club, they will never join any club again. Every day, in the afternoon, the director of the college will select one student from each club (in case some club has no members, nobody is selected from that club) to form a team for this day's coding competition. The strength of a team is the mex of potentials of the students in the team. The director wants to know the maximum possible strength of the team for each of the coming d days. Thus, every day the director chooses such team, that the team strength is maximized.
The mex of the multiset S is the smallest non-negative integer that is not present in S. For example, the mex of the \{0, 1, 1, 2, 4, 5, 9\} is 3, the mex of \{1, 2, 3\} is 0 and the mex of ∅ (empty set) is 0.
Input
The first line contains two integers n and m (1 ≤ m ≤ n ≤ 5000), the number of students and the number of clubs in college.
The second line contains n integers p_1, p_2, …, p_n (0 ≤ p_i < 5000), where p_i is the potential of the i-th student.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ m), which means that i-th student is initially a member of the club with index c_i.
The fourth line contains an integer d (1 ≤ d ≤ n), number of days for which the director wants to know the maximum possible strength of the team.
Each of the next d lines contains an integer k_i (1 ≤ k_i ≤ n), which means that k_i-th student lefts their club on the i-th day. It is guaranteed, that the k_i-th student has not left their club earlier.
Output
For each of the d days, print the maximum possible strength of the team on that day.
Examples
Input
5 3
0 1 2 2 0
1 2 2 3 2
5
3
2
4
5
1
Output
3
1
1
1
0
Input
5 3
0 1 2 2 1
1 3 2 3 2
5
4
2
3
5
1
Output
3
2
2
1
0
Input
5 5
0 1 2 4 5
1 2 3 4 5
4
2
3
5
4
Output
1
1
1
1
Note
Consider the first example:
On the first day, student 3 leaves their club. Now, the remaining students are 1, 2, 4 and 5. We can select students 1, 2 and 4 to get maximum possible strength, which is 3. Note, that we can't select students 1, 2 and 5, as students 2 and 5 belong to the same club. Also, we can't select students 1, 3 and 4, since student 3 has left their club.
On the second day, student 2 leaves their club. Now, the remaining students are 1, 4 and 5. We can select students 1, 4 and 5 to get maximum possible strength, which is 1.
On the third day, the remaining students are 1 and 5. We can select students 1 and 5 to get maximum possible strength, which is 1.
On the fourth day, the remaining student is 1. We can select student 1 to get maximum possible strength, which is 1.
On the fifth day, no club has students and so the maximum possible strength is 0.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
d = int(input())
disable = [False] * n
base = 5001
ds = [int(input())-1 for _ in range(d)]
for ele in ds:
disable[ele] = True
# Create Graph
childs = [[] for i in range(base+m+1)]
for idx, (i, j) in enumerate(zip(p, c)):
if not disable[idx]:
childs[i].append(base+j)
# dfs
# alternative path for finding maximum cardinality
vis = [False]*(base+m+1)
matching = [-1]*(base+m+1)
def dfs(num):
for child in childs[num]:
if not vis[child]:
vis[child] = True
if matching[child] == -1 or dfs(matching[child]):
matching[child] = num
return True
return False
ans = []
mex = 0
for idx in range(d-1, -1, -1):
while True:
vis = [False]*(base+m+1)
if not dfs(mex):
break
mex += 1
# Add edge
ans.append(mex)
childs[p[ds[idx]]].append(base+c[ds[idx]])
print("\n".join([str(a) for a in reversed(ans)])) | python | code_algorithm | [
{
"input": "5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n",
"output": "1\n1\n1\n1\n"
},
{
"input": "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n",
"output": "3\n1\n1\n1\n0\n"
},
{
"input": "5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n",
"output": "3\n2\n2\n1\n0\n"
},
{
"input": "5 5\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n",
"output": "3\n3\n"
},
{
"input": "5 3\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n",
"output": "3\n3\n"
},
{
"input": "10 5\n0 1 1 0 3 1 3 0 2 0\n5 4 3 4 3 4 1 2 3 3\n10\n1\n2\n8\n7\n3\n9\n6\n5\n10\n4\n",
"output": "4\n4\n2\n2\n2\n2\n1\n1\n1\n0\n"
},
{
"input": "10 10\n2 0 3 5 6 1 9 4 7 8\n9 2 5 7 1 6 4 10 8 3\n5\n9\n5\n4\n10\n7\n",
"output": "7\n6\n5\n5\n5\n"
},
{
"input": "10 5\n1 2 0 4 2 4 1 3 4 4\n2 4 4 3 5 1 1 4 4 2\n10\n1\n8\n2\n9\n10\n3\n5\n4\n6\n7\n",
"output": "3\n3\n3\n3\n3\n0\n0\n0\n0\n0\n"
},
{
"input": "10 5\n3 1 4 3 4 2 3 1 0 1\n2 5 3 5 2 5 4 4 1 4\n5\n4\n2\n10\n7\n1\n",
"output": "5\n5\n5\n5\n3\n"
},
{
"input": "20 5\n0 1 418 1718 2027 0 1 2 2 1 433 227 0 1 0 2 0 114 1 1329\n4 5 4 2 4 1 3 1 2 4 5 1 5 2 3 5 3 2 3 4\n10\n20\n12\n11\n18\n5\n3\n4\n9\n16\n8\n",
"output": "3\n3\n3\n3\n3\n3\n3\n3\n3\n2\n"
},
{
"input": "20 20\n10 13 3 14 17 19 0 7 16 5 9 8 12 2 18 6 11 4 15 1\n20 8 17 11 2 10 12 4 19 7 6 3 1 18 16 5 14 13 9 15\n15\n9\n15\n6\n5\n13\n2\n19\n4\n11\n17\n12\n1\n10\n18\n16\n",
"output": "16\n16\n16\n16\n12\n12\n12\n12\n9\n9\n8\n8\n5\n4\n4\n"
},
{
"input": "10 5\n1 0 1 4 2 4 4 0 1 1\n4 4 4 5 2 1 4 2 3 5\n5\n1\n6\n3\n2\n7\n",
"output": "3\n3\n3\n2\n2\n"
},
{
"input": "20 8\n1 17 10 12 13 7 14 9 16 15 6 3 11 18 19 8 4 2 0 5\n8 6 3 4 4 8 5 8 3 7 4 2 4 5 7 1 4 6 4 1\n8\n13\n17\n20\n11\n3\n16\n2\n4\n",
"output": "4\n4\n4\n4\n4\n4\n4\n4\n"
},
{
"input": "10 10\n8 5 1 3 9 2 7 0 6 4\n6 4 8 2 7 9 5 1 10 3\n10\n9\n2\n1\n7\n5\n6\n8\n3\n10\n4\n",
"output": "6\n5\n5\n5\n5\n2\n0\n0\n0\n0\n"
},
{
"input": "20 5\n6 3 8 0 0 2 7 5 7 1059 9 4 9 3457 1 3 8 988 6 8\n1 4 2 3 2 2 4 1 1 5 1 5 1 3 1 5 2 5 3 4\n10\n3\n11\n12\n19\n18\n10\n17\n13\n8\n14\n",
"output": "5\n5\n4\n4\n4\n4\n4\n4\n4\n4\n"
},
{
"input": "10 5\n9 7 8 0 1 4 5 2 6 3\n5 5 4 4 2 2 1 3 4 5\n5\n9\n6\n10\n5\n1\n",
"output": "4\n4\n3\n1\n1\n"
},
{
"input": "1 1\n0\n1\n1\n1\n",
"output": "0\n"
},
{
"input": "20 20\n0 0 3 2 1 2 2 3 2 2 1 1 0 3 0 0 1 1 1 3\n15 1 20 13 6 12 16 8 3 14 10 5 18 17 4 9 2 11 7 19\n20\n2\n10\n7\n4\n6\n5\n14\n8\n9\n18\n13\n11\n19\n1\n16\n20\n17\n12\n15\n3\n",
"output": "4\n4\n4\n4\n4\n4\n4\n4\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n0\n0\n"
},
{
"input": "10 5\n5 1 9 7 3 2 8 0 6 4\n1 1 1 5 4 3 2 5 2 4\n10\n9\n3\n5\n7\n10\n6\n1\n4\n2\n8\n",
"output": "4\n4\n3\n3\n3\n2\n2\n2\n1\n0\n"
}
] | code_contests | python | 0 | 4b58e061ed00b5dabdbb3a121b4cfeba |
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representing a number that does not exceed b. Here a and b are some given constants, s1 and s2 are chosen by the players. The strings are allowed to contain leading zeroes.
If a number obtained by the concatenation (joining together) of strings s1 and s2 is divisible by mod, then the second player wins. Otherwise the first player wins. You are given numbers a, b, mod. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.
Input
The first line contains three integers a, b, mod (0 ≤ a, b ≤ 109, 1 ≤ mod ≤ 107).
Output
If the first player wins, print "1" and the lexicographically minimum string s1 he has to write to win. If the second player wins, print the single number "2".
Examples
Input
1 10 7
Output
2
Input
4 0 9
Output
1 000000001
Note
The lexical comparison of strings is performed by the < operator in modern programming languages. String x is lexicographically less than string y if exists such i (1 ≤ i ≤ 9), that xi < yi, and for any j (1 ≤ j < i) xj = yj. These strings always have length 9.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | a, b, m = map(int, input().split())
k = s = 10 ** 9 % m
i = 0
while k and i < a:
i += 1
if k < m - b: exit(print(1, str(i).zfill(9)))
k += s
if k >= m: k -= m
print(2) | python | code_algorithm | [
{
"input": "4 0 9\n",
"output": "1 000000001\n"
},
{
"input": "1 10 7\n",
"output": "2\n"
},
{
"input": "1 2 11\n",
"output": "2\n"
},
{
"input": "576695 1234562 1234567\n",
"output": "1 000576695\n"
},
{
"input": "138 11711 11829\n",
"output": "2\n"
},
{
"input": "1000000000 100050 1000001\n",
"output": "1 000000101\n"
},
{
"input": "116482865 344094604 3271060\n",
"output": "2\n"
},
{
"input": "0 3 3\n",
"output": "2\n"
},
{
"input": "0 0 1\n",
"output": "2\n"
},
{
"input": "7004769 3114686 4659684\n",
"output": "1 000000002\n"
},
{
"input": "0 1 1\n",
"output": "2\n"
},
{
"input": "100 2 3\n",
"output": "2\n"
},
{
"input": "4 3 12\n",
"output": "1 000000001\n"
},
{
"input": "0 1000000000 10000000\n",
"output": "2\n"
},
{
"input": "6 4 10\n",
"output": "2\n"
},
{
"input": "0 7 13\n",
"output": "2\n"
},
{
"input": "3 0 3\n",
"output": "1 000000001\n"
},
{
"input": "1 1 1\n",
"output": "2\n"
},
{
"input": "1 0 11\n",
"output": "1 000000001\n"
},
{
"input": "1 0 3\n",
"output": "1 000000001\n"
},
{
"input": "0 1 3\n",
"output": "2\n"
},
{
"input": "9902593 9902584 9902593\n",
"output": "1 002490619\n"
},
{
"input": "1 0 7\n",
"output": "1 000000001\n"
},
{
"input": "2 3 1\n",
"output": "2\n"
},
{
"input": "12350 12000 12345\n",
"output": "1 000000011\n"
},
{
"input": "1000000000 25 30\n",
"output": "2\n"
},
{
"input": "1000000000 2 1000000\n",
"output": "2\n"
},
{
"input": "1000000000 1000000000 1\n",
"output": "2\n"
},
{
"input": "2 1 3\n",
"output": "1 000000001\n"
},
{
"input": "3 2 1\n",
"output": "2\n"
},
{
"input": "702034015 6007275 9777625\n",
"output": "1 000000001\n"
},
{
"input": "0 0 10000000\n",
"output": "2\n"
},
{
"input": "3631 1628 367377\n",
"output": "1 000000009\n"
},
{
"input": "1000000000 1000000000 9999999\n",
"output": "2\n"
},
{
"input": "0 1 11\n",
"output": "2\n"
},
{
"input": "1 2 13\n",
"output": "2\n"
},
{
"input": "1000000000 0 2\n",
"output": "2\n"
},
{
"input": "1000000000 9999995 10000000\n",
"output": "2\n"
},
{
"input": "999999999 0 10000000\n",
"output": "2\n"
},
{
"input": "19749161 751031022 646204\n",
"output": "2\n"
},
{
"input": "0 0 11\n",
"output": "2\n"
},
{
"input": "1000000000 0 1\n",
"output": "2\n"
},
{
"input": "22033548 813958 4874712\n",
"output": "1 000000001\n"
},
{
"input": "8270979 4785512 9669629\n",
"output": "1 000000001\n"
},
{
"input": "218 550 593\n",
"output": "1 000000011\n"
},
{
"input": "3966 5002 273075\n",
"output": "1 000000008\n"
},
{
"input": "13 4 51\n",
"output": "1 000000001\n"
},
{
"input": "1 1 1337\n",
"output": "1 000000001\n"
},
{
"input": "999999999 999999999 10000000\n",
"output": "2\n"
},
{
"input": "9 9 11\n",
"output": "2\n"
},
{
"input": "9323791 4748006 5840080\n",
"output": "1 000000005\n"
},
{
"input": "243 1001 1003\n",
"output": "2\n"
},
{
"input": "123456789 1234561 1234567\n",
"output": "1 000549636\n"
},
{
"input": "1 1 7\n",
"output": "2\n"
},
{
"input": "999999999 1000000000 10000000\n",
"output": "2\n"
},
{
"input": "815 216 182\n",
"output": "2\n"
},
{
"input": "1000000000 0 10000000\n",
"output": "2\n"
},
{
"input": "0 999999999 10000000\n",
"output": "2\n"
},
{
"input": "10 12000 12345\n",
"output": "2\n"
},
{
"input": "0 0 3\n",
"output": "2\n"
},
{
"input": "1960930 562910 606828\n",
"output": "1 000000011\n"
},
{
"input": "4 4 7\n",
"output": "2\n"
},
{
"input": "4 0 13\n",
"output": "1 000000001\n"
},
{
"input": "11 9 11\n",
"output": "1 000000010\n"
},
{
"input": "3 1 7\n",
"output": "1 000000002\n"
},
{
"input": "0 1000000000 1\n",
"output": "2\n"
},
{
"input": "23 0 23\n",
"output": "1 000000001\n"
},
{
"input": "1 0 1\n",
"output": "2\n"
},
{
"input": "1 0 9\n",
"output": "1 000000001\n"
},
{
"input": "1000000000 10000 10000000\n",
"output": "2\n"
},
{
"input": "972037745 4602117 5090186\n",
"output": "1 000000011\n"
},
{
"input": "4 7 9\n",
"output": "1 000000001\n"
},
{
"input": "1000000000 999999999 10000000\n",
"output": "2\n"
},
{
"input": "11 10 13\n",
"output": "1 000000011\n"
},
{
"input": "10000000 9999977 9999979\n",
"output": "1 009909503\n"
},
{
"input": "999999999 999999999 9009009\n",
"output": "2\n"
},
{
"input": "2 7 13\n",
"output": "2\n"
},
{
"input": "576694 1234562 1234567\n",
"output": "2\n"
},
{
"input": "585173560 4799128 5611727\n",
"output": "1 000000036\n"
},
{
"input": "1 1 2\n",
"output": "2\n"
},
{
"input": "2388 2896 73888\n",
"output": "1 000000016\n"
},
{
"input": "218556 828183 7799410\n",
"output": "1 000000001\n"
},
{
"input": "70499104 10483793 5504995\n",
"output": "2\n"
},
{
"input": "0 2 2\n",
"output": "2\n"
},
{
"input": "1167900 2709798 6800151\n",
"output": "1 000000001\n"
},
{
"input": "1000000000 1000000000 10000000\n",
"output": "2\n"
},
{
"input": "1000000000 9999991 10000000\n",
"output": "2\n"
},
{
"input": "10 7 8\n",
"output": "2\n"
},
{
"input": "4 1 4\n",
"output": "2\n"
},
{
"input": "1000000000 1 10\n",
"output": "2\n"
}
] | code_contests | python | 0 | 8ab6c209900e82eb6158555a9f45c210 |
You are given a sequence a_1, a_2, ..., a_n consisting of n non-zero integers (i.e. a_i ≠ 0).
You have to calculate two following values:
1. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a_{l + 1} ... a_{r - 1} ⋅ a_r is negative;
2. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a_{l + 1} ... a_{r - 1} ⋅ a_r is positive;
Input
The first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the number of elements in the sequence.
The second line contains n integers a_1, a_2, ..., a_n (-10^{9} ≤ a_i ≤ 10^{9}; a_i ≠ 0) — the elements of the sequence.
Output
Print two integers — the number of subsegments with negative product and the number of subsegments with positive product, respectively.
Examples
Input
5
5 -3 3 -1 1
Output
8 7
Input
10
4 2 -4 3 1 2 -4 3 2 3
Output
28 27
Input
5
-1 -2 -3 -4 -5
Output
9 6
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | input()
a=list(map(int,input().split()))
q,w,e,t,y=0,0,1,0,0
for i in a:
if e>0:
q+=1
if i>0:
e=1
else:
e=-1
else:
w+=1
if i>0:
e=-1
else:
e=1
if e>0:
t+=q
y+=w
else:
t+=w
y+=q
print(y,t) | python | code_algorithm | [
{
"input": "10\n4 2 -4 3 1 2 -4 3 2 3\n",
"output": "28 27\n"
},
{
"input": "5\n-1 -2 -3 -4 -5\n",
"output": "9 6\n"
},
{
"input": "5\n5 -3 3 -1 1\n",
"output": "8 7\n"
},
{
"input": "2\n-703630698 870277542\n",
"output": "2 1\n"
},
{
"input": "3\n-1 -1 1\n",
"output": "3 3\n"
},
{
"input": "2\n1000000000 -1000000000\n",
"output": "2 1\n"
},
{
"input": "2\n1 1\n",
"output": "0 3\n"
},
{
"input": "1\n1761402\n",
"output": "0 1\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "0 15\n"
},
{
"input": "1\n1\n",
"output": "0 1\n"
},
{
"input": "2\n665876657 284761489\n",
"output": "0 3\n"
},
{
"input": "1\n-648613522\n",
"output": "1 0\n"
},
{
"input": "10\n-27433367 -21216390 1 303383863 -799030648 -1 160141051 -1 -342089574 -215298491\n",
"output": "28 27\n"
},
{
"input": "1\n-11\n",
"output": "1 0\n"
},
{
"input": "3\n-1 -2 1\n",
"output": "3 3\n"
},
{
"input": "2\n1 753393670\n",
"output": "0 3\n"
},
{
"input": "2\n3 -1\n",
"output": "2 1\n"
},
{
"input": "3\n1 1000000000 -1\n",
"output": "3 3\n"
},
{
"input": "2\n-1 1\n",
"output": "2 1\n"
},
{
"input": "3\n-1 -1 -1\n",
"output": "4 2\n"
},
{
"input": "2\n-837247075 -925321573\n",
"output": "2 1\n"
},
{
"input": "2\n1 -42205445\n",
"output": "2 1\n"
},
{
"input": "3\n-1000000000 2 -2\n",
"output": "4 2\n"
}
] | code_contests | python | 0.1 | 0b942feae9db6aa4a777c5bc3bbc16a6 |
After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management. For that very reason the developers decided to leave the e-readers' software to programmers.
The display is represented by n × n square of pixels, each of which can be either black or white. The display rows are numbered with integers from 1 to n upside down, the columns are numbered with integers from 1 to n from the left to the right. The display can perform commands like "x, y". When a traditional display fulfills such command, it simply inverts a color of (x, y), where x is the row number and y is the column number. But in our new display every pixel that belongs to at least one of the segments (x, x) - (x, y) and (y, y) - (x, y) (both ends of both segments are included) inverts a color.
For example, if initially a display 5 × 5 in size is absolutely white, then the sequence of commands (1, 4), (3, 5), (5, 1), (3, 3) leads to the following changes:
<image>
You are an e-reader software programmer and you should calculate minimal number of commands needed to display the picture. You can regard all display pixels as initially white.
Input
The first line contains number n (1 ≤ n ≤ 2000).
Next n lines contain n characters each: the description of the picture that needs to be shown. "0" represents the white color and "1" represents the black color.
Output
Print one integer z — the least number of commands needed to display the picture.
Examples
Input
5
01110
10010
10001
10011
11110
Output
4
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n=int(input())
T=[]
for i in range(n):
T.append(input()[::-1])
Val=['0','1']
S=0
L1=[0]*n
C1=[0]*n
for diag in range(n-1):
for i in range(diag+1):
l,c=L1[i],C1[diag-i]
if T[i][diag-i]!=Val[(l+c)%2]:
S+=1
L1[i]=1-l
C1[diag-i]=1-c
L2=[0]*n
C2=[0]*n
for diag in range(n-1):
for i in range(diag+1):
l,c=L2[i],C2[diag-i]
if T[n-diag+i-1][n-i-1]!=Val[(l+c)%2]:
S+=1
L2[i]=1-l
C2[diag-i]=1-c
for i in range(n):
if Val[(L1[i]+L2[i]+C1[n-i-1]+C2[n-i-1])%2]!=T[i][n-i-1]:
S+=1
print(S)
| python | code_algorithm | [
{
"input": "5\n01110\n10010\n10001\n10011\n11110\n",
"output": "4\n"
},
{
"input": "3\n000\n000\n000\n",
"output": "0\n"
},
{
"input": "10\n1111100000\n0010100000\n0110111000\n0000001000\n1011001010\n0010100001\n0010111000\n0011001010\n0000110010\n0000001100\n",
"output": "20\n"
},
{
"input": "10\n1101010101\n1110101010\n0111010101\n1011101010\n0101110101\n1010111010\n0101011101\n1010101110\n0101010111\n1010101011\n",
"output": "100\n"
},
{
"input": "2\n11\n11\n",
"output": "4\n"
},
{
"input": "1\n0\n",
"output": "0\n"
},
{
"input": "10\n1100011000\n0000101000\n1001000011\n0000100010\n1101010011\n1100100101\n1000011101\n1001110011\n1110111100\n1000111100\n",
"output": "40\n"
},
{
"input": "3\n001\n100\n101\n",
"output": "8\n"
},
{
"input": "6\n110000\n000010\n001011\n011011\n100001\n111000\n",
"output": "13\n"
},
{
"input": "10\n0000000000\n0000110000\n1001000000\n1000011110\n1011111101\n1011110011\n1011000111\n1011000001\n1111000010\n0000111110\n",
"output": "20\n"
},
{
"input": "3\n011\n110\n001\n",
"output": "5\n"
},
{
"input": "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n",
"output": "0\n"
},
{
"input": "4\n1001\n0000\n1001\n0110\n",
"output": "10\n"
},
{
"input": "10\n1100111010\n1000011011\n0110000000\n1001111011\n0011011010\n1100001001\n0011010110\n1100011110\n0000101011\n1110101011\n",
"output": "75\n"
},
{
"input": "5\n01010\n01101\n11110\n00111\n10100\n",
"output": "22\n"
},
{
"input": "6\n100000\n010000\n001000\n000100\n000000\n000001\n",
"output": "5\n"
},
{
"input": "2\n00\n00\n",
"output": "0\n"
},
{
"input": "2\n11\n00\n",
"output": "2\n"
},
{
"input": "2\n10\n00\n",
"output": "1\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "4\n0000\n0111\n0001\n0001\n",
"output": "1\n"
},
{
"input": "7\n0000010\n0100101\n0010011\n0111111\n0100000\n0110010\n0000101\n",
"output": "19\n"
},
{
"input": "2\n11\n10\n",
"output": "3\n"
}
] | code_contests | python | 0 | 1e83fe6706e437b0948794766f0b0bf2 |
You've got a list of program warning logs. Each record of a log stream is a string in this format:
"2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes).
String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the year of 2012. String "HH:MM:SS" determines a correct time in the 24 hour format.
The described record of a log stream means that at a certain time the record has got some program warning (string "MESSAGE" contains the warning's description).
Your task is to print the first moment of time, when the number of warnings for the last n seconds was not less than m.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 10000).
The second and the remaining lines of the input represent the log stream. The second line of the input contains the first record of the log stream, the third line contains the second record and so on. Each record of the log stream has the above described format. All records are given in the chronological order, that is, the warning records are given in the order, in which the warnings appeared in the program.
It is guaranteed that the log has at least one record. It is guaranteed that the total length of all lines of the log stream doesn't exceed 5·106 (in particular, this means that the length of some line does not exceed 5·106 characters). It is guaranteed that all given dates and times are correct, and the string 'MESSAGE" in all records is non-empty.
Output
If there is no sought moment of time, print -1. Otherwise print a string in the format "2012-MM-DD HH:MM:SS" (without the quotes) — the first moment of time when the number of warnings for the last n seconds got no less than m.
Examples
Input
60 3
2012-03-16 16:15:25: Disk size is
2012-03-16 16:15:25: Network failute
2012-03-16 16:16:29: Cant write varlog
2012-03-16 16:16:42: Unable to start process
2012-03-16 16:16:43: Disk size is too small
2012-03-16 16:16:53: Timeout detected
Output
2012-03-16 16:16:43
Input
1 2
2012-03-16 23:59:59:Disk size
2012-03-17 00:00:00: Network
2012-03-17 00:00:01:Cant write varlog
Output
-1
Input
2 2
2012-03-16 23:59:59:Disk size is too sm
2012-03-17 00:00:00:Network failute dete
2012-03-17 00:00:01:Cant write varlogmysq
Output
2012-03-17 00:00:00
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
import bisect
from datetime import datetime
def main():
n, m = map(int, input().split())
n -= 1
timestamps = []
while True:
s = ""
try:
s = input()
except:
print(-1)
exit(0)
d = datetime.strptime(s[0:19], "%Y-%m-%d %H:%M:%S")
timestamps.append(int(d.timestamp()))
idx = bisect.bisect_left(timestamps, timestamps[-1] - n)
if len(timestamps) - idx == m:
print(s[0:19])
exit(0)
if __name__ == "__main__":
main()
| python | code_algorithm | [
{
"input": "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n",
"output": "2012-03-16 16:16:43\n"
},
{
"input": "2 2\n2012-03-16 23:59:59:Disk size is too sm\n2012-03-17 00:00:00:Network failute dete\n2012-03-17 00:00:01:Cant write varlogmysq\n",
"output": "2012-03-17 00:00:00\n"
},
{
"input": "1 2\n2012-03-16 23:59:59:Disk size\n2012-03-17 00:00:00: Network\n2012-03-17 00:00:01:Cant write varlog\n",
"output": "-1\n"
},
{
"input": "2 3\n2012-02-20 16:15:00: Dis\n2012-03-16 16:15:01: Net\n2012-03-16 16:15:02: Cant write varlog\n2012-03-16 16:15:02: Unable to start process\n2012-03-16 16:16:43: Dis\n2012-03-16 16:16:53: Timeout detected\n",
"output": "2012-03-16 16:15:02\n"
},
{
"input": "2 4\n2012-02-20 16:15:00: Dis\n2012-03-16 16:15:01: Net\n2012-03-16 16:15:02: Cant write varlog\n2012-03-16 16:15:02: Unable to start process\n2012-03-16 16:16:43: Dis\n2012-03-16 16:16:53: Timeout detected\n",
"output": "-1\n"
},
{
"input": "10 30\n2012-02-03 10:01:10: qQsNeHR.BLmZVMsESEKKDvqcQHHzBeddbKiIb,aDQnBKNtdcvitwtpUDGVFSh.Lx,FPBZXdSrsSDZtIJDgx!mSovndGiqHlCwCFAHy\n",
"output": "-1\n"
}
] | code_contests | python | 0 | 3a0a8b0c82229784f4455f955809143e |
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.
Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.
Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange m - 1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.
Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders.
Input
The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 5000, n ≥ m), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1 ≤ si ≤ m), and one real number xi (0 ≤ xi ≤ 109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point.
It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xi < xi + 1, 1 ≤ i < n).
Output
Output a single integer — the minimum number of plants to be replanted.
Examples
Input
3 2
2 1
1 2.0
1 3.100
Output
1
Input
3 3
1 5.0
2 5.5
3 6.0
Output
0
Input
6 3
1 14.284235
2 17.921382
1 20.328172
3 20.842331
1 25.790145
1 27.204125
Output
2
Note
In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.
In the second test case, the species are already in the correct order, so no replanting is needed.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n, m = [int(x) for x in input().split()]
d = [0 for i in range(m)]
for i in range(n):
c, x = [x for x in input().split()]
c = int(c)
d[c-1] = max(d[:c])+1
print(n-max(d))
| python | code_algorithm | [
{
"input": "3 3\n1 5.0\n2 5.5\n3 6.0\n",
"output": "0\n"
},
{
"input": "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n",
"output": "2\n"
},
{
"input": "3 2\n2 1\n1 2.0\n1 3.100\n",
"output": "1\n"
},
{
"input": "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.999990\n2 999999999.999991\n3 999999999.999992\n4 999999999.999993\n5 999999999.999994\n6 999999999.999995\n7 999999999.999996\n8 999999999.999997\n9 999999999.999998\n10 999999999.999999\n",
"output": "9\n"
},
{
"input": "1 1\n1 0\n",
"output": "0\n"
},
{
"input": "15 3\n1 0\n2 1\n3 2\n1 3\n2 4\n3 5\n1 6\n2 7\n3 8\n1 9\n2 10\n3 11\n1 12\n2 13\n3 14\n",
"output": "8\n"
},
{
"input": "12 4\n3 0\n3 1\n3 2\n3 3\n3 4\n1 5\n1 6\n2 7\n4 8\n4 9\n2 10\n3 11\n",
"output": "5\n"
},
{
"input": "10 10\n1 100\n2 101\n3 102\n5 103\n9 1000\n8 10000\n6 100000\n7 1000000\n4 10000000\n10 100000000\n",
"output": "3\n"
},
{
"input": "12 5\n2 0\n2 1\n3 2\n3 3\n3 4\n1 5\n5 6\n3 7\n3 8\n3 9\n4 999999999\n4 1000000000\n",
"output": "2\n"
},
{
"input": "20 15\n6 8719.787178\n10 13066.663722\n15 58623.690996\n9 184321.819759\n3 227999.294560\n2 279836.330518\n9 282806.308675\n8 311056.507765\n1 312315.562927\n5 459200.373445\n14 563454.265947\n7 647364.984868\n13 679761.613732\n4 684192.647497\n1 733119.607626\n7 748637.778398\n12 828048.945890\n11 893690.736585\n8 965323.895167\n5 967641.708962\n",
"output": "15\n"
},
{
"input": "4 2\n1 10\n2 20\n1 30\n2 40\n",
"output": "1\n"
},
{
"input": "16 2\n1 0\n1 1\n2 2\n2 3\n2 4\n2 5\n1 6\n1 7\n2 8\n2 9\n1 10\n1 11\n2 12\n2 13\n2 14\n2 15\n",
"output": "4\n"
},
{
"input": "5 5\n5 0\n4 1\n3 2\n2 3\n1 4\n",
"output": "4\n"
},
{
"input": "10 7\n4 70882.412953\n1 100461.912159\n3 100813.254090\n7 121632.112636\n2 424085.529781\n6 510966.713362\n6 543441.105338\n7 680094.776949\n1 721404.212606\n5 838754.272757\n",
"output": "5\n"
},
{
"input": "3 3\n3 0\n1 1\n2 2\n",
"output": "1\n"
},
{
"input": "10 6\n5 50837.108162\n3 111993.624183\n1 207268.919250\n6 567963.419694\n1 621364.247371\n2 630118.065585\n1 642135.221942\n6 642673.884754\n5 647004.198361\n4 735196.102629\n",
"output": "6\n"
},
{
"input": "20 2\n1 39277.770446\n1 131242.472574\n2 131745.437889\n1 261920.593789\n2 323611.256365\n1 341693.666730\n2 378611.498102\n2 568433.562368\n1 667757.789581\n1 674662.040626\n2 690065.099817\n2 724737.429934\n1 774858.513301\n2 783681.914774\n1 808327.402925\n2 867697.070403\n1 880911.396984\n1 929807.064277\n2 942269.265950\n1 999503.792481\n",
"output": "9\n"
},
{
"input": "3 3\n2 0\n1 1\n3 2\n",
"output": "1\n"
},
{
"input": "8 2\n1 0.000000\n1 1.000000\n1 2.000000\n2 2.000001\n1 999999997.000000\n2 999999998.000000\n2 999999999.999999\n2 1000000000.000000\n",
"output": "1\n"
},
{
"input": "10 2\n2 0\n2 1\n2 2\n2 3\n2 4\n1 5\n1 6\n1 7\n1 8\n1 9\n",
"output": "5\n"
},
{
"input": "15 5\n4 6.039627\n2 7.255149\n2 14.469785\n2 15.108572\n4 22.570081\n5 26.642253\n5 32.129202\n5 44.288220\n5 53.231909\n5 60.548042\n4 62.386581\n2 77.828816\n1 87.998512\n3 96.163559\n2 99.412872\n",
"output": "6\n"
},
{
"input": "11 3\n2 0\n2 1\n2 2\n2 3\n2 4\n3 5\n1 6\n1 7\n1 8\n1 9\n1 10\n",
"output": "5\n"
}
] | code_contests | python | 0.4 | 7f118c75fa355d464acb7ba662c08f6a |
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols sitting on the i-th wire.
<image>
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the i-th wire). Consequently all the birds on the i-th wire to the left of the dead bird get scared and jump up on the wire number i - 1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number i + 1, if there exists no such wire they fly away.
Shaass has shot m birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
Input
The first line of the input contains an integer n, (1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an, (0 ≤ ai ≤ 100).
The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass shoot the yi-th (from left) bird on the xi-th wire, (1 ≤ xi ≤ n, 1 ≤ yi). It's guaranteed there will be at least yi birds on the xi-th wire at that moment.
Output
On the i-th line of the output print the number of birds on the i-th wire.
Examples
Input
5
10 10 10 10 10
5
2 5
3 13
2 12
1 13
4 6
Output
0
12
5
0
16
Input
3
2 4 1
1
2 2
Output
3
0
3
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | n = int(input())
l = list(map(int,input().split()))
n1 = int(input())
for i in range(n1):
x,y = map(int,input().split())
if len(l)==1:
l[0]=0
elif x==1:
l[x]+=l[x-1]-y
l[x-1]=0
elif x==len(l):
l[x-2]+=y-1
l[x-1]=0
else:
l[x-2]+=y-1
l[x]+=l[x-1]-y
l[x-1]=0
for i in l:
print(i) | python | code_algorithm | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"output": "0\n12\n5\n0\n16\n"
},
{
"input": "3\n2 4 1\n1\n2 2\n",
"output": "3\n0\n3\n"
},
{
"input": "1\n100\n1\n1 100\n",
"output": "0\n"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43\n",
"output": "0\n66\n57\n7\n0\n"
},
{
"input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1\n",
"output": "0\n0\n"
},
{
"input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51\n",
"output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52\n"
},
{
"input": "1\n10\n0\n",
"output": "10\n"
},
{
"input": "1\n100\n1\n1 1\n",
"output": "0\n"
},
{
"input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0\n",
"output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95\n"
},
{
"input": "1\n50\n1\n1 25\n",
"output": "0\n"
},
{
"input": "2\n50 0\n1\n1 1\n",
"output": "0\n49\n"
},
{
"input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5\n",
"output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21\n"
}
] | code_contests | python | 0.6 | ba8618e4305620ed08c6c089b579beba |
Vasya and Petya wrote down all integers from 1 to n to play the "powers" game (n can be quite large; however, Vasya and Petya are not confused by this fact).
Players choose numbers in turn (Vasya chooses first). If some number x is chosen at the current turn, it is forbidden to choose x or all of its other positive integer powers (that is, x2, x3, ...) at the next turns. For instance, if the number 9 is chosen at the first turn, one cannot choose 9 or 81 later, while it is still allowed to choose 3 or 27. The one who cannot make a move loses.
Who wins if both Vasya and Petya play optimally?
Input
Input contains single integer n (1 ≤ n ≤ 109).
Output
Print the name of the winner — "Vasya" or "Petya" (without quotes).
Examples
Input
1
Output
Vasya
Input
2
Output
Petya
Input
8
Output
Petya
Note
In the first sample Vasya will choose 1 and win immediately.
In the second sample no matter which number Vasya chooses during his first turn, Petya can choose the remaining number and win.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | from sys import stdin, stdout
import math, collections
mod = 10**9+7
def isPower(n):
if (n <= 1):
return True
for x in range(2, (int)(math.sqrt(n)) + 1):
p = x
while (p <= n):
p = p * x
if (p == n):
return True
return False
n = int(input())
arr = [0,1,2,1,4,3,2,1,5,6,2,1,8,7,5,9,8,7,3,4,7,4,2,1,10,9,3,6,11,12]
ans = arr[int(math.log(n, 2))]
s = int(math.log(n, 2))
for i in range(3, int(n**0.5)+1):
if not isPower(i):
ans^=arr[int(math.log(n, i))]
s+=int(math.log(n, i))
ans^=((n-s)%2)
print("Vasya" if ans else "Petya") | python | code_algorithm | [
{
"input": "8\n",
"output": "Petya\n"
},
{
"input": "1\n",
"output": "Vasya\n"
},
{
"input": "2\n",
"output": "Petya\n"
},
{
"input": "10154\n",
"output": "Vasya\n"
},
{
"input": "19000881\n",
"output": "Vasya\n"
},
{
"input": "6\n",
"output": "Vasya\n"
},
{
"input": "18\n",
"output": "Vasya\n"
},
{
"input": "3\n",
"output": "Vasya\n"
},
{
"input": "947039074\n",
"output": "Vasya\n"
},
{
"input": "19000883\n",
"output": "Vasya\n"
},
{
"input": "10\n",
"output": "Vasya\n"
},
{
"input": "945070564\n",
"output": "Vasya\n"
},
{
"input": "15\n",
"output": "Vasya\n"
},
{
"input": "987719184\n",
"output": "Vasya\n"
},
{
"input": "956726760\n",
"output": "Vasya\n"
},
{
"input": "16\n",
"output": "Vasya\n"
},
{
"input": "12\n",
"output": "Vasya\n"
},
{
"input": "1000000000\n",
"output": "Vasya\n"
},
{
"input": "992187002\n",
"output": "Petya\n"
},
{
"input": "987719182\n",
"output": "Petya\n"
},
{
"input": "951352336\n",
"output": "Vasya\n"
},
{
"input": "956726762\n",
"output": "Petya\n"
},
{
"input": "954377448\n",
"output": "Petya\n"
},
{
"input": "19000882\n",
"output": "Petya\n"
},
{
"input": "992313002\n",
"output": "Petya\n"
},
{
"input": "13\n",
"output": "Vasya\n"
},
{
"input": "23\n",
"output": "Vasya\n"
},
{
"input": "957097968\n",
"output": "Vasya\n"
},
{
"input": "19000880\n",
"output": "Vasya\n"
},
{
"input": "26\n",
"output": "Vasya\n"
},
{
"input": "250\n",
"output": "Petya\n"
},
{
"input": "987656328\n",
"output": "Vasya\n"
},
{
"input": "989983296\n",
"output": "Petya\n"
},
{
"input": "246\n",
"output": "Petya\n"
},
{
"input": "25\n",
"output": "Vasya\n"
},
{
"input": "959140898\n",
"output": "Vasya\n"
},
{
"input": "21\n",
"output": "Vasya\n"
},
{
"input": "988850914\n",
"output": "Vasya\n"
},
{
"input": "200\n",
"output": "Vasya\n"
},
{
"input": "200702\n",
"output": "Vasya\n"
},
{
"input": "22\n",
"output": "Vasya\n"
},
{
"input": "951352334\n",
"output": "Petya\n"
},
{
"input": "24\n",
"output": "Vasya\n"
},
{
"input": "947900944\n",
"output": "Petya\n"
},
{
"input": "248\n",
"output": "Petya\n"
},
{
"input": "28\n",
"output": "Vasya\n"
},
{
"input": "200705\n",
"output": "Vasya\n"
},
{
"input": "7\n",
"output": "Vasya\n"
},
{
"input": "200706\n",
"output": "Petya\n"
},
{
"input": "992313000\n",
"output": "Vasya\n"
},
{
"input": "53\n",
"output": "Vasya\n"
},
{
"input": "200704\n",
"output": "Petya\n"
},
{
"input": "247\n",
"output": "Vasya\n"
},
{
"input": "959140900\n",
"output": "Petya\n"
},
{
"input": "200703\n",
"output": "Vasya\n"
},
{
"input": "999999999\n",
"output": "Vasya\n"
},
{
"input": "945070562\n",
"output": "Petya\n"
},
{
"input": "992187000\n",
"output": "Vasya\n"
},
{
"input": "19\n",
"output": "Vasya\n"
},
{
"input": "52\n",
"output": "Petya\n"
},
{
"input": "999999998\n",
"output": "Vasya\n"
},
{
"input": "954377450\n",
"output": "Vasya\n"
},
{
"input": "947039076\n",
"output": "Petya\n"
},
{
"input": "11\n",
"output": "Vasya\n"
},
{
"input": "940219568\n",
"output": "Vasya\n"
},
{
"input": "988850916\n",
"output": "Petya\n"
},
{
"input": "17\n",
"output": "Vasya\n"
},
{
"input": "10155\n",
"output": "Petya\n"
},
{
"input": "5\n",
"output": "Vasya\n"
},
{
"input": "4\n",
"output": "Vasya\n"
},
{
"input": "957097970\n",
"output": "Petya\n"
},
{
"input": "27\n",
"output": "Vasya\n"
},
{
"input": "9\n",
"output": "Vasya\n"
},
{
"input": "989983294\n",
"output": "Vasya\n"
},
{
"input": "987656330\n",
"output": "Petya\n"
},
{
"input": "10153\n",
"output": "Petya\n"
},
{
"input": "14\n",
"output": "Vasya\n"
},
{
"input": "940219570\n",
"output": "Petya\n"
},
{
"input": "249\n",
"output": "Vasya\n"
},
{
"input": "20\n",
"output": "Vasya\n"
},
{
"input": "947900942\n",
"output": "Vasya\n"
}
] | code_contests | python | 0 | 405d3be9c39568d7d13394bc0db6c1a4 |
Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).
Input
The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).
Output
Print a single integer — the number of k-good numbers in a.
Examples
Input
10 6
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
Output
10
Input
2 1
1
10
Output
1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | import sys
x=input().split()
n=int(x[0])
k=int(x[1])
list=[]
for i in range(0,n):
y=input()
list.append(y)
l=0
for j in list:
flag=1
for z in range(0,k+1):
if str(z) not in j:
flag=0
break
if flag==1:
l=l+1
print(l) | python | code_algorithm | [
{
"input": "2 1\n1\n10\n",
"output": "1\n"
},
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"output": "10\n"
},
{
"input": "1 0\n1000000000\n",
"output": "1\n"
},
{
"input": "1 3\n1\n",
"output": "0\n"
},
{
"input": "2 8\n12345678\n1230\n",
"output": "0\n"
},
{
"input": "6 1\n10\n102\n120\n1032\n1212103\n1999999\n",
"output": "5\n"
},
{
"input": "6 0\n10\n102\n120\n1032\n1212103\n1999999\n",
"output": "5\n"
},
{
"input": "1 1\n1\n",
"output": "0\n"
},
{
"input": "1 3\n1000000000\n",
"output": "0\n"
},
{
"input": "1 2\n2220\n",
"output": "0\n"
},
{
"input": "1 0\n1\n",
"output": "0\n"
},
{
"input": "6 9\n10\n102\n120\n1032\n1212103\n1999999\n",
"output": "0\n"
},
{
"input": "2 8\n123456780\n123\n",
"output": "1\n"
},
{
"input": "1 1\n1000000000\n",
"output": "1\n"
},
{
"input": "6 3\n10\n102\n120\n1032\n1212103\n1999999\n",
"output": "2\n"
},
{
"input": "1 9\n1000000000\n",
"output": "0\n"
},
{
"input": "1 9\n1\n",
"output": "0\n"
},
{
"input": "6 2\n10\n102\n120\n1032\n1212103\n1999999\n",
"output": "4\n"
}
] | code_contests | python | 1 | f046badc98836d2fef052f084febc7d9 |
Salve, mi amice.
Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.
Rp:
I Aqua Fortis
I Aqua Regia
II Amalgama
VII Minium
IV Vitriol
Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via.
Fac et spera,
Vale,
Nicolas Flamel
Input
The first line of input contains several space-separated integers ai (0 ≤ ai ≤ 100).
Output
Print a single integer.
Examples
Input
2 4 6 8 10
Output
1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
``` | b =[1,1,2,7,4]
a =list(map(int,input().split()))
ans = 100
for i in range(5):
ans = min(a[i]//b[i],ans)
print(ans)
| python | code_algorithm | [
{
"input": "2 4 6 8 10\n",
"output": "1\n"
},
{
"input": "18 13 91 64 22\n",
"output": "5\n"
},
{
"input": "31 38 47 26 13\n",
"output": "3\n"
},
{
"input": "65 46 3 77 81\n",
"output": "1\n"
},
{
"input": "94 21 36 89 20\n",
"output": "5\n"
},
{
"input": "12 39 3 50 84\n",
"output": "1\n"
},
{
"input": "75 82 48 95 12\n",
"output": "3\n"
},
{
"input": "46 68 3 0 51\n",
"output": "0\n"
},
{
"input": "1 1 2 6 4\n",
"output": "0\n"
},
{
"input": "50 27 17 31 89\n",
"output": "4\n"
},
{
"input": "42 9 59 19 24\n",
"output": "2\n"
},
{
"input": "74 21 36 68 80\n",
"output": "9\n"
},
{
"input": "50 87 29 81 21\n",
"output": "5\n"
},
{
"input": "0 74 25 35 48\n",
"output": "0\n"
},
{
"input": "41 85 14 43 23\n",
"output": "5\n"
},
{
"input": "3 26 69 33 18\n",
"output": "3\n"
},
{
"input": "14 63 14 25 18\n",
"output": "3\n"
},
{
"input": "32 36 80 54 48\n",
"output": "7\n"
},
{
"input": "12 31 47 31 84\n",
"output": "4\n"
},
{
"input": "0 0 0 0 0\n",
"output": "0\n"
},
{
"input": "1 1 2 7 4\n",
"output": "1\n"
},
{
"input": "1 0 2 7 4\n",
"output": "0\n"
},
{
"input": "1 1 1 7 4\n",
"output": "0\n"
},
{
"input": "67 66 69 96 92\n",
"output": "13\n"
},
{
"input": "51 19 70 5 78\n",
"output": "0\n"
},
{
"input": "79 2 93 92 16\n",
"output": "2\n"
},
{
"input": "81 26 69 0 84\n",
"output": "0\n"
},
{
"input": "28 49 58 47 54\n",
"output": "6\n"
},
{
"input": "2 2 3 14 8\n",
"output": "1\n"
},
{
"input": "51 56 14 99 21\n",
"output": "5\n"
},
{
"input": "81 67 58 8 51\n",
"output": "1\n"
},
{
"input": "94 28 3 29 9\n",
"output": "1\n"
},
{
"input": "71 61 47 9 19\n",
"output": "1\n"
},
{
"input": "60 92 82 71 53\n",
"output": "10\n"
},
{
"input": "1 2 2 7 4\n",
"output": "1\n"
},
{
"input": "1 1 3 7 4\n",
"output": "1\n"
},
{
"input": "100 100 100 100 100\n",
"output": "14\n"
},
{
"input": "52 43 80 14 79\n",
"output": "2\n"
},
{
"input": "19 84 69 57 55\n",
"output": "8\n"
}
] | code_contests | python | 0 | ae7dcedfbbd3c78e270e0be43b74e19e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.