message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliens’ hands were often very different from humans’. Generally speaking, in a kind of aliens, there are N fingers and M bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends.
When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her?
Input
N M
S1 D1
S2 D2
.
.
.
SM DM
The first line contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 1000) in this order. The following M lines mean bend rules. Each line contains two integers Si and Di in this order, which mean that the finger Di always bends when the finger Si bends. Any finger appears at most once in S.
Output
Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line.
Examples
Input
5 4
2 3
3 4
4 3
5 4
Output
10
Input
5 5
1 2
2 3
3 4
4 5
5 1
Output
2
Input
5 0
Output
32 | instruction | 0 | 32,449 | 20 | 64,898 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
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 main():
rr = []
def f(n,m):
a = [LI_() for _ in range(m)]
p = collections.defaultdict(list)
c = collections.defaultdict(list)
for s,d in a:
p[s].append(d)
c[d].append(s)
v = collections.defaultdict(int)
d = collections.defaultdict(lambda: -1)
b = collections.defaultdict(set)
def _f(i):
# print('_f',i)
if v[i] == 2:
return -1
if v[i] == 1:
d[i] = i
b[i].add(i)
return i
v[i] = 1
for j in p[i]:
r = _f(j)
if r < 0:
continue
d[i] = r
b[r].add(i)
v[i] = 2
if d[i] == i:
return -1
return d[i]
for i in range(n):
_f(i)
def g(i):
# print('g',i)
if d[i] >= 0 and d[i] != i:
return 1
cs = set(c[i])
if d[i] == i:
for j in b[i]:
cs |= set(c[j])
r = 1
# print('cs',i,cs)
for j in cs:
if j in b[i]:
continue
gr = g(j)
# print('jgr',j,gr)
r *= gr
r %= mod
r += 1
return r
r = 1
for i in range(n):
if d[i] == i or len(p[i]) == 0:
gr = g(i)
# print('igr',i,gr)
r *= gr
r %= mod
return r
while 1:
n,m = LI()
if n == 0:
break
rr.append(f(n,m))
break
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 32,449 | 20 | 64,899 |
Provide a correct Python 3 solution for this coding contest problem.
Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliens’ hands were often very different from humans’. Generally speaking, in a kind of aliens, there are N fingers and M bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends.
When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her?
Input
N M
S1 D1
S2 D2
.
.
.
SM DM
The first line contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 1000) in this order. The following M lines mean bend rules. Each line contains two integers Si and Di in this order, which mean that the finger Di always bends when the finger Si bends. Any finger appears at most once in S.
Output
Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line.
Examples
Input
5 4
2 3
3 4
4 3
5 4
Output
10
Input
5 5
1 2
2 3
3 4
4 5
5 1
Output
2
Input
5 0
Output
32 | instruction | 0 | 32,450 | 20 | 64,900 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
sys.setrecursionlimit(10**6)
def scc(N, G, RG):
order = []
used = [0]*N
group = [None]*N
def dfs(s):
used[s] = 1
for t in G[s]:
if not used[t]:
dfs(t)
order.append(s)
def rdfs(s, col):
group[s] = col
used[s] = 1
for t in RG[s]:
if not used[t]:
rdfs(t, col)
for i in range(N):
if not used[i]:
dfs(i)
used = [0]*N
label = 0
for s in reversed(order):
if not used[s]:
rdfs(s, label)
label += 1
return label, group
def construct(N, G, label, group):
G0 = [set() for i in range(label)]
GP = [[] for i in range(label)]
for v in range(N):
lbs = group[v]
for w in G[v]:
lbt = group[w]
if lbs == lbt:
continue
G0[lbs].add(lbt)
GP[lbs].append(v)
return G0, GP
N, M = map(int, readline().split())
G = [[] for i in range(N)]
RG = [[] for i in range(N)]
for i in range(M):
s, d = map(int, readline().split()); s -= 1; d -= 1
G[d].append(s)
RG[s].append(d)
N0, group = scc(N, G, RG)
G0, GP = construct(N, G, N0, group)
deg = [0]*N0
for v in range(N0):
for w in G0[v]:
deg[w] += 1
MOD = 10**9 + 7
def dfs(v):
r = 1
for w in G0[v]:
r = r * dfs(w) % MOD
return r + 1
ans = 1
for v in range(N0):
if deg[v] == 0:
ans = ans * dfs(v) % MOD
write("%d\n" % ans)
``` | output | 1 | 32,450 | 20 | 64,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliens’ hands were often very different from humans’. Generally speaking, in a kind of aliens, there are N fingers and M bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends.
When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her?
Input
N M
S1 D1
S2 D2
.
.
.
SM DM
The first line contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 1000) in this order. The following M lines mean bend rules. Each line contains two integers Si and Di in this order, which mean that the finger Di always bends when the finger Si bends. Any finger appears at most once in S.
Output
Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line.
Examples
Input
5 4
2 3
3 4
4 3
5 4
Output
10
Input
5 5
1 2
2 3
3 4
4 5
5 1
Output
2
Input
5 0
Output
32
Submitted Solution:
```
n,m = map(int, input().split(" "))
s = [0 for i in range(m)]
d = [0 for i in range(m)]
sum = 2**n
for i in range(m):
s[i],d[i] = map(int, input().split(" "))
for i in range(m):
sum -= 2**(n-2)
sum %= 1000000007
sum += 1000000007
for j in range(m):
if i == j:
continue
if s[i] == s[j] or d[i] == d[j]:
sum += 2**(n-4)
if s[i] != s[j] and s[i] != d[j] and d[i] != s[j] and d[i] != d[j]:
sum += 2**(n-5)
print(sum%1000000007)
``` | instruction | 0 | 32,451 | 20 | 64,902 |
No | output | 1 | 32,451 | 20 | 64,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliens’ hands were often very different from humans’. Generally speaking, in a kind of aliens, there are N fingers and M bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends.
When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her?
Input
N M
S1 D1
S2 D2
.
.
.
SM DM
The first line contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 1000) in this order. The following M lines mean bend rules. Each line contains two integers Si and Di in this order, which mean that the finger Di always bends when the finger Si bends. Any finger appears at most once in S.
Output
Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line.
Examples
Input
5 4
2 3
3 4
4 3
5 4
Output
10
Input
5 5
1 2
2 3
3 4
4 5
5 1
Output
2
Input
5 0
Output
32
Submitted Solution:
```
def combi(n):
if n == 1:
return [[1],[0]]
else:
s = combi(n-1)
ret = [[t] + x for x in s for t in [1, 0]]
return ret
N, M = map(int, input().split())
whole = combi(N)
for i in range(M):
select = []
s, d = map(int, input().split())
for c in whole:
if c[s-1] == 1 and c[d-1] ==0:
select.append(c)
for c in select:
whole.remove(c)
print(len(whole))
``` | instruction | 0 | 32,452 | 20 | 64,904 |
No | output | 1 | 32,452 | 20 | 64,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliens’ hands were often very different from humans’. Generally speaking, in a kind of aliens, there are N fingers and M bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends.
When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her?
Input
N M
S1 D1
S2 D2
.
.
.
SM DM
The first line contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 1000) in this order. The following M lines mean bend rules. Each line contains two integers Si and Di in this order, which mean that the finger Di always bends when the finger Si bends. Any finger appears at most once in S.
Output
Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line.
Examples
Input
5 4
2 3
3 4
4 3
5 4
Output
10
Input
5 5
1 2
2 3
3 4
4 5
5 1
Output
2
Input
5 0
Output
32
Submitted Solution:
```
n,m = map(int, input().split(" "))
s = [0 for i in range(m)]
d = [0 for i in range(m)]
sum = 2**n
for i in range(m):
s[i],d[i] = map(int, input().split(" "))
if n >= 3:
for i in range(m):
sum -= 2**(n-2)
for j in range(m):
if i == j:
continue
if s[i] == s[j] or d[i] == d[j]:
sum += 2**(n-4)
if s[i] != s[j] and s[i] != d[j] and d[i] != s[j] and d[i] != d[j]:
sum += 2**(n-5)
if n == 2:
if m == 0:
sum = 4
if m == 1:
sum = 3
if m >= 2:
sum = 2
print(int(sum%1000000007))
``` | instruction | 0 | 32,453 | 20 | 64,906 |
No | output | 1 | 32,453 | 20 | 64,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19 | instruction | 0 | 32,546 | 20 | 65,092 |
Tags: math, number theory
Correct Solution:
```
def binNumber(n,size):
return bin(n)[2:].zfill(size)
def gcd(a,b):
if a == 0:
return b
return gcd(b%a,a)
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
#code
n = int(input())
for _ in range(n):
k,x = map(int,input().split())
print(x + (k-1)*9)
``` | output | 1 | 32,546 | 20 | 65,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19 | instruction | 0 | 32,547 | 20 | 65,094 |
Tags: math, number theory
Correct Solution:
```
t=int(input())
for i in range(t):
k,i=list(map(int,input().split()))
print(i+9*(k-1))
``` | output | 1 | 32,547 | 20 | 65,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19 | instruction | 0 | 32,548 | 20 | 65,096 |
Tags: math, number theory
Correct Solution:
```
for i in range(int(input())):
a,b=map(int,input().split())
print(b+(a-1)*9)
``` | output | 1 | 32,548 | 20 | 65,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19 | instruction | 0 | 32,549 | 20 | 65,098 |
Tags: math, number theory
Correct Solution:
```
n = int(input())
for i in range(n):
k, x = map(int, input().split(' '))
print((k-1)*9 + x)
``` | output | 1 | 32,549 | 20 | 65,099 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19 | instruction | 0 | 32,550 | 20 | 65,100 |
Tags: math, number theory
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
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")
#-------------------game starts now-----------------------------------------------------
for t in range (int(input())):
k,x=map(int,input().split())
r=9*(k-1)+x
print(r)
``` | output | 1 | 32,550 | 20 | 65,101 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19 | instruction | 0 | 32,551 | 20 | 65,102 |
Tags: math, number theory
Correct Solution:
```
n = int(input())
for i in range(0, n):
l, r = map(int, input().split())
if l == 1:
print(r)
continue
print(9 * (l - 1) + r)
``` | output | 1 | 32,551 | 20 | 65,103 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19 | instruction | 0 | 32,552 | 20 | 65,104 |
Tags: math, number theory
Correct Solution:
```
# from functools import lru_cache
t = int(input())
for _ in range(t):
k, x = map(int, input().split())
print(x + 9 * (k - 1))
``` | output | 1 | 32,552 | 20 | 65,105 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19 | instruction | 0 | 32,553 | 20 | 65,106 |
Tags: math, number theory
Correct Solution:
```
t = int(input())
for i in range(t):
li = [int(x) for x in input().split()]
print(li[1]+(li[0]-1)*9)
``` | output | 1 | 32,553 | 20 | 65,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19
Submitted Solution:
```
n = int(input())
for i in range(n):
x,y = map(int,input().split())
print(y+(x-1)*9)
``` | instruction | 0 | 32,554 | 20 | 65,108 |
Yes | output | 1 | 32,554 | 20 | 65,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19
Submitted Solution:
```
t=int(input())
a=[]
for i in range(t):
b=list(map(int,input().split()))
a.append(b)
#print(a)
for j in range(t):
#print(a[j][0])
#print(a[j][1])
print(9*(a[j][0])-(9-a[j][1]))
``` | instruction | 0 | 32,555 | 20 | 65,110 |
Yes | output | 1 | 32,555 | 20 | 65,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19
Submitted Solution:
```
import sys
R = lambda: map(int, input().split())
t = int(input())
while t:
k,x = R()
print(x + (k-1)*9)
t-=1
``` | instruction | 0 | 32,556 | 20 | 65,112 |
Yes | output | 1 | 32,556 | 20 | 65,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19
Submitted Solution:
```
from sys import stdin, stdout
q = int(stdin.readline())
for i in range(q):
k, x = map(int, stdin.readline().split())
stdout.write(str((k - 1) * 9 + x) + '\n')
``` | instruction | 0 | 32,557 | 20 | 65,114 |
Yes | output | 1 | 32,557 | 20 | 65,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19
Submitted Solution:
```
t = int(input())
for i in range(t):
n, k = map(int, input().split())
if n == 1:
print(k)
continue
x = k * 10
while x <= n * 10 - 1:
n -= 1
x *= 10
x = (k + 9) * 10
while x <= n * 10 - 1:
n -= 1
x *= 10
sm = sum(list(map(int, list(str(n - 1)))))
for j in range(1, 10):
if int(str(n - 1) + str(j)) % 9 == k:
x = j
break
print(n - 1, x, sep = "")
``` | instruction | 0 | 32,558 | 20 | 65,116 |
No | output | 1 | 32,558 | 20 | 65,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19
Submitted Solution:
```
n=int(input())
for i in range(0,n):
p=input().rstrip().split(' ')
k=int(p[0])
x=int(p[1])
for j in range(0,1000000000000):
if k!=0:
N=j;
s=0;
while(N>=1):
I=N%10;
N=N//10;
s=s+I;
if s%9==0:
S=9;
else:
S=s%9;
if S==x:
T=j;
k-=1;
else:
break;
print(T)
``` | instruction | 0 | 32,559 | 20 | 65,118 |
No | output | 1 | 32,559 | 20 | 65,119 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19
Submitted Solution:
```
n= int(input())
from math import *
a=0
def f(n,m):
a=0
if n==1:
return m
else:
for i in range(int(pow(10,12))):
if i-9*(floor( (i-1)/9))==m:
a+=1
if a==n:
return i
for i in range(n):
l=[int(i) for i in input().split()]
print(f(l[0],l[1]))
``` | instruction | 0 | 32,560 | 20 | 65,120 |
No | output | 1 | 32,560 | 20 | 65,121 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today at the lesson of mathematics, Petya learns about the digital root.
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.
As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.
Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.
Output
Output n lines, i-th line should contain a single integer — the answer to the i-th problem.
Example
Input
3
1 5
5 2
3 1
Output
5
38
19
Submitted Solution:
```
n = int(input())
t = 0
lis = []
for i in range(n):
m = list(map(int,input().split()))
for j in range(1000000000000000):
if (1+((j-1)%9)) == m[1]:
t += 1
if t == m[0]:
break
lis.append(j)
t = 0
for i in lis:
print(i)
``` | instruction | 0 | 32,561 | 20 | 65,122 |
No | output | 1 | 32,561 | 20 | 65,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:
* ">" → 1000,
* "<" → 1001,
* "+" → 1010,
* "-" → 1011,
* "." → 1100,
* "," → 1101,
* "[" → 1110,
* "]" → 1111.
Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.
You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).
Input
The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".
Output
Output the size of the equivalent Unary program modulo 1000003 (106 + 3).
Examples
Input
,.
Output
220
Input
++++[>,.<-]
Output
61425
Note
To write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.
In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program. | instruction | 0 | 32,673 | 20 | 65,346 |
Tags: implementation
Correct Solution:
```
conv = {'>' : 8, '<' : 9, '+' : 10, '-' : 11, '.' : 12, ',' : 13, '[' : 14, ']' : 15}
s = 0
for c in input():
s *= 16
s += conv[c]
s %= 1000003
print(s)
``` | output | 1 | 32,673 | 20 | 65,347 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:
* ">" → 1000,
* "<" → 1001,
* "+" → 1010,
* "-" → 1011,
* "." → 1100,
* "," → 1101,
* "[" → 1110,
* "]" → 1111.
Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.
You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).
Input
The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".
Output
Output the size of the equivalent Unary program modulo 1000003 (106 + 3).
Examples
Input
,.
Output
220
Input
++++[>,.<-]
Output
61425
Note
To write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.
In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program. | instruction | 0 | 32,676 | 20 | 65,352 |
Tags: implementation
Correct Solution:
```
def solve(a):
x=0
y=len(a)
for i in a:
x=x+int(i)*(2**(y-1))
y=y-1
return x%(1000003)
p=input()
x=""
#11011100
for i in p:
if i=='>':
x=x+'1000'
elif i=='<':
x=x+'1001'
elif i=='+':
x=x+'1010'
elif i=='-':
x=x+'1011'
elif i=='.':
x=x+'1100'
elif i==',':
x=x+'1101'
elif i=='[':
x=x+'1110'
elif i==']':
x=x+'1111'
print(solve(x))
``` | output | 1 | 32,676 | 20 | 65,353 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:
* ">" → 1000,
* "<" → 1001,
* "+" → 1010,
* "-" → 1011,
* "." → 1100,
* "," → 1101,
* "[" → 1110,
* "]" → 1111.
Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.
You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).
Input
The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".
Output
Output the size of the equivalent Unary program modulo 1000003 (106 + 3).
Examples
Input
,.
Output
220
Input
++++[>,.<-]
Output
61425
Note
To write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.
In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program. | instruction | 0 | 32,677 | 20 | 65,354 |
Tags: implementation
Correct Solution:
```
def Decimal(s):
n=len(s)
x=0
for i in range(n):
x+=int(s[n-1-i])*(2**i)
return x
s=input()
K={}
K[">"]="1000"
K["<"]="1001"
K["+"]="1010"
K["-"]="1011"
K["."]="1100"
K[","]="1101"
K["["]="1110"
K["]"]="1111"
for item in K:
s=s.replace(item,K[item])
print(Decimal(s)%1000003)
``` | output | 1 | 32,677 | 20 | 65,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:
* ">" → 1000,
* "<" → 1001,
* "+" → 1010,
* "-" → 1011,
* "." → 1100,
* "," → 1101,
* "[" → 1110,
* "]" → 1111.
Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.
You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).
Input
The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".
Output
Output the size of the equivalent Unary program modulo 1000003 (106 + 3).
Examples
Input
,.
Output
220
Input
++++[>,.<-]
Output
61425
Note
To write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.
In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program. | instruction | 0 | 32,678 | 20 | 65,356 |
Tags: implementation
Correct Solution:
```
d={">":'1000',
"<":'1001',
"+":'1010',
"-":'1011',
".":'1100',
",":'1101',
"[":'1110',
"]":'1111'}
s=input()
l=[]
for i in s:
l.append(d[i])
a="".join(l)
ans=int(a,2)
print(ans%1000003)
``` | output | 1 | 32,678 | 20 | 65,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:
* ">" → 1000,
* "<" → 1001,
* "+" → 1010,
* "-" → 1011,
* "." → 1100,
* "," → 1101,
* "[" → 1110,
* "]" → 1111.
Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.
You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).
Input
The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".
Output
Output the size of the equivalent Unary program modulo 1000003 (106 + 3).
Examples
Input
,.
Output
220
Input
++++[>,.<-]
Output
61425
Note
To write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.
In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program. | instruction | 0 | 32,679 | 20 | 65,358 |
Tags: implementation
Correct Solution:
```
s,z,k=input(),0,0
for x in s[::-1]:
if x==">":
z+=8<<k
elif x=="<":
z+=9<<k
elif x=="+":
z+=10<<k
elif x=="-":
z+=11<<k
elif x==".":
z+=12<<k
elif x==",":
z+=13<<k
elif x=="[":
z+=14<<k
else:
z+=15<<k
k+=4
print(z%1000003)
``` | output | 1 | 32,679 | 20 | 65,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:
* ">" → 1000,
* "<" → 1001,
* "+" → 1010,
* "-" → 1011,
* "." → 1100,
* "," → 1101,
* "[" → 1110,
* "]" → 1111.
Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.
You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).
Input
The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".
Output
Output the size of the equivalent Unary program modulo 1000003 (106 + 3).
Examples
Input
,.
Output
220
Input
++++[>,.<-]
Output
61425
Note
To write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.
In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program. | instruction | 0 | 32,680 | 20 | 65,360 |
Tags: implementation
Correct Solution:
```
ch=input()
d={">":'1000',"<":'1001',"+":'1010',"-":'1011',"." :'1100',"," :'1101',"[":'1110',"]":'1111'}
c=''
for i in range(len(ch)):
c+=d[ch[i]]
m=len(c)
s=0
for i in range (m):
s+=2**(m-i-1)*int(c[i])
print(s%((10**6)+3))
``` | output | 1 | 32,680 | 20 | 65,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:
* ">" → 1000,
* "<" → 1001,
* "+" → 1010,
* "-" → 1011,
* "." → 1100,
* "," → 1101,
* "[" → 1110,
* "]" → 1111.
Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.
You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).
Input
The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".
Output
Output the size of the equivalent Unary program modulo 1000003 (106 + 3).
Examples
Input
,.
Output
220
Input
++++[>,.<-]
Output
61425
Note
To write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.
In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program.
Submitted Solution:
```
val = 0
for ch in input():
val = ( '><+-.,[]'.find(ch) )
print(val)
``` | instruction | 0 | 32,687 | 20 | 65,374 |
No | output | 1 | 32,687 | 20 | 65,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 32), separated by a single space.
Output
Output a single integer.
Examples
Input
1 1
Output
0
Input
3 7
Output
0
Input
13 10
Output
1 | instruction | 0 | 32,814 | 20 | 65,628 |
Tags: *special, implementation
Correct Solution:
```
"""111111101010101111100101001111111
100000100000000001010110001000001
101110100110110000011010001011101
101110101011001001111101001011101
101110101100011000111100101011101
100000101010101011010000101000001
111111101010101010101010101111111
000000001111101111100111100000000
100010111100100001011110111111001
110111001111111100100001000101100
011100111010000101000111010001010
011110000110001111110101100000011
111111111111111000111001001011000
111000010111010011010011010100100
101010100010110010110101010000010
101100000101010001111101000000000
000010100011001101000111101011010
101001001111101111000101010001110
101101111111000100100001110001000
000010011000100110000011010000010
001101101001101110010010011011000
011101011010001000111101010100110
111010100110011101001101000001110
110001010010101111000101111111000
001000111011100001010110111110000
000000001110010110100010100010110
111111101000101111000110101011010
100000100111010101111100100011011
101110101001010000101000111111000
101110100011010010010111111011010
101110100100011011110110101110000
100000100110011001111100111100000
111111101101000101001101110010001"""
x, y = [int(x) for x in input().split()]
print(__doc__[34*x+y])
``` | output | 1 | 32,814 | 20 | 65,629 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 32), separated by a single space.
Output
Output a single integer.
Examples
Input
1 1
Output
0
Input
3 7
Output
0
Input
13 10
Output
1 | instruction | 0 | 32,816 | 20 | 65,632 |
Tags: *special, implementation
Correct Solution:
```
nums = ["111111101010101111100101001111111",
"100000100000000001010110001000001",
"101110100110110000011010001011101",
"101110101011001001111101001011101",
"101110101100011000111100101011101",
"100000101010101011010000101000001",
"111111101010101010101010101111111",
"000000001111101111100111100000000",
"100010111100100001011110111111001",
"110111001111111100100001000101100",
"011100111010000101000111010001010",
"011110000110001111110101100000011",
"111111111111111000111001001011000",
"111000010111010011010011010100100",
"101010100010110010110101010000010",
"101100000101010001111101000000000",
"000010100011001101000111101011010",
"101001001111101111000101010001110",
"101101111111000100100001110001000",
"000010011000100110000011010000010",
"001101101001101110010010011011000",
"011101011010001000111101010100110",
"111010100110011101001101000001110",
"110001010010101111000101111111000",
"001000111011100001010110111110000",
"000000001110010110100010100010110",
"111111101000101111000110101011010",
"100000100111010101111100100011011",
"101110101001010000101000111111000",
"101110100011010010010111111011010",
"101110100100011011110110101110000",
"100000100110011001111100111100000",
"111111101101000101001101110010001"]
a, b = map(int,input().split())
print(int(nums[a][b]))
``` | output | 1 | 32,816 | 20 | 65,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 32), separated by a single space.
Output
Output a single integer.
Examples
Input
1 1
Output
0
Input
3 7
Output
0
Input
13 10
Output
1 | instruction | 0 | 32,818 | 20 | 65,636 |
Tags: *special, implementation
Correct Solution:
```
lol = ['111111101010101111100101001111111\n', '100000100000000001010110001000001\n', '101110100110110000011010001011101\n', '101110101011001001111101001011101\n', '101110101100011000111100101011101\n', '100000101010101011010000101000001\n', '111111101010101010101010101111111\n', '000000001111101111100111100000000\n', '100010111100100001011110111111001\n', '110111001111111100100001000101100\n', '011100111010000101000111010001010\n', '011110000110001111110101100000011\n', '111111111111111000111001001011000\n', '111000010111010011010011010100100\n', '101010100010110010110101010000010\n', '101100000101010001111101000000000\n', '000010100011001101000111101011010\n', '101001001111101111000101010001110\n', '101101111111000100100001110001000\n', '000010011000100110000011010000010\n', '001101101001101110010010011011000\n', '011101011010001000111101010100110\n', '111010100110011101001101000001110\n', '110001010010101111000101111111000\n', '001000111011100001010110111110000\n', '000000001110010110100010100010110\n', '111111101000101111000110101011010\n', '100000100111010101111100100011011\n', '101110101001010000101000111111000\n', '101110100011010010010111111011010\n', '101110100100011011110110101110000\n', '100000100110011001111100111100000\n', '111111101101000101001101110010001']
a1, a2 = map(int, input().split())
print(lol[a1][a2])
``` | output | 1 | 32,818 | 20 | 65,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
import math
'''
r,c,n,k = map(int,input().split())
matrix = [['*' for row in range(c)] for column in range(r)]
for i in range(n):
x,y = map(int,input().split())
matrix[x-1][y-1] = '#'
ans = 0
for row1 in range(r):
for row2 in range(r):
if matrix[row1:row2+1].count('#') >= k:
ans+=1
for column1 in range(c):
for column2 in range(column1,c):
count = 0
for row in range(r):
count+=matrix[r][column1:column2+1].count('#')
if count >=k:
ans+=1
print(ans)
'''
s = input()
d = {'?':5,'1':5,'2':5,'3':5,'4':5,'5':5,'6':5,'7':5,'8':5,'9':5,'0':5,'A':0,\
'B':0,'C':0,'D':0,'E':0,'F':0,'G':0,'H':0,'I':0,'J':0}
digit = set([str(i) for i in range(0,10)])
digit.add('?')
ans = 1
count =0
for i in range(1,len(s)):
if d[s[i]] == 0:
count+=1
d[s[i]] = 1
elif s[i] == '?':
d[s[i]]+=1
ans*=pow(10,d['?']-5)
start = 10
if d[s[0]] == 1:
count-=1
ans*=9
start = 9
if d[s[0]] == 0:
ans*=9
start = 9
while count!=0:
ans*=start
start-=1
count-=1
if s[0] == '?':
ans*=9
print(ans)
``` | instruction | 0 | 32,838 | 20 | 65,676 |
Yes | output | 1 | 32,838 | 20 | 65,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
s=input()
G='ABCDEFGHIJ'
d=0
g=dict()
for i in s:
if i in G:
g[i]=1
if i=='?':
d+=1
if(d>=1):
A=10
d=d-1
else:
A=1
g=len(g)
for i in range(10,10-g,-1):
A*=i
if((s[0] in G) or (s[0]=='?')):
A*=9
A//=10
print(str(A)+'0'*d)
``` | instruction | 0 | 32,839 | 20 | 65,678 |
Yes | output | 1 | 32,839 | 20 | 65,679 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
a=input()
s=set()
for x in a:
if ord(x)>64:s|={x}
r=10**a.count('?')
for i in range(len(s)):r*=10-i
if ord(a[0])>57:r=r//10*9
print(r)
``` | instruction | 0 | 32,840 | 20 | 65,680 |
Yes | output | 1 | 32,840 | 20 | 65,681 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
import math
import string
s = input()
pr = set()
ans = 0
for x in s:
if ord('A') <= ord(x) <= ord('J'):
pr.add(x)
pr = len(pr)
r = s.count('?')
if s[0] == '?':
ans = (9 * math.factorial(10) // math.factorial(10 - pr))
print(str(ans) + '0' * (r - 1))
elif s[0] in string.ascii_uppercase:
ans = (9 * math.factorial(9) // math.factorial(9 - pr + 1))
print(str(ans) + '0' * r)
else:
ans = (math.factorial(10) // math.factorial(10 - pr))
print(str(ans) + '0' * r)
``` | instruction | 0 | 32,841 | 20 | 65,682 |
Yes | output | 1 | 32,841 | 20 | 65,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
if __name__ == '__main__':
s = input()
digits = set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
letters = set(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'])
count_1 = {0: 1}
letters_used = set()
for i, ch in enumerate(s):
if ch in digits:
count_1[i + 1] = count_1[i]
continue
if ch == '?':
count_1[i + 1] = count_1[i] * 10
continue
if ch in letters:
if ch not in letters_used:
count_1[i + 1] = count_1[i] * (10 - len(letters_used))
letters_used.add(ch)
continue
count_1[i + 1] = count_1[i]
count_2 = 0
letters_used = set()
for i, ch in enumerate(s):
if ch in digits:
break
if ch == '?':
count_2 = count_2 * 9 + 1
continue
if ch in letters:
if ch not in letters_used:
if not letters_used:
count_2 = count_2 * 9 + 1
else:
count_2 = count_2 * (10 - len(letters_used))
letters_used.add(ch)
print(count_1, count_2)
print(count_1[len(s)] - count_2)
``` | instruction | 0 | 32,842 | 20 | 65,684 |
No | output | 1 | 32,842 | 20 | 65,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
#!/bin/python
string = input()
is_leading = True
leading_letters = set()
all_letters = set()
number_of_leading_question_marks = 0;
number_of_non_leading_question_marks = 0;
for character in string:
if character.isdigit():
is_leading = False
elif character.isalpha():
all_letters.add(character)
if is_leading:
leading_letters.add(character)
is_leading = False
else:
if is_leading:
number_of_leading_question_marks += 1
is_leading = True
else:
number_of_non_leading_question_marks += 1
number_of_leading_letters = len(leading_letters)
number_of_non_leading_letters = len(all_letters - leading_letters)
solution = 9 ** number_of_leading_question_marks * 10 ** number_of_non_leading_question_marks
def fact(n):
a = 1
for b in range(1, n + 1):
a *= b
return a
if number_of_leading_letters == 1:
solution *= 9 * fact(9) / fact(9 - number_of_non_leading_letters)
else:
solution *= fact(10) / fact(10 - number_of_non_leading_letters)
print(int(solution))
``` | instruction | 0 | 32,843 | 20 | 65,686 |
No | output | 1 | 32,843 | 20 | 65,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
s = str(input())
result = 1
n = len(s)
print(s)
rozne = set()
for i in range(0,n):
if ord(s[i]) >= ord('0') and ord(s[i]) <= ord('9'):
continue;
elif ord(s[i]) >= ord('A') and ord(s[i]) <= ord('Z'):
rozne.add(ord(s[i]))
continue
else:
if i == 0:
result = result * 9
else:
result = result * 10
for i in range(0, len(rozne)):
result = result * (10 - i)
if ord(s[0]) >= ord('A') and ord(s[0]) <= ord('Z'):
result = result / 10 * 9
print(int(result))
``` | instruction | 0 | 32,844 | 20 | 65,688 |
No | output | 1 | 32,844 | 20 | 65,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
if __name__ == '__main__':
s = input()
digits = set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
letters = set(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'])
count_1 = {0: 1}
letters_used = set()
for i, ch in enumerate(s):
if ch in digits:
count_1[i + 1] = count_1[i]
continue
if ch == '?':
count_1[i + 1] = count_1[i] * 10
continue
if ch in letters:
if ch not in letters_used:
count_1[i + 1] = count_1[i] * (10 - len(letters_used))
letters_used.add(ch)
continue
count_1[i + 1] = count_1[i]
count_2 = 0
letters_used = set()
for i, ch in enumerate(s):
if ch in digits:
break
if ch == '?':
count_2 = count_2 * 9 + 1
continue
if ch in letters:
if ch not in letters_used:
if not letters_used:
count_2 = count_2 * 9 + 1
else:
count_2 = count_2 * (10 - len(letters_used))
letters_used.add(ch)
print(count_1[len(s)] - count_2)
``` | instruction | 0 | 32,845 | 20 | 65,690 |
No | output | 1 | 32,845 | 20 | 65,691 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | instruction | 0 | 32,861 | 20 | 65,722 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,k = input().split()
n,k = int(n), int(k)
for i in range(n):
for j in range(n):
if i==j:
print(k, end=' ')
else:
print(0, end=' ')
print('')
``` | output | 1 | 32,861 | 20 | 65,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | instruction | 0 | 32,862 | 20 | 65,724 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,k=map(int,input().split())
for i in range(n):
b=[]
for j in range(n):
if j==i:
b.append(k)
else:
b.append(0)
print(*b)
``` | output | 1 | 32,862 | 20 | 65,725 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | instruction | 0 | 32,863 | 20 | 65,726 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n, k = map(int,input().split())
for i in range(n):
for j in range(i,n-1):
print(0,end = ' ')
print(k,end = ' ')
for j in range(n-i,n):
print(0,end = ' ')
print()
``` | output | 1 | 32,863 | 20 | 65,727 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | instruction | 0 | 32,864 | 20 | 65,728 |
Tags: constructive algorithms, implementation
Correct Solution:
```
string = input()
numbers = string.split()
a, b = int(numbers[0]), int(numbers[1])
row = [0 for x in range(a - 1)]
row.append(b)
for x in range(a):
print(" ".join(map(str, row[x:] + row[:x])))
``` | output | 1 | 32,864 | 20 | 65,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | instruction | 0 | 32,865 | 20 | 65,730 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,k=map(int,input().split())
for i in range(n):
l=[]
for j in range(n):
if(i==j):
l.append(k)
else:
l.append(0)
print(*l)
``` | output | 1 | 32,865 | 20 | 65,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | instruction | 0 | 32,866 | 20 | 65,732 |
Tags: constructive algorithms, implementation
Correct Solution:
```
a = input().split()
n = int(a[0])
x = int(a[1]) - n + 1
for i in range(n):
for j in range(n):
if i == j:
print(x , end = " ")
else:
print(1 , end = " ")
print()
``` | output | 1 | 32,866 | 20 | 65,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | instruction | 0 | 32,867 | 20 | 65,734 |
Tags: constructive algorithms, implementation
Correct Solution:
```
a, b = map(int, input().split())
c = [1 for i in range(a)]
for j in range(a):
if c[j] == 1:
c[j] = b - (a-1)
print(*c, sep=' ')
c = [1 for i in range(a)]
``` | output | 1 | 32,867 | 20 | 65,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
Output
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Examples
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
Note
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | instruction | 0 | 32,868 | 20 | 65,736 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,temp = map(int,input().split())
val = 0
arr = [[val for i in range(n)] for j in range(n)]
for i in range(n):
arr[i][i]=temp
for i in range(n):
for j in range(n):
print(arr[i][j],end=' ')
print("")
``` | output | 1 | 32,868 | 20 | 65,737 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916 | instruction | 0 | 33,165 | 20 | 66,330 |
"Correct Solution:
```
n = int(input())
ans = 0
for i in range(1,n):
if (n-i)/i > i:
if (n-i)%i == 0:
ans += (n-i)/i
else:
break
print(int(ans))
``` | output | 1 | 33,165 | 20 | 66,331 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916 | instruction | 0 | 33,166 | 20 | 66,332 |
"Correct Solution:
```
N=int(input())
ans=0
i=1
while i*(i+1)+i<=N:
if N%i==0:
ans+=(N-i)//i
i+=1
print(ans)
``` | output | 1 | 33,166 | 20 | 66,333 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916 | instruction | 0 | 33,167 | 20 | 66,334 |
"Correct Solution:
```
N = int(input())
ans = 0
for a in range(1,int(N**0.5)+1):
if N%a == 0:
m = N//a - 1
if a < m:
ans += m
print(ans)
``` | output | 1 | 33,167 | 20 | 66,335 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.