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 tags and a correct Python 3 solution for this coding contest problem.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | instruction | 0 | 27,961 | 20 | 55,922 |
Tags: brute force, greedy, implementation
Correct Solution:
```
s = input()
l = list()
l1 = list(map(int, s[:3]))
l2 = list(map(int, s[3:]))
if sum(l1) > sum(l2):
l1, l2 = l2, l1
suml, sumr = sum(l1), sum(l2)
for i, j in zip(l1, l2):
l.append(9 - i)
l.append(j)
l.sort(reverse = True)
ans = 0
for i in l:
if suml >= sumr: break
suml += i
ans += 1
print(ans)
``` | output | 1 | 27,961 | 20 | 55,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | instruction | 0 | 27,962 | 20 | 55,924 |
Tags: brute force, greedy, implementation
Correct Solution:
```
l=list(input())
a=list(map(int,l))
l1=a[0:3]
l2=a[3:6]
if sum(l1)>sum(l2):
b=l2
l2=l1
l1=b
l1.sort()
l2.sort()
d=sum(l2)-sum(l1)
if d==0:
print("0")
else:
i=0
j=2
c=0
while d>0 :
if l1==[]:
d-=l2[j]
l2.remove(l2[j])
j-=1
c+=1
elif l2==[]:
d-=(9-l1[0])
l1.remove(l[0])
c+=1
elif (9-l1[0])>=l2[j]:
d-=(9-l1[i])
l1.remove(l1[i])
c+=1
else:
d-=l2[j]
l2.remove(l2[j])
j-=1
c+=1
print(c)
``` | output | 1 | 27,962 | 20 | 55,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | instruction | 0 | 27,963 | 20 | 55,926 |
Tags: brute force, greedy, implementation
Correct Solution:
```
entrada = list(map(int, input()))
l = entrada[:3]
r = entrada[3:]
sl = l[0] + l[1] + l[2]
sr = r[0] + r[1] + r[2]
l.sort()
r.sort()
if sl == sr:
print(0)
elif sl < sr:
dif = abs(sl-sr)
if dif <= r[2] or dif + l[0] <= 9:
print(1)
else:
if 9-l[0] == r[2]:
dif -= r[2]
if dif <= r[1] or dif + l[0] <= 9:
print(2)
else:
print(3)
elif 9-l[0] < r[2]:# se vale a pena remover da direita...
dif -= r[2] # entao remove
if dif <= r[1] or dif + l[0] <= 9:
print(2)
else:
print(3)
elif 9-l[0] > r[2]: # se valeu a pena acrescentar na esquerda...
dif -= 9-l[0] # entao coloca
if dif <= r[2] or dif + l[1] <= 9:
print(2)
else:
print(3)
else:
l, r = r, l
dif = abs(sl - sr)
if dif <= r[2] or dif + l[0] <= 9:
print(1)
else:
if 9 - l[0] == r[2]:
dif -= r[2]
if dif <= r[1] or dif + l[0] <= 9:
print(2)
else:
print(3)
elif 9 - l[0] < r[2]: # se vale a pena remover da direita...
dif -= r[2] # entao remove
if dif <= r[1] or dif + l[0] <= 9:
print(2)
else:
print(3)
elif 9 - l[0] > r[2]: # se valeu a pena acrescentar na esquerda...
dif -= 9 - l[0] # entao coloca
if dif <= r[2] or dif + l[1] <= 9:
print(2)
else:
print(3)
``` | output | 1 | 27,963 | 20 | 55,927 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | instruction | 0 | 27,964 | 20 | 55,928 |
Tags: brute force, greedy, implementation
Correct Solution:
```
p = [int(x) for x in input()]
ans = []
for a in range(10) :
for b in range(10) :
for c in range(10) :
for d in range(10) :
for e in range(10) :
f = a + b + c - d - e
o = [a, b, c, d, e, f]
delta = 0
if 0 <= f <= 9 :
for i in range(6) :
if p[i] != o[i] :
delta += 1
ans.append(delta)
print(min(ans))
``` | output | 1 | 27,964 | 20 | 55,929 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | instruction | 0 | 27,965 | 20 | 55,930 |
Tags: brute force, greedy, implementation
Correct Solution:
```
s = str(input())
r = []
for el in s:
r.append(int(el))
l1 = r[0:3]
l2 = r[3:6]
if sum(l1) < sum(l2):
l1, l2 = l2, l1
s = abs(sum(l1) - sum(l2))
if s == 0:
print(0)
else:
usable = []
for e in l1:
usable.append(e)
for e in l2:
usable.append(9-e)
usable.sort(reverse = True)
i = 0
while s > 0:
s -= usable[i]
i += 1
print(i)
``` | output | 1 | 27,965 | 20 | 55,931 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | instruction | 0 | 27,966 | 20 | 55,932 |
Tags: brute force, greedy, implementation
Correct Solution:
```
s=input()
a,b = sorted(list(map(int,s[:3:]))), sorted(list(map(int,s[3::])))
sma,smb=sum(a),sum(b)
if sum(a) < sum(b):
mn, mx = a, b[::-1]
else:
mn, mx = b, a[::-1]
k1, k2=0, 0
while (sum(mn) < sum(mx)):
if 9-mn[k1] >= mx[k2]:
mn[k1] = 9
k1+=1
else:
mx[k2] = 0
k2+=1
print(k1+k2)
``` | output | 1 | 27,966 | 20 | 55,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Submitted Solution:
```
s = input()
a = [int(x) for x in s[:3]]
b = [int(x) for x in s[3:]]
a.sort()
b.sort()
if sum(a) > sum(b):
a, b = b, a
if sum(a) == sum(b):
print(0)
exit()
dt = sum(b) - sum(a)
diffs = []
for i in a:
diffs.append(9-i)
diffs.extend(b)
diffs.sort()
i = 0
while dt > 0:
dt -= diffs[5-i]
i += 1
print(i)
``` | instruction | 0 | 27,967 | 20 | 55,934 |
Yes | output | 1 | 27,967 | 20 | 55,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Submitted Solution:
```
def work():
s = input()
a = [int(s[0]), int(s[1]), int(s[2])]
b = [int(s[3]), int(s[4]), int(s[5])]
if sum(a) == sum(b):
print(0)
return
if sum(a) > sum(b):
a, b = b, a
# now sum(a) < sum(b)
a = sorted(a)
b = sorted(b)
ben = [9-a[0], 9-a[1], 9-a[2], b[0], b[1], b[2]]
ben = sorted(ben)[::-1]
k = sum(b) - sum(a)
t = 0
i = 0
while t < k:
t += ben[i]
i += 1
print(i)
return
work()
``` | instruction | 0 | 27,968 | 20 | 55,936 |
Yes | output | 1 | 27,968 | 20 | 55,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Submitted Solution:
```
a = list(map(int, input()))
b = a[:3]
a = a[3:]
if sum(a) > sum(b):
a, b = b, a
d = sum(b) - sum(a)
if d == 0:
print(0)
exit()
t = list(b)
for i in a:
t.append(9-i)
for i, j in enumerate(sorted(t, reverse=True)):
d -= j
if d <= 0:
print(i+1)
break
``` | instruction | 0 | 27,969 | 20 | 55,938 |
Yes | output | 1 | 27,969 | 20 | 55,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Submitted Solution:
```
s=input()
left = [int(s[0]), int(s[1]), int(s[2])]
right = [int(s[3]), int(s[4]), int(s[5])]
s1 = sum(left)
s2 = sum(right)
if s1 > s2:
t = left
left = right
right = t
s1 = sum(left)
s2 = sum(right)
if s1 == s2 :
print(0)
else:
dif = s2 - s1
if left[0] + dif <= 9 or left[1] + dif <= 9 or left[2] + dif <= 9 or right[0] - dif >= 0 or right[1] - dif >= 0 or right[2] - dif >= 0:
print(1)
elif left[0] + left[1] + dif <= 18 or left[1] + left[2] + dif <= 18 or left[2] + left[0] + dif <= 18 \
or right[0] + right[1] - dif >= 0 or right[1] +right[2]- dif >= 0 or right[2] + right[0]- dif >= 0:
print(2)
else:
ans = 3
for i in range(3):
for j in range(3):
if (dif - right[j] <= 9 - left[i]):
ans = 2
break
print(ans)
``` | instruction | 0 | 27,970 | 20 | 55,940 |
Yes | output | 1 | 27,970 | 20 | 55,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Submitted Solution:
```
n=(input())
f=list(map(int,(n[:3])))
l=list(map(int,(n[3:])))
s=0
k=0
sf=sum(f)
sl=sum(l)
if sl> sf:
d=sl-sf
f.sort()
l.sort()
if (f[0]+d)>=10:
if f[1]+(f[0]-10)+d>=10:
s=3
else:
s=2
else:
s=1
if l[2]-d<0:
if l[1]-d+l[2]<0:
k=3
else:
k=2
else:
k=1
elif sf> sl:
d=sf-sl
l.sort()
f.sort()
if l[0]+d>=10:
if l[1]+(l[0]-10)+d>=10:
s=3
else:
s=2
else:
s=1
if f[2]-d<0:
if f[1]+(f[2]-d)<0:
k=3
else:
k=2
else:
k=1
print(min(s,k))
``` | instruction | 0 | 27,971 | 20 | 55,942 |
No | output | 1 | 27,971 | 20 | 55,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Submitted Solution:
```
a=[int(i) for i in input()]
if sum(a[3:])>sum(a[:3]):
a[:3],a[3:]=a[3:],a[:3]
a[:3]=sorted(a[:3],reverse=True)
a[3:]=sorted(a[3:])
#print(a)
ans=0
i=0; j=5
while sum(a[:3])>sum(a[3:]):
ans+=1
#print(sum(a[:3]),sum(a[3:]),'i',i,'j',j)
if a[i]>9-a[j]:
a[i]=0
i+=1
else:
a[j]=9
j-=1
print(ans)
``` | instruction | 0 | 27,972 | 20 | 55,944 |
No | output | 1 | 27,972 | 20 | 55,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Submitted Solution:
```
s = input()
a = sorted(list(map(int, list(s[:3]))))
b = sorted(list(map(int, list(s[3:]))), reverse=True)
if sum(a) > sum(b):
a, b = b, a
d = []
for i in range(3):
d.append(b[i] - a[i])
d.sort()
ans1 = min(sum(d) // 9 + 1, 3) if sum(d) > 0 else 0
x = d[0] + d[1]
if d[2] - 9 + x <= 0:
ans1 = 1
print(ans1, d)
``` | instruction | 0 | 27,973 | 20 | 55,946 |
No | output | 1 | 27,973 | 20 | 55,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Examples
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
Note
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
Submitted Solution:
```
def main():
digits = input()
li = list(digits)
digits = list(map(int, li))
first = digits[:3]
second = digits[3:]
first.sort()
second.sort()
sumf = sum(first)
sums = sum(second)
if sumf == sums:
print('0')
return
elif sumf < sums:
small = 1
else:
small = 2
if small == 1:
diff = sums - sumf
cnt1 = 0
for i in range(0, 3):
diff = diff + first[i]
if diff<=9:
cnt1 = cnt1+1
break
else:
diff = diff - 9
cnt1 = cnt1+1
cnt2 = 0
diff = sums - sumf
for i in range(2, -1, -1):
diff = diff - second[i]
#print(diff)
if diff <= 0:
cnt2 = cnt2 + 1
break
else:
cnt2 = cnt2 + 1
#print(cnt1)
#print(cnt2)
result = min(cnt1, cnt2)
else:
cnt1 = 0
diff = sumf - sums
for i in range(0, 3):
diff = diff + second[i]
if diff<=9:
cnt1 = cnt1 +1
break
else:
diff = diff - 9
cnt1 = cnt1 + 1
cnt2 = 0
diff = sumf - sums
for i in range(2, -1, -1):
diff = diff - first[i]
if diff <= 0:
cnt2 = cnt2 + 1
break
else:
cnt2 = cnt2 + 1
result = min(cnt1, cnt2)
print(result)
if __name__ == "__main__":
main()
``` | instruction | 0 | 27,974 | 20 | 55,948 |
No | output | 1 | 27,974 | 20 | 55,949 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20 | instruction | 0 | 27,983 | 20 | 55,966 |
Tags: math, number theory
Correct Solution:
```
LEN1 = 31
LEN2 = 50
MOD = 10 ** LEN2
def binpow(a, b, mod):
x = 1
y = a
while b > 0:
if b % 2:
x = x * y % mod
y = y * y % mod
b //= 2
return x
def solve(n):
n = n * 10 ** LEN1
diff = (2 ** LEN2 - n) % 2 ** LEN2
if diff < 0:
diff += 2 ** LEN2
#print(diff)
#print(n)
#print(n + diff)
if diff % 5 == 0:
diff += 2 ** LEN2
n += diff
#if (n % (2 ** LEN2) != 0):
# print("bad\n")
#if (n % 5 == 0):
# print("bad2\n")
#print(n)
n %= (5 ** LEN2)
k = 0
#print(n)
for i in range(5):
if ((2 ** k) % 5) == (n % 5):
break
#print((2 ** k) % 5)
#print(n % 5);
#print()
k += 1
Pow = 1
Pow2 = 2 ** k # 2 ** k % MOD
Pow25 = 2 ** 4 # 2 ** (4 * Pow) % MOD
for i in range(2, LEN2 + 1):
res = n % (25 * Pow)
for j in range(5):
if Pow2 % (25 * Pow) == res:
break
k += 4 * Pow
Pow2 *= Pow25
#print("val: ", Pow25 % (5 * Pow))
Pow2 %= MOD
#print(Pow2 % (5 * Pow))
if (Pow2 % (25 * Pow) != res):
print("bad\n");
Pow *= 5
Pow25 = Pow25 * Pow25 % MOD * Pow25 % MOD * Pow25 % MOD * Pow25 % MOD
#print(binpow(2, k, 5 ** LEN2))
#print(n)
return k
n = int(input())
a = [int(input()) for i in range(n)]
#print(a)
for x in a:
print(solve(x))
``` | output | 1 | 27,983 | 20 | 55,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20 | instruction | 0 | 27,984 | 20 | 55,968 |
Tags: math, number theory
Correct Solution:
```
def lift(n, a):
# base: mod 5
x = 0
while pow(2, x, 5) != a % 5:
x += 1
for i in range(2, n + 1):
mod, phi, step = pow(5, i), 4 * pow(5, i - 1), 4 * pow(5, i - 2)
while pow(2, x, mod) != a % mod:
x += step
if x >= phi:
x -= phi
return x
def solve(a):
n = len(str(a))
m = 0
while 10 ** m / (2 ** (n + m)) * 4 / 5 < n + m + 1:
m += 1
pw2, pw5 = 2 ** (n + m), 5 ** (n + m)
b = a * 10 ** m % pw2
if b != 0:
b = pw2 - b
while b < 10 ** m:
if b % 5 != 0:
k = lift(n + m, (a * 10 ** m + b) % pw5)
if k >= n + m:
return k
b += pw2
for _ in range(int(input())):
a = int(input())
k = solve(a)
assert str(a) in str(pow(2, k, 10 ** 100))
print(k)
``` | output | 1 | 27,984 | 20 | 55,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20 | instruction | 0 | 27,985 | 20 | 55,970 |
Tags: math, number theory
Correct Solution:
```
import time
start = time.time()
mod=5;
G=4
def ModPow(exp):
if exp==0:return 1;
if exp%2==1:return (2*ModPow(exp-1))%mod;
A=ModPow(exp//2);
return (A*A)%mod;
t=int(input());
while t>0:
t=t-1;
x=int(input());
mod=5
G=4
a=(10**12)*x;
k=(2**23)-a;
k%=(2**23);
k+=(2**23);
k%=(2**23);
X=a+k;
if X%5==0:
X+=(2**23);
power=int(0);
while ModPow(power)%5!=X%5:
power=power+1;
turn=2
mod*=5;
while turn<=23:
while ModPow(power)%mod!=X%mod:
power+=G;
#print("A");
#print(ModPow(2,power));
#print(X%mod);
#print(ModPow(2,5*G));
turn=turn+1;
mod=mod*5;
G=G*5;
print(power);
##mod=mod//5;
#print(X%mod);
#print(X0%mod);
end = time.time()
##print(end - start)
``` | output | 1 | 27,985 | 20 | 55,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20 | instruction | 0 | 27,986 | 20 | 55,972 |
Tags: math, number theory
Correct Solution:
```
import sys
#sys.stdout = open('output.txt', 'w')
#sys.stdin = open('input.txt', 'r')
#for line in sys.stdin:
#while 1:
# line = sys.stdin.readline()
# if line:
# print (line,end="")
def phi(p,i):
if i == 0:
return 1
return p**i - p**(i-1)
def pwr(x,p,mod):
if p == 0:
return 1
if p%2 == 1:
return x*pwr(x*x%mod,p//2,mod)%mod
else:
return pwr(x*x%mod,p//2,mod)
n = int(input())
m = 6
for _ in range(0,n):
x = input()
k = len(x)+m
ten = 10**k
two = 2**k
five = 5**k
x = int(x)
x *= 10**m
x += ((two-x)%two+two)%two
if x % 5 == 0:
x += two
x /= two
ans = 0
for i in range(1,k+1):
y = x%(5**i)
for j in range(0,5):
d = ans+j*phi(5,i-1)
if pwr(2,d,5**i) == y:
ans = d
break
print(ans+k)
``` | output | 1 | 27,986 | 20 | 55,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20 | instruction | 0 | 27,987 | 20 | 55,974 |
Tags: math, number theory
Correct Solution:
```
MOD = 10**18
def pow2(n):
if n == 0:
return 1
if n % 2:
return (2 * pow2(n-1)) % MOD
c = pow2(n//2)
return (c*c) % MOD
n = int(input())
start2 = pow2(1000)
p2 = [pow2(4*(5**x)) for x in range(50)]
c2 = [10**x for x in range(50)]
c3 = [4*(5**x) for x in range(50)]
for tt in range(n):
q = int(input())
f = q * 10**7
f = f // (2**18)
f = f + 1
while(f % 5 == 0):
f = f + 1
f = f * (2**18)
ans = 1000
s2 = start2
for i in range(1, 19):
while((pow2(ans) % c2[i]) != (f % c2[i]) ):
if(i == 1):
ans = ans + 1
s2 = (s2 * 2) % MOD
elif(i > 1):
ans = ans + c3[i-2]
s2 = (s2 * p2[i-2]) % MOD
print(ans)
``` | output | 1 | 27,987 | 20 | 55,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20 | instruction | 0 | 27,988 | 20 | 55,976 |
Tags: math, number theory
Correct Solution:
```
import sys
import math
from decimal import *
line = lambda: list(int(x) for x in input().split())
def pow(a, k, p):
r = 1
t = a
while k > 0:
if k % 2 == 1:
r = r * t % p
t = t * t % p
k >>= 1
return r
test = int(input())
for i in range(0, test):
x = int(input())
x = x * 10 ** 6
x += (2 ** 17 - x % 2 ** 17) % 2 ** 17
if x % 5 == 0:
x += 2 ** 17;
res = 0
for i in range(1, 17 + 1):
while pow(2, res, 5 ** i) != x % 5 ** i:
if i == 1:
res += 1
else:
res += 4 * 5 ** (i - 2)
res += 4 * 5 ** 16
print(res)
``` | output | 1 | 27,988 | 20 | 55,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20 | instruction | 0 | 27,989 | 20 | 55,978 |
Tags: math, number theory
Correct Solution:
```
import sys
import random
N = 20
ntest = int(sys.stdin.readline())
for _ in range(ntest):
target = int(sys.stdin.readline())
# target = random.randint(1, 10 ** 11 - 1)
# savetarget = target
divtarget = 2 ** N
target_min = target
target_max = target + 1
while True:
target_min *= 10
target_max *= 10
if target_min // divtarget == (target_max - 1) // divtarget:
# assert target_max - target_min < 3 * divtarget
continue
target = (target_max - 1) // divtarget
if target % 5 == 0:
target -= 1
# assert target % 5 != 0
target *= divtarget
# assert target % divtarget == 0
if target >= target_min:
break
# print(target)
# del target_max
# del target_min
# del divtarget
mod = 10 ** 0
base = N
gap = 1
for i in range(100):
# print(pow(2, base, mod));
mod *= 10
target_mod = target % mod
# assert mod == 10 ** (1+i)
# assert target_mod % (2 ** (1+i)) == 0
# print('>>>', target_mod)
cur = pow(2, base, mod)
cur_mul = pow(2, gap, mod)
while cur != target_mod:
# print(pow(2, base, mod));
base += gap
cur = (cur * cur_mul) % mod
newgap = gap
base += gap
cur = pow(2, base, mod)
while cur != target_mod:
# print(pow(2, base, mod));
base += gap
newgap += gap
cur = (cur * cur_mul) % mod
# assert pow(2, base + newgap, mod) == target_mod
gap = newgap
if mod > target: break
print(base)
# debug below
# a = str(savetarget)
# b = str(pow(2, base, mod))
# print(b)
# assert b[:len(a)] == a, (b[:len(a)], a)
# print(10 ** 50)
``` | output | 1 | 27,989 | 20 | 55,979 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20 | instruction | 0 | 27,990 | 20 | 55,980 |
Tags: math, number theory
Correct Solution:
```
m10=10000000000
mp=21
p2=2**mp
def qmd(log, md):
ans=1
a=2
while log>0:
if log%2:
ans=ans*a%md
log=log//2
a=a*a%md
return ans
n=int(input())
for nn in range(n):
a=int(input())
#print(a)
x=a*m10//p2*p2+p2
while x%5==0:
x+=p2
#print(x)
log=0
while 2**log%5!=x%5:
log+=1
#print(log)
md=5
phi=4
for i in range(1, mp):
md*=5
#print(x%md)
while qmd(log,md)!=x%md:
log+=phi
#print('log'+str(log))
phi*=5
if log<mp:
log+=phi
print(log)
#print(qmd(log,10**mp))
``` | output | 1 | 27,990 | 20 | 55,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't have to minimize ki. The decimal notations in this problem do not contain leading zeros.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011).
Output
Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.
Examples
Input
2
8
2
Output
3
1
Input
2
3
4857
Output
5
20
Submitted Solution:
```
#from math import *
from sys import *
#from decimal import *
#getcontext().prec = 100
#in_ = open("input.txt","r")
#out_ = open("output.txt","w")
mod = 10 ** 100
n = int(input())
a = []
for i in range(n):
a += input().split()
ans = [-1] * n
cnt = 0
k = 0
while cnt < n:
kek = str(pow(2, k, mod))
for i in range(n):
if ans[i] == -1 and kek.find(a[i]) != -1:
ans[i] = k
cnt += 1
k += 1
for i in range(n):
print(ans[i])
``` | instruction | 0 | 27,998 | 20 | 55,996 |
No | output | 1 | 27,998 | 20 | 55,997 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007 (109 + 7).
Examples
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
Note
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). | instruction | 0 | 28,596 | 20 | 57,192 |
Tags: implementation, math
Correct Solution:
```
a,b=map(int,input().split())
n=int(input())
ans=[a,b,b-a,-a,-b,a-b]
print(ans[(n-1)%6]%(10**9 + 7))
``` | output | 1 | 28,596 | 20 | 57,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007 (109 + 7).
Examples
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
Note
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). | instruction | 0 | 28,597 | 20 | 57,194 |
Tags: implementation, math
Correct Solution:
```
x,y = map(int,input().split())
n=int(input())
z=[x,y,y-x,-x,-y,x-y]
print(z[n%6-1]% (10**9+7))
``` | output | 1 | 28,597 | 20 | 57,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007 (109 + 7).
Examples
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
Note
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). | instruction | 0 | 28,598 | 20 | 57,196 |
Tags: implementation, math
Correct Solution:
```
x, y = list(map(int, input().split()))
n = int(input())
mod = 1000000007
arr = []
arr.append(x)
arr.append(y)
arr.append(y-x)
arr.append(-x)
arr.append(-y)
arr.append(x-y)
a = n % 6
#print(a)
print(arr[a-1] % mod)
#print(arr)
``` | output | 1 | 28,598 | 20 | 57,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007 (109 + 7).
Examples
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
Note
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). | instruction | 0 | 28,599 | 20 | 57,198 |
Tags: implementation, math
Correct Solution:
```
x,y= map(int, input().split())
n= int(input())
seq=[x , y , y-x , -x ,-y , x-y]
d= n%6
print(seq[d-1]%1000000007 )
``` | output | 1 | 28,599 | 20 | 57,199 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007 (109 + 7).
Examples
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
Note
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). | instruction | 0 | 28,600 | 20 | 57,200 |
Tags: implementation, math
Correct Solution:
```
def main():
MOD = 1000000007
(x, y) = map(int, input().split(' '))
n = int(input())
out = [x - y, x, y, y - x, -x, -y]
ret = out[n % 6]
print(ret % MOD)
main()
``` | output | 1 | 28,600 | 20 | 57,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007 (109 + 7).
Examples
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
Note
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). | instruction | 0 | 28,601 | 20 | 57,202 |
Tags: implementation, math
Correct Solution:
```
mod=1000000007
x,y=map(int,input().split())
n=int(input())
if n%6==0:
ans=x-y
print(ans%mod)
if n%6==1:
ans=x
print(ans%mod)
if n%6==2:
ans=y
if ans>0:
print(ans%mod)
else:
print(mod+ans)
if n%6==3:
ans=y-x
print(ans%mod)
if n%6==4:
ans=-x
print(ans%mod)
if n%6==5:
ans=-y
print(ans%mod)
``` | output | 1 | 28,601 | 20 | 57,203 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007 (109 + 7).
Examples
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
Note
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). | instruction | 0 | 28,602 | 20 | 57,204 |
Tags: implementation, math
Correct Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/450/B
x, y = map(int, input().split())
n = int(input())
if n % 6 == 1:
print(x % int(1e9 + 7))
elif n % 6 == 2:
print(y % int(1e9 + 7))
elif n % 6 == 3:
print((y - x) % int(1e9 + 7))
elif n % 6 == 4:
print(-x % int(1e9 + 7))
elif n % 6 == 5:
print(-y % int(1e9 + 7))
elif n % 6 == 0:
print((x - y) % int(1e9 + 7))
``` | output | 1 | 28,602 | 20 | 57,205 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007 (109 + 7).
Examples
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
Note
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6). | instruction | 0 | 28,603 | 20 | 57,206 |
Tags: implementation, math
Correct Solution:
```
def discos():
x = int()
y = int
z =int
n = int
ans = list()
x, y = [int(x) for x in input().split()]
n = int(input())
ans = [x-y, x, y, y-x, -x, -y];
z = (ans[n%6]%1000000007 + 1000000007) % 1000000007
print(z)
return
discos()
``` | output | 1 | 28,603 | 20 | 57,207 |
Provide a correct Python 3 solution for this coding contest problem.
Number of tanka
Wishing to die in the spring under the flowers
This is one of the famous tanka poems that Saigyo Hoshi wrote. Tanka is a type of waka poem that has been popular in Japan for a long time, and most of it consists of five phrases and thirty-one sounds of 5, 7, 5, 7, and 7.
By the way, the number 57577 consists of two types, 5 and 7. Such a positive integer whose decimal notation consists of exactly two types of numbers is called a tanka number. For example, 10, 12, 57577, 25252 are tanka numbers, but 5, 11, 123, 20180701 are not tanka songs.
A positive integer N is given. Find the Nth smallest tanka number.
Input
The input consists of up to 100 datasets. Each dataset is represented in the following format.
> N
The integer N satisfies 1 ≤ N ≤ 1018.
The end of the input is represented by a single zero line.
Output
For each dataset, output the Nth smallest tanka number on one line.
Sample Input
1
2
3
390
1124
1546
314159265358979323
0
Output for the Sample Input
Ten
12
13
2020
25252
57577
7744444777744474777777774774744777747477444774744744
Example
Input
1
2
3
390
1124
1546
314159265358979323
0
Output
10
12
13
2020
25252
57577
7744444777744474777777774774744777747477444774744744 | instruction | 0 | 29,063 | 20 | 58,126 |
"Correct Solution:
```
N = int(input())
while N:
l = 2
N -= 1
while N >= ((1<<(l - 1)) - 1)*81:
N -= ((1<<(l - 1)) - 1)*81
l += 1
s = N // (((1<<(l - 1)) - 1)*9) + 1
N %= ((1<<(l - 1)) - 1)*9
t = -1
ans = str(s)
#print("N = ", N)
while t < 0:
for i in range(s):
if(N >= (1<<(l - 2))):
N -= (1<<(l - 2))
else:
t = i
break
if t >= 0:
continue
if N >= ((1<<(l - 2)) - 1)*9:
N -= ((1<<(l - 2)) - 1)*9
for i in range(s+1, 10):
if N >= (1<<(l-2)):
N -= (1<<(l-2))
else:
t = i
break
else:
l -= 1
ans += str(s)
#print("N = ", N)
ans += str(t)
if s > t:
b = bin(N)[2:]
ans_ = str(t)*(l - 1 - len(b))
C = [str(t), str(s)]
else:
b = bin(N)[2:]
ans_ = str(s)*(l - 1 - len(b))
C = [str(s), str(t)]
for i in range(len(b)):
ans_ += C[int(b[i])]
print(ans+ans_[1:])
N = int(input())
``` | output | 1 | 29,063 | 20 | 58,127 |
Provide a correct Python 3 solution for this coding contest problem.
Number of tanka
Wishing to die in the spring under the flowers
This is one of the famous tanka poems that Saigyo Hoshi wrote. Tanka is a type of waka poem that has been popular in Japan for a long time, and most of it consists of five phrases and thirty-one sounds of 5, 7, 5, 7, and 7.
By the way, the number 57577 consists of two types, 5 and 7. Such a positive integer whose decimal notation consists of exactly two types of numbers is called a tanka number. For example, 10, 12, 57577, 25252 are tanka numbers, but 5, 11, 123, 20180701 are not tanka songs.
A positive integer N is given. Find the Nth smallest tanka number.
Input
The input consists of up to 100 datasets. Each dataset is represented in the following format.
> N
The integer N satisfies 1 ≤ N ≤ 1018.
The end of the input is represented by a single zero line.
Output
For each dataset, output the Nth smallest tanka number on one line.
Sample Input
1
2
3
390
1124
1546
314159265358979323
0
Output for the Sample Input
Ten
12
13
2020
25252
57577
7744444777744474777777774774744777747477444774744744
Example
Input
1
2
3
390
1124
1546
314159265358979323
0
Output
10
12
13
2020
25252
57577
7744444777744474777777774774744777747477444774744744 | instruction | 0 | 29,064 | 20 | 58,128 |
"Correct Solution:
```
def solve(N):
k = 0
rng = 0
for i in range(54):
if cl[i] < N <= cl[i+1]:
k = i + 2
rng2 = cl[i]
rng = cl[i+1] - cl[i]
# print(k)
posrng = (N-rng2)%(rng//9)
perrng = (N-rng2)//(rng//9)+1
if posrng == 0:
posrng = rng//9
perrng -= 1
ans = [perrng]
for i in range(k-1):
if i == k-2:
tmp = [0 if j == perrng else 1 for j in range(10)]
else:
tmp = [(cl[k-i-2]-cl[k-i-3])//9 if j == perrng else 2**(k-i-2) for j in range(10)]
if posrng <= tmp[0]:
ans.append(0)
# posrng = posrng
for j in range(1, 10):
tmp[j] += tmp[j-1]
if tmp[j-1] < posrng <=tmp[j]:
ans.append(j)
posrng -= tmp[j-1]
if max(ans) != min(ans):
break
for i in range(k-len(ans), 0, -1):
if posrng <= 2**(i-1):
ans.append(min(ans))
else:
ans.append(max(ans))
posrng -= 2**(i-1)
print(''.join(map(str, ans)))
cl = [sum([9*2**j for j in range(i)])*9 for i in range(55)]
for i in range(1, 55):
cl[i] += cl[i-1]
while True:
N = int(input())
if N == 0:
break
solve(N)
``` | output | 1 | 29,064 | 20 | 58,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Number of tanka
Wishing to die in the spring under the flowers
This is one of the famous tanka poems that Saigyo Hoshi wrote. Tanka is a type of waka poem that has been popular in Japan for a long time, and most of it consists of five phrases and thirty-one sounds of 5, 7, 5, 7, and 7.
By the way, the number 57577 consists of two types, 5 and 7. Such a positive integer whose decimal notation consists of exactly two types of numbers is called a tanka number. For example, 10, 12, 57577, 25252 are tanka numbers, but 5, 11, 123, 20180701 are not tanka songs.
A positive integer N is given. Find the Nth smallest tanka number.
Input
The input consists of up to 100 datasets. Each dataset is represented in the following format.
> N
The integer N satisfies 1 ≤ N ≤ 1018.
The end of the input is represented by a single zero line.
Output
For each dataset, output the Nth smallest tanka number on one line.
Sample Input
1
2
3
390
1124
1546
314159265358979323
0
Output for the Sample Input
Ten
12
13
2020
25252
57577
7744444777744474777777774774744777747477444774744744
Example
Input
1
2
3
390
1124
1546
314159265358979323
0
Output
10
12
13
2020
25252
57577
7744444777744474777777774774744777747477444774744744
Submitted Solution:
```
# 文字列s以下のa,bを使った短歌数
def calc(a, b, s):
sz = len(s)
dp = [[0] * 2 for i in range(sz + 1)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(sz):
if s[i] == str(a):
dp[i + 1][0] += dp[i][0]
elif s[i] > str(a):
if i == 0 and a == 0:
a == 0
else:
dp[i + 1][1] += dp[i][0]
if s[i] == str(b):
dp[i + 1][0] += dp[i][0]
elif s[i] > str(b):
dp[i + 1][1] += dp[i][0]
dp[i + 1][1] += dp[i][1] * 2
# for i in range(sz + 1):
# print(dp[i])
res = dp[sz][0] + dp[sz][1]
if a != 0 and str(a) * sz <= s:
res -= 1
if str(b) * sz <= s:
res -= 1
return res
def check(x, N):
s = str(x)
sz = len(s)
res = 0
for i in range(0, 10):
for j in range(i + 1, 10):
tmp = calc(i, j, s)
res += tmp
for i in range(2, sz):
res += 45 * (2 ** i - 2) - 9 * (2 ** (i - 1) - 1)
return res >= N
while True:
N = int(input())
if N == 0:
break
ng = 1
ok = 10 ** 61
while ok - ng > 1:
mid = (ok + ng) // 2
if (check(mid, N)): ok = mid
else: ng = mid
print(ok)
``` | instruction | 0 | 29,065 | 20 | 58,130 |
No | output | 1 | 29,065 | 20 | 58,131 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628 | instruction | 0 | 29,271 | 20 | 58,542 |
Tags: brute force, implementation, math
Correct Solution:
```
for _ in range(int(input())):
x, k = map(int, input().split())
for i in range(k - 1):
dg = []
x1 = x
while x1 > 0:
dg.append(x1 % 10)
x1 //= 10
x = x + min(dg) * max(dg)
if 0 in dg:
break
print(x)
``` | output | 1 | 29,271 | 20 | 58,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628 | instruction | 0 | 29,272 | 20 | 58,544 |
Tags: brute force, implementation, math
Correct Solution:
```
def minn(m):
mx = 0
mn = 9
while m>0:
a = m%10
mn = min(a,mn)
mx = max(a,mx)
m//=10
return mn*mx
for lo in range(int(input())):
#n = int(input())
n,k = map(int,input().split())
#ls = [int(x) for x in input().split()]
ls = []
m = n
for i in range(k-1):
a = minn(m)
m = m + a
ls.append(a)
if a==0:
break
print(m)
``` | output | 1 | 29,272 | 20 | 58,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628 | instruction | 0 | 29,273 | 20 | 58,546 |
Tags: brute force, implementation, math
Correct Solution:
```
import sys
for _ in range(int(input())):
a,k=map(int,input().split())
if k==1:
print(a)
else:
s=str(a)
if '0' in s:
print(a)
else:
flag=1
for i in range(k-1):
s=str(a)
if '0' in s:
print(a)
flag=0
if flag==1:
ma=-1
mi=10
for i in s:
ma=max(ma,int(i))
mi=min(mi,int(i))
t=ma*mi
a+=t
else:
break
if flag==1:
print(a)
``` | output | 1 | 29,273 | 20 | 58,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628 | instruction | 0 | 29,274 | 20 | 58,548 |
Tags: brute force, implementation, math
Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
def I(): return(list(map(int,input().split())))
def sieve(n):
a=[1]*n
for i in range(2,n):
if a[i]:
for j in range(i*i,n,i):
a[j]=0
return a
for __ in range(int(input())):
a,k=I()
a=str(a)
mi=min(a)
ma=max(a)
for i in range(k-1):
mi=min(a)
ma=max(a)
if mi=="0":
break
a=str(int(a)+int(min(a))*int(max(a)))
print(a)
``` | output | 1 | 29,274 | 20 | 58,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628 | instruction | 0 | 29,275 | 20 | 58,550 |
Tags: brute force, implementation, math
Correct Solution:
```
for j in range(int(input())):
n,k = map(int,input().split())
for i in range(k-1):
n2 = n
max = n2%10
min = n2%10
while(n2>0):
c = n2%10
if c>max:
max = c
if c<min:
min = c
n2 //= 10
if min == 0:
break
n = n + (max*min)
print(n)
``` | output | 1 | 29,275 | 20 | 58,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628 | instruction | 0 | 29,276 | 20 | 58,552 |
Tags: brute force, implementation, math
Correct Solution:
```
t = int(input())
ls = [list(map(int, input().split())) for _ in range(t)]
for i in range(t):
n = ls[i][0]
for j in range(1, ls[i][1]):
l = [int(x) for x in list(str(n))]
mnd = min(l)
mxd = max(l)
n = n + mnd * mxd
if mnd == 0:
break
print(n)
``` | output | 1 | 29,276 | 20 | 58,553 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628 | instruction | 0 | 29,277 | 20 | 58,554 |
Tags: brute force, implementation, math
Correct Solution:
```
t = int(input())
def f(n,mx,mn):
temp = list(str(n))
for i in range(0,len(temp)):
temp[i] = int(temp[i])
if(i==0):
t1 = temp[i]
t2 = temp[i]
else:
t1 = max(t1,temp[i])
t2 = min(t2,temp[i])
# print(t1,t2)
mx[0] = t1
mn[0] = t2
return temp
for p in range(0,t):
n,k = map(int,input().split())
for i in range(0,k-1):
mx= [0]
mn = [0]
temp = f(n,mx,mn)
if(mx[0]==0 or mn[0]==0):
break
# print(mx,mn)
# print(n,max(temp),min(temp))
n = n+ (mx[0]*mn[0])
print(n)
``` | output | 1 | 29,277 | 20 | 58,555 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628 | instruction | 0 | 29,278 | 20 | 58,556 |
Tags: brute force, implementation, math
Correct Solution:
```
t = int(input())
for i in range(0, t):
nums = list(map(int, input().split(' ')))
ak = nums[0]
for j in range(1, nums[1]):
min = '9'
max = '0'
for i in str(ak):
if min > i:
min = i
if max < i:
max = i
ak = ak + (ord(min) - ord('0')) * (ord(max) - ord('0'))
if min == '0':
break
print(ak)
``` | output | 1 | 29,278 | 20 | 58,557 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | instruction | 0 | 29,509 | 20 | 59,018 |
Tags: implementation
Correct Solution:
```
a='012456','25','02346','02356','1235','01356','013456','025','0123456','012356'
b=[set(a[i])for i in range(10)]
c,d=map(int,input())
f,e=0,0
for i in b:f+=i>=b[c];e+=i>=b[d]
print(f*e)
``` | output | 1 | 29,509 | 20 | 59,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | instruction | 0 | 29,510 | 20 | 59,020 |
Tags: implementation
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
dic = { '0' : 2, '1' : 7, '2' : 2, '3' : 3, '4' : 3, '5' : 4, '6' : 2, '7' : 5, '8' : 1, '9' : 2}
n = input()
start = time.time()
ans = dic[n[0]]*dic[n[1]]
print(ans)
finish = time.time()
#print(finish - start)
``` | output | 1 | 29,510 | 20 | 59,021 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | instruction | 0 | 29,511 | 20 | 59,022 |
Tags: implementation
Correct Solution:
```
#!/usr/bin/env python3
digit = input()
good_value = {'0': 2, '1': 7, '2': 2, '3': 3, '4': 3, '5': 4, '6': 2, '7': 5, '8': 1, '9': 2}
print(good_value[digit[0]] * good_value[digit[1]])
``` | output | 1 | 29,511 | 20 | 59,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | instruction | 0 | 29,512 | 20 | 59,024 |
Tags: implementation
Correct Solution:
```
a = [2, 7, 2, 3, 3, 4, 2, 5, 1, 2]
l = int(input())
r = int(l % 10)
l = int(l / 10)
print(a[l] * a[r])
``` | output | 1 | 29,512 | 20 | 59,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | instruction | 0 | 29,513 | 20 | 59,026 |
Tags: implementation
Correct Solution:
```
data = []
data.extend([2,7,2,3,3,4,2,5,1,2])
line = input()
x = data[int(line[0])]
y = data[int(line[1])]
print(x*y)
``` | output | 1 | 29,513 | 20 | 59,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | instruction | 0 | 29,514 | 20 | 59,028 |
Tags: implementation
Correct Solution:
```
n=int(input())
a=int(n//10)
b=int(n%10)
if a==0:
x=1
if a==1:
x=6
if a==2:
x=1
if a==3:
x=2
if a==4:
x=2
if a==5:
x=3
if a==6:
x=1
if a==7:
x=4
if a==8:
x=0
if a==9:
x=1
if b==0:
y=1
if b==1:
y=6
if b==2:
y=1
if b==3:
y=2
if b==4:
y=2
if b==5:
y=3
if b==6:
y=1
if b==7:
y=4
if b==8:
y=0
if b==9:
y=1
print ((x+1)*(y+1))
``` | output | 1 | 29,514 | 20 | 59,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | instruction | 0 | 29,515 | 20 | 59,030 |
Tags: implementation
Correct Solution:
```
def findC(n):
if n == 0:
return [0,8]
elif n == 1:
return [0,1,3,4,7,8,9]
elif n == 2:
return [2,8]
elif n == 3:
return [3,8,9]
elif n == 4:
return [4,8,9]
elif n == 5:
return [5,6,8,9]
elif n == 6:
return [6,8]
elif n == 7:
return [0,3,7,8,9]
elif n == 8:
return [8]
elif n == 9:
return [8,9]
def findCount(n):
return len(findC(n))
n = str(input())
print(findCount(int(n[0]))*findCount(int(n[1])))
``` | output | 1 | 29,515 | 20 | 59,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
<image>
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99) good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.
Input
The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.
Output
In the only line of the output print the number of good integers.
Examples
Input
89
Output
2
Input
00
Output
4
Input
73
Output
15
Note
In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | instruction | 0 | 29,516 | 20 | 59,032 |
Tags: implementation
Correct Solution:
```
a = [2, 7, 2, 3, 3, 4, 2, 5, 1, 2]
n = input()
print(a[int(n[0])] * a[int(n[1])])
``` | output | 1 | 29,516 | 20 | 59,033 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.