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.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | instruction | 0 | 85,466 | 20 | 170,932 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
n = int(input())
ans = []
flag = 0
if n % 2:
n -= 1
flag = 1
if (n % 4 == 0 and not flag) or (n % 4 and flag):
print(0)
for i in range(n // 2):
if i % 2 == 0:
ans.append(i + 1)
ans.append(n - i)
print(len(ans), end=' ')
for i in ans:
print(i, end=' ')
else:
print(1)
for i in range(n // 2 - 1):
if i % 2 == 0:
if i % 2 == 0:
ans.append(i + 1)
ans.append(n - i)
ans.append(n // 2 + 1)
print(len(ans), end=' ')
for i in ans:
print(i, end=' ')
``` | output | 1 | 85,466 | 20 | 170,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | instruction | 0 | 85,467 | 20 | 170,934 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
n = int(input())
res_list = []
desired_sum = (n * (n + 1) // 2)
s = 0
for j in range(n, 0, -1):
if 2 * (s + j) <= desired_sum:
s += j
res_list += [j]
print(desired_sum - 2 * s)
print(str(len(res_list)), " ".join(map(str, res_list)))
``` | output | 1 | 85,467 | 20 | 170,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | instruction | 0 | 85,468 | 20 | 170,936 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
n = int(input())
v = int(n * (n + 1) / 2)
print(v % 2)
targ = int(v / 2)
seq = []
for i in range(n, 0, -1):
if (targ >= i):
targ -= i
seq.append(i)
print(len(seq), end = " ")
[print(seq[i], end = " ") for i in range(len(seq))]
``` | output | 1 | 85,468 | 20 | 170,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
Submitted Solution:
```
n = int(input())
goal = (n * (n + 1)) >> 1
ans = 1 if goal & 1 == 1 else 0
lis = ''
cnt = 0
goal >>= 1
while goal > 0:
if goal > n:
goal -= n
lis += ' ' + str(n)
n -= 1
else:
lis += ' ' + str(goal)
goal = 0
cnt += 1
print(ans)
print(str(cnt) + lis)
``` | instruction | 0 | 85,469 | 20 | 170,938 |
Yes | output | 1 | 85,469 | 20 | 170,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 28 03:20:26 2020
@author: Dark Soul
"""
n=int(input(''))
sol=[]
ans=0
for i in range(n,0,-1):
if ans<=0:
ans+=i
sol.append(i)
else:
ans-=i
print(ans)
print(len(sol),*sol)
``` | instruction | 0 | 85,470 | 20 | 170,940 |
Yes | output | 1 | 85,470 | 20 | 170,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
Submitted Solution:
```
import sys
n = int(sys.stdin.readline().rstrip("\n"))
if n % 4 == 0:
res = []
for i in range(1, n+1):
if i % 4 == 1 or i % 4 == 0:
res.append(i)
print(0)
print(len(res), " ".join(list(map(str, res))))
exit(0)
elif n % 4 == 1:
res = []
for i in range(2, n + 1):
if i % 4 == 1 or i % 4 == 2:
res.append(i)
print(1)
print(len(res)+1, 1, " ".join(list(map(str, res))))
exit(0)
elif n % 4 == 2:
res = []
for i in range(3, n + 1):
if i % 4 == 3 or i % 4 == 2:
res.append(i)
print(1)
print(len(res) + 1, 1, " ".join(list(map(str, res))))
exit(0)
elif n % 4 == 3:
res = []
for i in range(4, n + 1):
if i % 4 == 0 or i % 4 == 3:
res.append(i)
print(0)
print(len(res) + 2, 1, 2, " ".join(list(map(str, res))))
exit(0)
``` | instruction | 0 | 85,471 | 20 | 170,942 |
Yes | output | 1 | 85,471 | 20 | 170,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
Submitted Solution:
```
n = int(input())
g1 = []
g2 = []
s1 = s2 = n1 = 0
for i in range(n, 0, -1):
if s1 <= s2:
g1.append(i)
s1 += i
n1 += 1
else:
g2.append(i)
s2 += i
print(abs(s1 - s2))
print(n1, end=' ')
print(' '.join(f'{a}' for a in g1))
``` | instruction | 0 | 85,472 | 20 | 170,944 |
Yes | output | 1 | 85,472 | 20 | 170,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
Submitted Solution:
```
import sys
for line in sys.stdin:
if line == None or line == '\n':
break
# first if it is already a palindrome then just ouput itself
num = int(line)
if num == 2:
print(1)
print(str(1) + " " + str(1))
continue
if num == 3:
print(0)
print(str(2) + " " + str(1) + " " + str(2))
continue
str_container = [str(i) for i in range(1, num + 1)]
left, right = 0, len(str_container) - 1
left_con = []
while left < right:
left_con.append(str_container[left])
left_con.append(str_container[right])
left += 2
right -= 2
print(abs(sum(map(int,left_con)) - (sum(map(int, str_container)) - sum(map(int, left_con)))))
print(str(len(left_con)) + " " + ' '.join(left_con))
``` | instruction | 0 | 85,473 | 20 | 170,946 |
No | output | 1 | 85,473 | 20 | 170,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
Submitted Solution:
```
n = int(input())
total = int(n*(n+1)/2)
half = int(total/2)
ans = []
total = 0
#print(half)
temp = 1
while(True):
if n > 0:
if total == half:
ans = sorted(ans)
break
if temp > n:
temp-=1
if temp<= n:
ans.append(temp)
total+=temp
temp = half - total
z = list()
z.append(len(ans))
for x in ans:
z.append(x)
p = ""
for x in z:
p+=str(x)
p+=" "
print(total-half)
print(p)
``` | instruction | 0 | 85,474 | 20 | 170,948 |
No | output | 1 | 85,474 | 20 | 170,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
Submitted Solution:
```
n=int(input())
if n==2:
print("1\n1 1")
elif n==3:
print("0\n1 3")
else:
if n%2==0:
print("0")
print("2 1 "+str(n))
else:
print("0")
print("1 "+str(n))
``` | instruction | 0 | 85,475 | 20 | 170,950 |
No | output | 1 | 85,475 | 20 | 170,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of n integers should be exactly in one group.
Input
The first line contains a single integer n (2 β€ n β€ 60 000) β the number of integers Petya has.
Output
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Examples
Input
4
Output
0
2 1 4
Input
2
Output
1
1 1
Note
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
Submitted Solution:
```
def solution():
n=int(input())
first_group=[]
second_group=[]
beg=1
end=n
if n==2:
print(1)
print(1,1)
return
while beg < end:
first_group += [str(beg),str(end)]
second_group+=[beg+1, end-1]
beg+=2
end-=2
if n%2==0:
print(0)
else:
print(n//2+1)
print(len(first_group), ' '.join(first_group))
solution()
``` | instruction | 0 | 85,476 | 20 | 170,952 |
No | output | 1 | 85,476 | 20 | 170,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | instruction | 0 | 85,725 | 20 | 171,450 |
Tags: brute force
Correct Solution:
```
n=int(input())
s=input()
con=n//11
if (s.count('8')>=con) and (n>=11):
print(con)
elif (s.count('8')!=0) and (n>=11):
print(s.count('8'))
else:
print(0)
``` | output | 1 | 85,725 | 20 | 171,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | instruction | 0 | 85,726 | 20 | 171,452 |
Tags: brute force
Correct Solution:
```
n=int(input())
k=0
p=n//11
s=input()
for i in range(len(s)):
if s[i]=='8':
k+=1
else:
pass
if p<=k:
print(p)
elif p>k:
print(k)
``` | output | 1 | 85,726 | 20 | 171,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | instruction | 0 | 85,727 | 20 | 171,454 |
Tags: brute force
Correct Solution:
```
def read():
return int(input())
def read_cards():
s = input()
return list(int(e) for e in s)
n = read()
arr = read_cards()
print(min(len(arr) // 11, arr.count(8)))
``` | output | 1 | 85,727 | 20 | 171,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | instruction | 0 | 85,728 | 20 | 171,456 |
Tags: brute force
Correct Solution:
```
n = int(input())
c = sum(map(lambda x: x == '8', input()))
print(min(n//11, c))
``` | output | 1 | 85,728 | 20 | 171,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | instruction | 0 | 85,729 | 20 | 171,458 |
Tags: brute force
Correct Solution:
```
n = int(input())
s = input()
n8 = 0
for i in range(n):
if s[i] == '8':
n8 += 1
ans = 0
for i in range(n8, 0, -1):
if (n - i) // 10 >= i:
ans = i
break
print(ans)
``` | output | 1 | 85,729 | 20 | 171,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | instruction | 0 | 85,730 | 20 | 171,460 |
Tags: brute force
Correct Solution:
```
n=int(input())
num=input()
e=0
for x in num:
if x == '8':
e+=1
print(min(e,n//11))
``` | output | 1 | 85,730 | 20 | 171,461 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | instruction | 0 | 85,731 | 20 | 171,462 |
Tags: brute force
Correct Solution:
```
n = int(input())
s = input()
ans = 0
for i in range(0, n) :
if s[i] == '8' :
ans = ans + 1
print(int(min(n / 11, ans)))
``` | output | 1 | 85,731 | 20 | 171,463 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | instruction | 0 | 85,732 | 20 | 171,464 |
Tags: brute force
Correct Solution:
```
n = int(input())
s = str(input())
n8 = s.count("8")
print(min(n // 11 , n8))
``` | output | 1 | 85,732 | 20 | 171,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
Submitted Solution:
```
a=int(input())
b=input()
cnt=0
for i in b:
if i=='8':
cnt+=1
if a>=11:
if b.find('8')>=0:
x=a//11
print(min(cnt, x))
else:
print("0")
else:
print("0")
``` | instruction | 0 | 85,733 | 20 | 171,466 |
Yes | output | 1 | 85,733 | 20 | 171,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
Submitted Solution:
```
import math
n=int(input())
s=input()
print(min(s.count('8'), n//11))
``` | instruction | 0 | 85,734 | 20 | 171,468 |
Yes | output | 1 | 85,734 | 20 | 171,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
Submitted Solution:
```
n=int(input())
s=input()
res1=0
res2=0
l='8'
if l not in s or n<11:
print(0)
else:
res1=s.count(l)
res2=n//11
print(min(res1, res2))
``` | instruction | 0 | 85,735 | 20 | 171,470 |
Yes | output | 1 | 85,735 | 20 | 171,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
Submitted Solution:
```
a=int(input())//11
b=input()
b = b.count("8")
c=min(a,b)
print(c )
``` | instruction | 0 | 85,736 | 20 | 171,472 |
Yes | output | 1 | 85,736 | 20 | 171,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
Submitted Solution:
```
n=int(input())
s=input()
i=s.count('8')
if(s.count('8')==0):
print(0)
else:
while(i>0):
if (n-i)>=10*i:
print(i)
break
else:
i-=1
``` | instruction | 0 | 85,737 | 20 | 171,474 |
No | output | 1 | 85,737 | 20 | 171,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
Submitted Solution:
```
n = int(input())
s = input()
c = 0
for i in range(s.count('8')):
n -= 10
if n < 0:
break
c += 1
print(c)
``` | instruction | 0 | 85,738 | 20 | 171,476 |
No | output | 1 | 85,738 | 20 | 171,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
Submitted Solution:
```
n=int(input())
arr=input()
d=[0]*10
for i in arr:
d[int(i)]+=1
if(d[8]==0 or len(arr)<11):
print(0)
else:
count=0
for i in range(len(d)):
if(d[i]>=10 and d[8]>=1):
count+=1
d[i]-=10
d[8]-=1
z=d[8]
z=int(z)
d[8]=10000000
x=min(d)
if(z>=2):
if(x*2==z):
count+=x
else:
z=z//2
count+=abs(x-z)
print(count)
else:
print(count)
``` | instruction | 0 | 85,739 | 20 | 171,478 |
No | output | 1 | 85,739 | 20 | 171,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards.
Submitted Solution:
```
a = int(input())
st = str(input())
if (a < 11):
print(0)
exit()
map = {}
for i in range(10):
map[i]=0
for i in range(a):
map[int(st[i])] += 1
if map[8] == 0:
print(0)
exit()
map[8] -= 1
ans = 0
print(int(a / 11))
``` | instruction | 0 | 85,740 | 20 | 171,480 |
No | output | 1 | 85,740 | 20 | 171,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | instruction | 0 | 85,951 | 20 | 171,902 |
Tags: dp, matrices
Correct Solution:
```
from sys import stdin, stdout, maxsize
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
M = int(1e9) + 7
mx = int(2e5) + 5
dp = [0]+9*[1] +[2] + mx*[0]
for i in range(11, len(dp)):
dp[i] = (dp[i-9] + dp[i-10])%M
for tc in range(int(R())):
n, m = RL(int)
ans = 0
for i in list(str(n)):
ans = (ans +dp[int(i) + m])%M
print(ans)
``` | output | 1 | 85,951 | 20 | 171,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | instruction | 0 | 85,952 | 20 | 171,904 |
Tags: dp, matrices
Correct Solution:
```
def main():
import sys
input = sys.stdin.readline
MOD=10**9+7
t=int(input())
x=1
m=int(2*1e5+10)
dp= [1 for i in range(m+1) ]
for i in range(10,m+1):
dp[i]=(dp[i-10]+dp[i-9])%(MOD)
for _ in range(t):
n,k=map(int,input().split())
sums=0
while n:
sums = (sums+dp[k+n%10])
n = n//10
sums %=MOD
print(sums)
main()
``` | output | 1 | 85,952 | 20 | 171,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | instruction | 0 | 85,953 | 20 | 171,906 |
Tags: dp, matrices
Correct Solution:
```
import sys
input = sys.stdin.readline
M = 10 ** 9 + 7
dp = [[0, 0] for i in range(200001)]
for i in range(200001):
if i < 10:
dp[i][0] = 1
dp[i][1] = 1
if i == 9:
dp[i][1] = dp[1][1] + dp[1][0]
else:
dp[i][0] = (dp[i - 10][1] + dp[i - 10][0]) % M
dp[i][1] = (dp[i - 9][1] + dp[i - 9][0]) % M
def solve(n, m):
s = list(str(n))
z = 0
for i in range(len(s)):
x = int(s[i])
if x + m < 10:
z += 1
else:
z += dp[m - (10 - x)][1] + dp[m - (10 - x)][0]
return str(z % M)
t = int(input())
o = []
while t > 0:
n, m = map(int, input().split())
o.append(solve(n, m))
t -= 1
print('\n'.join(o))
``` | output | 1 | 85,953 | 20 | 171,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | instruction | 0 | 85,954 | 20 | 171,908 |
Tags: dp, matrices
Correct Solution:
```
from sys import stdin
input = stdin.readline
mxn = 2 * (10 ** 5) + 15
mod = 10 ** 9 + 7
dp = [1] * mxn
for i in range(10, mxn):
dp[i] = (dp[i - 9] + dp[i - 10]) % mod
for test in range(int(input())):
n, k = map(int, input().strip().split())
ans = 0
for i in str(n):
ans = (ans + dp[k + int(i)]) % mod
print(ans)
``` | output | 1 | 85,954 | 20 | 171,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | instruction | 0 | 85,955 | 20 | 171,910 |
Tags: dp, matrices
Correct Solution:
```
#pyrival orz
import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ ---- Dijkstra with path ---- ############
def dijkstra(start, distance, path, n):
# requires n == number of vertices in graph,
# adj == adjacency list with weight of graph
visited = [False for _ in range(n)] # To keep track of vertices that are visited
distance[start] = 0 # distance of start node from itself is 0
for i in range(n):
v = -1 # Initialize v == vertex from which its neighboring vertices' distance will be calculated
for j in range(n):
# If it has not been visited and has the lowest distance from start
if not visited[v] and (v == -1 or distance[j] < distance[v]):
v = j
if distance[v] == math.inf:
break
visited[v] = True # Mark as visited
for edge in adj[v]:
destination = edge[0] # Neighbor of the vertex
weight = edge[1] # Its corresponding weight
if distance[v] + weight < distance[destination]: # If its distance is less than the stored distance
distance[destination] = distance[v] + weight # Update the distance
path[destination] = v # Update the path
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a, b):
return (a*b)//gcd(a, b)
def ncr(n, r):
return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
def npr(n, r):
return math.factorial(n)//math.factorial(n-r)
def seive(n):
primes = [True]*(n+1)
ans = []
for i in range(2, n):
if not primes[i]:
continue
j = 2*i
while j <= n:
primes[j] = False
j += i
for p in range(2, n+1):
if primes[p]:
ans += [p]
return ans
def factors(n):
factors = []
x = 1
while x*x <= n:
if n % x == 0:
if n // x == x:
factors.append(x)
else:
factors.append(x)
factors.append(n//x)
x += 1
return factors
# Functions: list of factors, seive of primes, gcd of two numbers,
# lcm of two numbers, npr, ncr
def main():
try:
max_n = 2*10**5
mod = 10**9 + 7
dp = [0]*max_n
for i in range(0, 9):
dp[i] = 2
dp[9] = 3
for i in range(10, 2*10**5):
dp[i] = dp[i-9] + dp[i-10]
dp[i] %= mod
for _ in range(inp()):
n, m = invr()
ans = 0
while n > 0:
x = n%10
ans += 1*int(m + x < 10) + dp[m+x-10]*int(not m + x < 10)
ans %= mod
n //= 10
print(ans)
except Exception as e:
print(e)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | output | 1 | 85,955 | 20 | 171,911 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | instruction | 0 | 85,956 | 20 | 171,912 |
Tags: dp, matrices
Correct Solution:
```
from sys import stdin,stdout
z=10**9+7
dp={}
for i in range(200009):
if i<9:
dp[i]=2
elif i==9:
dp[i]=3
else:
dp[i]=(dp[i-9]+dp[i-10])%z
for _ in range(int(input())):
n,m=stdin.readline().split()
n=int(n);m=int(m)
ans=0
while n>0:
i=n%10
if (m+i)<10:
ans+=1
else:
ans+=((dp[m+i-10])%z)
ans=ans%z
n//=10
stdout.write(str(ans)+'\n')
``` | output | 1 | 85,956 | 20 | 171,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | instruction | 0 | 85,957 | 20 | 171,914 |
Tags: dp, matrices
Correct Solution:
```
import sys
input = sys.stdin.readline
mod=10**9+7
mxi=210000
ans=[0]*mxi
cts=[0]*10
cts[0]=1
s=1
for i in range(mxi):
ans[i]=s
s+=cts[-1]
s%=mod
cts[0]+=cts[-1]
cts[0]%=mod
cts.insert(0,cts.pop())
for f in range(int(input())):
n,m=map(int,input().split())
sol=0
for x in str(n):
sol+=ans[m+int(x)]
sol%=mod
print(sol)
``` | output | 1 | 85,957 | 20 | 171,915 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | instruction | 0 | 85,958 | 20 | 171,916 |
Tags: dp, matrices
Correct Solution:
```
# Author: yumtam
# Created at: 2021-04-29 12:58
MOD = 10**9 + 7
a = []
c = [1] + [0]*9
for _ in range(2 * 10**5 + 50):
a.append(sum(c))
d = [0] * 10
for i in range(9):
d[i+1] = c[i]
d[0] = (d[0] + c[9]) % MOD
d[1] = (d[1] + c[9]) % MOD
c = d
import sys, os, io
input = lambda: sys.stdin.readline().rstrip('\r\n')
stdout = io.BytesIO()
sys.stdout.write = lambda s: stdout.write(s.encode("ascii"))
for _ in range(int(input())):
n, k = [int(t) for t in input().split()]
s = str(n)
c = [s.count(str(i)) for i in range(10)]
ans = 0
for i in range(10):
ans = (ans + c[i] * a[i+k]) % MOD
print(ans)
os.write(1, stdout.getvalue())
``` | output | 1 | 85,958 | 20 | 171,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
Submitted Solution:
```
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
MOD = 10 ** 9 + 7
LIMIT = 200011
dp = [0] * LIMIT
for i in range(10):
dp[i] = 1
for i in range(10, LIMIT, 1):
dp[i] = (dp[i - 9] + dp[i - 10]) % MOD
def solve(N, M):
ans = 0
while N:
ans = (ans + dp[N % 10 + M]) % MOD
N //= 10
return ans % MOD
T = int(input())
for _ in range(T):
N, M = get_ints()
print(solve(N, M))
``` | instruction | 0 | 85,959 | 20 | 171,918 |
Yes | output | 1 | 85,959 | 20 | 171,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
Submitted Solution:
```
from sys import stdin, stdout
s = "0"
curr = 1
count = 0
check = 0
dp = [1]
for i in range(100):
fin = ""
for i in s:
num = int(i)
num += 1
num = str(num)
fin = fin+num
dp.append(len(fin))
s = (fin)
tog = 101
mod = 10**9 + 7
for i in range(2*(10**5)):
num = (dp[tog-1] + dp[tog-9]-dp[tog-11]) % mod
dp.append(num)
tog += 1
t=t=int(stdin.readline())
for test in range(t):
n,m=map(int,stdin.readline().split())
ans=0
while(n>0):
temp=n%10
ans = (ans+ dp[temp+m])%mod
n=n//10
stdout.write(str(ans)+'\n')
``` | instruction | 0 | 85,960 | 20 | 171,920 |
Yes | output | 1 | 85,960 | 20 | 171,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#https://github.com/cheran-senthil/PyRival/blob/master/templates/template_py3.py
mod=10**9+7
max_n=2*10**5
dp=[0 for i in range(max_n+1)]
dp[9]=1
dp[10]=2
for i in range(11,max_n+1):
dp[i]=(2+dp[i-9]+dp[i-10])%mod
from collections import Counter
t=int(input())
for _ in range(t):
n,m=input().split()
m=int(m)
c=Counter(n)
ans=0
for i in c:
j=int(i)
if(10-j>m):
ans+=c[i]
continue
ans=(ans+c[i]*(2+dp[m+j-10]))%mod
print(ans)
``` | instruction | 0 | 85,961 | 20 | 171,922 |
Yes | output | 1 | 85,961 | 20 | 171,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
Submitted Solution:
```
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
MOD = 10 ** 9 + 7
LIMIT = 20011
dp = []
for i in range(200011):
if i < 10:
dp.append(1)
else:
dp.append((dp[i - 9] + dp[i - 10]) % MOD)
T = int(input())
for _ in range(T):
N, M = get_ints()
ans = 0
while N:
ans = (ans + dp[N % 10 + M]) % MOD
N //= 10
print(ans)
``` | instruction | 0 | 85,962 | 20 | 171,924 |
Yes | output | 1 | 85,962 | 20 | 171,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
Submitted Solution:
```
def solve(n):
number = n[0]
add = int(n[1])
_s = ''
for _ in number:
_s += str(int(_) + add)
return len(_s)
case = int(input())
for i in range(case):
_t = input().split()
print(solve(_t))
``` | instruction | 0 | 85,963 | 20 | 171,926 |
No | output | 1 | 85,963 | 20 | 171,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
Submitted Solution:
```
for _ in range(int(input())):
(n,m)=(int(x) for x in input().split())
s=str(n)
ans=len(s)
req={}
mod=int(1e9+7)
for i in s:
req[10-int(i)]=req.get(int(i),0)+1
cnt=0
while(cnt<m):
cnt+=1
temp=req.get(cnt,0)
if (temp>0):
ans=(ans+temp)%mod
req[cnt+9]=(req.get(cnt+9,0)+temp)%mod
req[cnt+10]=(req.get(cnt+10,0)+temp)%mod
print(ans)
``` | instruction | 0 | 85,964 | 20 | 171,928 |
No | output | 1 | 85,964 | 20 | 171,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
Submitted Solution:
```
lst=[]
inp=int(input())
for i in range(inp):
inp_lst=input().split()
num=inp_lst[0]
incr=int(inp_lst[1])
num_lst=[str(int(i)+incr) for i in num]
sol="".join(num_lst)
lst.append(len(sol))
for i in lst:
print(i)
``` | instruction | 0 | 85,965 | 20 | 171,930 |
No | output | 1 | 85,965 | 20 | 171,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
Submitted Solution:
```
t = int(input())
arr = [list(map(int, input().split())) for i in range(t)]
for n, m in arr:
n = [int(i) for i in str(n)]
for i in range(len(n)):
n[i] += m
ans = 0
for i in n:
ans += len(str(i))
print(ans)
``` | instruction | 0 | 85,966 | 20 | 171,932 |
No | output | 1 | 85,966 | 20 | 171,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 β€ A, B, C β€ 105). Any coefficient may be equal to 0.
Output
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Examples
Input
1 -5 6
Output
2
2.0000000000
3.0000000000 | instruction | 0 | 85,990 | 20 | 171,980 |
Tags: math
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 16 03:38:40 2018
@author: anshul
"""
from math import sqrt
a,b,c=list(map(int,input().split()))
if a==0 and b==0 and c==0:
print(-1)
elif a==0 and b==0:
print(0)
elif a==0:
print(1)
ans=(-1*c)/b
print(ans)
else:
d = b*b - 4*a*c
if d<0:
print(0)
elif d>0:
print(2)
d=sqrt(d)
ans1=(-b-d)/(2*a)
ans2=(-b+d)/(2*a)
if ans1<ans2:
ans1,ans2=ans2,ans1
print(ans2)
print(ans1)
else:
print(1)
ans=(-b)/(2*a)
print(ans)
``` | output | 1 | 85,990 | 20 | 171,981 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 β€ A, B, C β€ 105). Any coefficient may be equal to 0.
Output
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Examples
Input
1 -5 6
Output
2
2.0000000000
3.0000000000 | instruction | 0 | 85,991 | 20 | 171,982 |
Tags: math
Correct Solution:
```
import math
data = [int(x) for x in input().split()]
a = data[0]
b = data[1]
c = data[2]
if a == 0 and b == 0 and c == 0:
print(-1)
elif a == 0 and b == 0:
print(0)
elif a == 0 and b != 0:
print(1)
print(-c/b)
elif (b ** 2) - (4 * a * c) < 0:
print(0)
else:
ans1 = (-b + math.sqrt((b ** 2) - (4 * a * c)))/(2*a)
ans2 = (-b - math.sqrt((b ** 2) - (4 * a * c)))/(2*a)
if ans1 == ans2:
print(1)
print(ans1)
else:
answers = [ans1,ans2]
answers.sort()
print(2)
print(answers[0])
print(answers[1])
``` | output | 1 | 85,991 | 20 | 171,983 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 β€ A, B, C β€ 105). Any coefficient may be equal to 0.
Output
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Examples
Input
1 -5 6
Output
2
2.0000000000
3.0000000000 | instruction | 0 | 85,992 | 20 | 171,984 |
Tags: math
Correct Solution:
```
from math import *
a,b,c = input().split()
a,b,c = int(a),int(b),int(c)
d_2 = (b**2) - (4 * a * c)
if d_2 < 0:
print("0")
elif a == 0 and b == 0:
if c == 0:print("-1")
else:print('0')
elif a == 0 and b != 0:
print("1")
x_1 = -(float(c)/float(b))
print("%.10f" % x_1)
else:
if d_2 == 0:
print('1')
print('%.10f' % (-b/(2*a)))
exit()
print("2")
x_small = float((-float(b) - sqrt(d_2)))/float(2 * a)
x_big = float((-float(b) + sqrt(d_2)))/float(2 * a)
print("%.10f" % min(x_small,x_big) + '\n' + "%.10f" % max(x_big,x_small))
``` | output | 1 | 85,992 | 20 | 171,985 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 β€ A, B, C β€ 105). Any coefficient may be equal to 0.
Output
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Examples
Input
1 -5 6
Output
2
2.0000000000
3.0000000000 | instruction | 0 | 85,993 | 20 | 171,986 |
Tags: math
Correct Solution:
```
import re
arr = re.split(' ', input())
A = int(arr[0])
B = int(arr[1])
C = int(arr[2])
dis = B*B-4*A*C
if (A == 0 and B == 0 and C == 0):
print(-1)
elif (A == 0 and B == 0):
print(0)
elif (A == 0):
print(1)
print(-C/B)
elif (dis<0):
print(0)
elif (dis==0):
print(1)
print(-B/(2*A))
else:
print(2)
if (A>0):
print((-B-dis**0.5)/(2*A))
print((-B+dis**0.5)/(2*A))
else:
print((-B+dis**0.5)/(2*A))
print((-B-dis**0.5)/(2*A))
``` | output | 1 | 85,993 | 20 | 171,987 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 β€ A, B, C β€ 105). Any coefficient may be equal to 0.
Output
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Examples
Input
1 -5 6
Output
2
2.0000000000
3.0000000000 | instruction | 0 | 85,994 | 20 | 171,988 |
Tags: math
Correct Solution:
```
import sys
import math
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
if __name__ == '__main__':
q = inlt()
a = q[0]
b = q[1]
c = q[2]
if a == 0 :
if b == 0 and c == 0 :
print("-1")
else :
if b == 0 :
print("0")
else :
print("1")
print("{:.6f}".format(-1*c / b))
else :
d = b*b - 4*a*c
if d > 0 :
print("2")
bb = [ (-1*b + math.sqrt(d))/(2*a) ,(-1*b - math.sqrt(d))/(2*a) ]
bb.sort()
print("{:.6f}".format(bb[0]))
print("{:.6f}".format(bb[1]))
else :
if d == 0 :
print("1")
print("{:.6f}".format(-b/(2*a)))
else :
print("0")
``` | output | 1 | 85,994 | 20 | 171,989 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 β€ A, B, C β€ 105). Any coefficient may be equal to 0.
Output
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Examples
Input
1 -5 6
Output
2
2.0000000000
3.0000000000 | instruction | 0 | 85,995 | 20 | 171,990 |
Tags: math
Correct Solution:
```
a,b,c=map(int,input().split())
if a==0:
if b==0:
if c==0:
print("-1")
else:
print("0")
else:
print(1)
print("%.6f"%((-c)/b))
else:
d=b*b-4*a*c
if d<0:
print(0)
elif d==0:
print(1)
print("%.6f"%((-b)/(2*a)))
else:
print(2)
l=[((-b-(d**0.5))/(2*a)),((-b+(d**0.5))/(2*a))]
l.sort()
print("%.6f"%l[0])
print("%.6f"%l[1])
``` | output | 1 | 85,995 | 20 | 171,991 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 β€ A, B, C β€ 105). Any coefficient may be equal to 0.
Output
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Examples
Input
1 -5 6
Output
2
2.0000000000
3.0000000000 | instruction | 0 | 85,996 | 20 | 171,992 |
Tags: math
Correct Solution:
```
a,b,c = map(int,input().split())
if a ==0 and b==0:
if c ==0:
print("-1")
else:
print("0")
exit(0)
D = pow(b,2) -4*a*c
x = -b
y = pow(D,1/2)
z = 2*a
r = 0
if a ==0:
print("1")
print(-c/b)
exit(0)
if D < 0:
print(r)
exit(0)
if D ==0:
r = 1
e1 = (x-y)/z
print(r,e1)
else:
r = 2
e1 = (x+y)/z
e2 = (x-y)/z
if e2<e1:
e1,e2 =e2,e1
print(r,e1,e2)
``` | output | 1 | 85,996 | 20 | 171,993 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.