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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).
Constraints
* 1 \leq N \leq 10^5
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of positive integers less than or equal to N that have an odd number of digits.
Examples
Input
11
Output
9
Input
136
Output
46
Input
100000
Output
90909
Submitted Solution:
```
n=int(input())
digit=1
count=0
while(10**digit<n):
if(digit%2==1):
count=count+9*10**(digit-1)
digit=digit+1
if(digit%2==1):
count=count+n-10**(digit-1)
print(count)
``` | instruction | 0 | 44,466 | 20 | 88,932 |
No | output | 1 | 44,466 | 20 | 88,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).
Constraints
* 1 \leq N \leq 10^5
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of positive integers less than or equal to N that have an odd number of digits.
Examples
Input
11
Output
9
Input
136
Output
46
Input
100000
Output
90909
Submitted Solution:
```
import io
import sys
MOD = 10 ** 9 + 7
def IN_S():
return input()
def IN_I():
return int(input())
def IN_L_I():
return list(map(int, input().split()))
def IN_L_S():
return list(map(str, input().split()))
def STR_SPLIT(s, n):
for l in range(0, len(s), n):
yield s[0 + l:n + l]
def T_IN():
global test_str
sys.stdin = io.StringIO(test_str[1:-1])
test_str = '''
136
'''
def MAIN():
T_IN()
A()
def A():
n = IN_I()
t = 0
if n > 9:
t += 9
if n > 999:
t += 900
if n > 99999:
t += 90000
if n <= 9:
t += n
elif 99 < n <= 999:
t += n - 99
elif 9999 < n <= 99999:
t += n - 9999
print(t)
return None
def B():
return None
def C():
return None
MAIN()
``` | instruction | 0 | 44,467 | 20 | 88,934 |
No | output | 1 | 44,467 | 20 | 88,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).
Constraints
* 1 \leq N \leq 10^5
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of positive integers less than or equal to N that have an odd number of digits.
Examples
Input
11
Output
9
Input
136
Output
46
Input
100000
Output
90909
Submitted Solution:
```
n = int(input())
num = int(input())
num_digit = len(str(num))
if num_digit == 1:
print(0)
elif num_digit == 2:
print(9)
elif num_digit == 3:
print(9 + (num - 100 + 1))
elif num_digit == 4:
print(909)
elif num_digit == 5:
print(909 + (num - 10000 + 1))
``` | instruction | 0 | 44,468 | 20 | 88,936 |
No | output | 1 | 44,468 | 20 | 88,937 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920 | instruction | 0 | 44,527 | 20 | 89,054 |
"Correct Solution:
```
def solve(k, d, fl):
if k <= 1:
if d == 0:
return 10 ** k
return 0
x = (-d) % 10
c = 9 - x + 1 - fl
d -= 10 ** (k - 1) * x - x
return c * solve(k - 2, abs(d) // 10, 0)
d = int(input())
ans = 0
for i in range(1, 100):
ans += solve(i, d, 1)
print(ans)
``` | output | 1 | 44,527 | 20 | 89,055 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920 | instruction | 0 | 44,528 | 20 | 89,056 |
"Correct Solution:
```
from collections import deque
D=int(input())
def f(d,k):
if 0<=k<=1:
if d!=0:
return "Unko"
if k==1:
return deque([0])
else:
return deque([])
if d>=0:
s=10-(d%10)
else:
s=-(d%10)
if s==10:
A=f(d//10,k-2)
s=0
#print(d,s,d-s*(10**(k-1))+s)
else:
A=f((d-s*(10**(k-1))+s)//10,k-2)
if A=="Unko":
return "Unko"
A.appendleft(s)
A.append(-s)
return A
ans=0
for k in range(1,50):
A=f(D,k)
if A=="Unko":
continue
# print(A)
res=1
for j in range((k+1)//2):
if j==0:
res*=9-abs(A[j])
else:
if A[j]==0:
res*=10
else:
res*=10-abs(A[j])
ans+=res
print(ans)
``` | output | 1 | 44,528 | 20 | 89,057 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920 | instruction | 0 | 44,529 | 20 | 89,058 |
"Correct Solution:
```
def result(letters, number, cant_zero):
if letters <= 1:
if number == 0:
return 10 ** letters
return 0
diff = (10 - number%10) % 10
variants = number % 10 - cant_zero
if number % 10 == 0:
variants = 10 - cant_zero
number -= diff * (10**(letters-1) - 1)
number = abs(number // 10)
return variants * result(letters-2, number, 0)
d = int(input())
ans = 0
for i in range(20):
ans += result(i, d, 1)
print(ans)
``` | output | 1 | 44,529 | 20 | 89,059 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920 | instruction | 0 | 44,530 | 20 | 89,060 |
"Correct Solution:
```
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
d = int(input())
def main(d):
from collections import defaultdict
vals = defaultdict(int)
vals2 = defaultdict(int)
for i in range(10):
for j in range(10):
vals[i-j] += 1
if j>0:
vals2[i-j] += 1
def sub(n):
vs = []
for i in range(n):
if i>=n-i:
break
vs.append(pow(10,n-i) - pow(10,i))
# if 9*sum(vs)<d:
# return 0
def _sub(val, i):
"""vs[i:]δ»₯ιγ§valγδ½γιγζ°
"""
if i==len(vs):
if val==0:
return 1
else:
return 0
ans = 0
for j in range(-9, 10):
if (vs[i]*j)%pow(10,i+1)==val%(pow(10,i+1)):
ans += _sub(val-vs[i]*j, i+1) * vals[j]
return ans
ans = 0
for i in range(-9,10):
if (vs[0]*i)%10==d%10:
ans += _sub(d-vs[0]*i, 1) * vals2[i]
if n%2==0:
ans *= 10
return ans
ans = 0
i = 1
while True:
val = sub(i)
ans += val
if i>20:
break
# if pow(10,i)-1>d:
# break
i += 1
return ans
print(main(d))
``` | output | 1 | 44,530 | 20 | 89,061 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920 | instruction | 0 | 44,531 | 20 | 89,062 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
D = int(input())
memo_F = [0] * 30
memo_T = [0] * 30
for x in range(10):
for y in range(10):
memo_T[y-x] += 1
if x != 0:
memo_F[y-x] += 1
def F(K,D,allow_leading_zero):
if K == 0:
return 1 if D == 0 else 0
if K == 1:
if D != 0:
return 0
if allow_leading_zero:
return 10
else:
return 9
x = 10**(K-1)-1
d = (-D)%10
# xγdεγΎγγ―d-10ε
ret = 0
for use_x in [d,d-10]:
if allow_leading_zero:
coef = memo_T[use_x]
else:
coef = memo_F[use_x]
if coef == 0:
continue
ret += coef * F(K-2,(D-x*use_x)//10,True)
return ret
answer = sum(F(K,D,False) for K in range(1,20))
print(answer)
``` | output | 1 | 44,531 | 20 | 89,063 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920 | instruction | 0 | 44,532 | 20 | 89,064 |
"Correct Solution:
```
# (10-x) ways: (0,x)-(9-x,9) -> (x, -x) <- This should never happens when D > 0
# (x) ways: (10-x,0)-(9,x-1) -> (x-10, 10 - x)
def solve(d, k, outer):
if k <= 1:
return 10**k if d == 0 else 0
# if d >= 10**k:
# return 0
t = (-d)%10 # 10-d%10 doesn't work when d = 10
d -= t*10**(k-1) - t
return (10-t-outer)*solve(abs(d//10), k-2, 0)
D = int(input())
result = 0
for k in range(1,20):
result += solve(D, k, 1)
print(result)
``` | output | 1 | 44,532 | 20 | 89,065 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920 | instruction | 0 | 44,533 | 20 | 89,066 |
"Correct Solution:
```
def solve(d, K):
r = 1
for k in range(K,1,-2):
if d >= 10**k:
return 0
t = (-d)%10
d = abs((d-t*(10**(k-1)-1))//10)
r *= 10-t-(K==k)
return r*(10**(K%2)) if d == 0 else 0
D = int(input())
result = 0
l = len(str(D))
for k in range(l,2*l+1):
result += solve(D, k)
print(result)
``` | output | 1 | 44,533 | 20 | 89,067 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920 | instruction | 0 | 44,534 | 20 | 89,068 |
"Correct Solution:
```
D = int(input())
def table(i, k):
if i == k:
return list(range(9, -1, -1)) + [0]*9
else:
return list(range(10, 0, -1)) + list(range(1, 10))
def nine(i):
return 10**i - 1
def rec(d, i, k):
res = 0
num = table(i, k)
if i == 1:
for j in range(-9, 10):
if 9*j == d:
return num[j]
return 0
if i == 2:
for j in range(-9, 10):
if d == 99*j:
return 10*num[j]
if not -10*nine(i) <= d <= 10*nine(i):
return 0
for j in range(-9, 10):
if d%10 == j*nine(i)%10:
res += num[j] * rec((d-j*nine(i))//10, i-2, k)
return res
l = 0
while D % 10 == 0:
D//= 10
l += 1
if l == 0:
a = 1
else:
a = 9*10**(l-1)
ans = 0
for i in range(1, 20):
if not l:
ans += rec(D, i, i)
else:
ans += rec(D, i, 100)
print(a * ans)
``` | output | 1 | 44,534 | 20 | 89,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920
Submitted Solution:
```
def recursion(length, ll, string, cc):
answer = 0
az = 0
if ll * 2 < length:
for i in range(10):
string1 = string + str(i)
line = recursion(length, ll+1, string1, cc)
answer += line[0]
az += line[1]
line = [answer, az]
return line
else:
number = str(int(string) + int(cc[-ll:]))
ds = ""
for i in range(length // 2):
if i + 1 <= len(number):
ds += number[-i-1]
else:
ds += "0"
string = ds + string
if str(int(string) + int(cc)) == string[::-1] and string[0] != "0":
answer += 1
elif str(int(string) + int(cc)) == string[::-1]:
az += 1
line = [answer, az]
return line
d = input()
d1 = d
plus = 0
while True:
if d[-1] == "0":
d = d[:-1]
plus += 1
else:
break
l1 = recursion(len(d), 0, "", d)
l2 = recursion(len(d)+1, 0, "", d)
answer = l1[0] + l2[0]
az = l1[1] + l2[1]
yes = False
while plus > 0:
yes = True
if plus == 1:
plus -= 1
answer = answer * 9
az = az * 9
else:
plus -= 1
answer *= 10
az *= 10
if yes:
answer += az
print(answer)
``` | instruction | 0 | 44,538 | 20 | 89,076 |
No | output | 1 | 44,538 | 20 | 89,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.
You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?
Constraints
* D is an integer.
* 1 β€ D < 10^9
Input
Input is given from Standard Input in the following format:
D
Output
Print the number of the positive integers N such that rev(N) = N + D.
Examples
Input
63
Output
2
Input
75
Output
0
Input
864197532
Output
1920
Submitted Solution:
```
def recursion(length, ll, string, cc):
if ll * 2 < length:
for i in range(10):
string1 = string + str(i)
recursion(length, ll+1, string1, cc)
else:
number = str(int(string) + int(cc[-ll:]))
ds = ""
for i in range(length // 2):
if i + 1 <= len(number):
ds += number[-i-1]
else:
ds += "0"
string = ds + string
if str(int(string) + int(cc)) == string[::-1] and string[0] != "0":
global answer
answer += 1
d = input()
plus = 0
while True:
if d[-1] == "0":
d = d[:-1]
plus += 1
else:
break
answer = 0
recursion(len(d), 0, "", d)
recursion(len(d)+1, 0, "", d)
while plus > 0:
if plus == 1:
plus -= 1
answer = answer * 9
else:
plus -= 1
answer *= 10
print(answer)
``` | instruction | 0 | 44,539 | 20 | 89,078 |
No | output | 1 | 44,539 | 20 | 89,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya brought home string s with the length of n. The string only consists of lucky digits. The digits are numbered from the left to the right starting with 1. Now Petya should execute m queries of the following form:
* switch l r β "switch" digits (i.e. replace them with their opposites) at all positions with indexes from l to r, inclusive: each digit 4 is replaced with 7 and each digit 7 is replaced with 4 (1 β€ l β€ r β€ n);
* count β find and print on the screen the length of the longest non-decreasing subsequence of string s.
Subsequence of a string s is a string that can be obtained from s by removing zero or more of its elements. A string is called non-decreasing if each successive digit is not less than the previous one.
Help Petya process the requests.
Input
The first line contains two integers n and m (1 β€ n β€ 106, 1 β€ m β€ 3Β·105) β the length of the string s and the number of queries correspondingly. The second line contains n lucky digits without spaces β Petya's initial string. Next m lines contain queries in the form described in the statement.
Output
For each query count print an answer on a single line.
Examples
Input
2 3
47
count
switch 1 2
count
Output
2
1
Input
3 5
747
count
switch 1 1
count
switch 1 3
count
Output
2
3
2
Note
In the first sample the chronology of string s after some operations are fulfilled is as follows (the sought maximum subsequence is marked with bold):
1. 47
2. 74
3. 74
In the second sample:
1. 747
2. 447
3. 447
4. 774
5. 774
Submitted Solution:
```
it = lambda: list(map(int, input().strip().split()))
n, m = it()
arr = [0 if ch == '4' else 1 for ch in input().strip()]
one = [0] * (n << 2)
zer = [0] * (n << 2)
inc = [0] * (n << 2)
dec = [0] * (n << 2)
lzy = [0] * (n << 2)
def apply(idx):
inc[idx], dec[idx] = dec[idx], inc[idx]
one[idx], zer[idx] = zer[idx], one[idx]
lzy[idx] = 1
def push(idx):
if lzy[idx] == 1:
apply(idx << 1)
apply(idx << 1 | 1)
lzy[idx] = 0
def pull(idx):
one[idx] = one[idx << 1] + one[idx << 1 | 1]
zer[idx] = zer[idx << 1] + zer[idx << 1 | 1]
inc[idx] = max(zer[idx << 1] + inc[idx << 1 | 1], inc[idx << 1] + one[idx << 1 | 1], zer[idx << 1] + one[idx << 1 | 1])
dec[idx] = max(one[idx << 1] + dec[idx << 1 | 1], dec[idx << 1] + zer[idx << 1 | 1], one[idx << 1] + zer[idx << 1 | 1])
def build(idx=1, l=0, r=n):
if r - l < 2:
one[idx] = 1 if arr[l] == 1 else 0
zer[idx] = 1 if arr[l] == 0 else 0
inc[idx] = 1
dec[idx] = 1
return
mid = (l + r) >> 1
build(idx << 1, l, mid)
build(idx << 1 | 1, mid, r)
pull(idx)
def update(x, y, idx=1, l=0, r=n):
if x >= r or y <= l: return
if x <= l and r <= y:
apply(idx)
return
push(idx)
mid = (l + r) >> 1
update(x, y, idx << 1, l, mid)
update(x, y, idx << 1 | 1, mid, r)
pull(idx)
build()
for _ in range(m):
query = input().strip().split()
if len(query) == 1:
print(inc[1])
else:
l, r = query[1:]
update(int(l) - 1, int(r))
``` | instruction | 0 | 44,820 | 20 | 89,640 |
No | output | 1 | 44,820 | 20 | 89,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321. | instruction | 0 | 44,915 | 20 | 89,830 |
Tags: combinatorics, greedy
Correct Solution:
```
s=input()
ans=1
n=len(s)
c=1
for i in range(1,n):
#print("i is",i,' and c is',c)
if(int(s[i])+int(s[i-1])-2*int('0')==9):
#print('s[i]+s[i-1]==9')
c+=1
else:
#print('else')
if(c%2==1 and c>1):
#print('c%2==1 and c>1')
ans*=(c+1)//2
#print('ans is',ans)
c=1
if(c%2==1 and c>1):
ans*=(c+1)//2
print(ans)
``` | output | 1 | 44,915 | 20 | 89,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321. | instruction | 0 | 44,916 | 20 | 89,832 |
Tags: combinatorics, greedy
Correct Solution:
```
a=input()
ans=1
count=1
l=len(a)
for i in range(l-1):
if int(a[i])+int(a[i+1])==9:
count+=1
else:
if count%2:
ans*=(count+1)//2
count=1
if count%2:
ans*=(count+1)//2
print(ans)
``` | output | 1 | 44,916 | 20 | 89,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321. | instruction | 0 | 44,917 | 20 | 89,834 |
Tags: combinatorics, greedy
Correct Solution:
```
a=input()
n=len(a)
ans=1
c=0
for i in range(n-1):
if int(a[i+1])+int(a[i])==9:
c+=1
else:
if c%2==0 and c!=0:
# print(c+1)
ans*=(c+1)//2+1
c=0
if c%2==0 and c!=0:
ans*=(c+1)//2+1
print(ans)
``` | output | 1 | 44,917 | 20 | 89,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321. | instruction | 0 | 44,918 | 20 | 89,836 |
Tags: combinatorics, greedy
Correct Solution:
```
# -*- coding: utf-8 -*-
def count_nine(a, i):
while i < len(a) - 1:
if a[i] + a[i+1] == 9:
break
i += 1
else:
return 0, 1
n1, c1 = count_nine(a, i+1)
n2, c2 = count_nine(a, i+2)
if n1 == n2 + 1:
return n2+1, c1+c2
else:
return n2+1, c2
def count_nine2(a):
n_list = [0] * (len(a)+1)
c_list = [0] * (len(a)+1)
c_list[-1] = c_list[-2] = 1
for i in range(len(a)-2, -1, -1):
if a[i] + a[i+1] == 9:
n_list[i] = n_list[i+2]+1
if n_list[i+1] == n_list[i+2]+1:
c_list[i] = c_list[i+1] + c_list[i+2]
else:
c_list[i] = c_list[i+2]
else:
n_list[i] = n_list[i+1]
c_list[i] = c_list[i+1]
return n_list[0], c_list[0]
n, c = count_nine2([int(x) for x in input()])
print(c)
``` | output | 1 | 44,918 | 20 | 89,837 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321. | instruction | 0 | 44,919 | 20 | 89,838 |
Tags: combinatorics, greedy
Correct Solution:
```
if __name__ == '__main__':
n = input()
res = 1
countConsecutivePairs = 0
length = len(n)
for i in range(length):
if (i+1 < length and int(n[i]) + int(n[i+1]) == 9):
countConsecutivePairs += 1
else:
if (countConsecutivePairs % 2 == 0):
res *= (countConsecutivePairs//2 + 1)
countConsecutivePairs = 0
print(res)
``` | output | 1 | 44,919 | 20 | 89,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321. | instruction | 0 | 44,920 | 20 | 89,840 |
Tags: combinatorics, greedy
Correct Solution:
```
#!/usr/bin/python3
def readln(): return list(map(int, input().split()))
ans = 1
l = 1
p = -1
a = input()
for i in range(len(a)):
c = int(a[i])
if c + p == 9:
l += 1
if c + p != 9 or i == len(a) - 1:
if l % 2:
ans *= (l + 1) // 2
l = 1
p = c
print(ans)
``` | output | 1 | 44,920 | 20 | 89,841 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321. | instruction | 0 | 44,921 | 20 | 89,842 |
Tags: combinatorics, greedy
Correct Solution:
```
# import itertools
# import bisect
# import math
from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
# sys.setrecursionlimit(10 ** 5)
ii = lambda: int(input())
lmii = lambda: list(map(int, input().split()))
slmii = lambda: sorted(map(int, input().split()))
li = lambda: list(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def lcm(a, b): return (a * b) // gcd(a, b)
def main():
# for _ in " " * int(input()):
n = li()
n.append(10)
cnt = 0
ans = 1
ln = len(n)
for i in range(1, ln):
if int(n[i]) + int(n[i - 1]) == 9:
cnt += 1
else:
ans *= ((((cnt + 1) // 2) + 1) if cnt % 2 == 0 else 1)
cnt = 0
print(ans)
pass
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")
if __name__ == "__main__":
main()
``` | output | 1 | 44,921 | 20 | 89,843 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321. | instruction | 0 | 44,922 | 20 | 89,844 |
Tags: combinatorics, greedy
Correct Solution:
```
import sys
import math
data = sys.stdin.read().split()
data_ptr = 0
def data_next():
global data_ptr, data
data_ptr += 1
return data[data_ptr - 1]
S = data[0]
N = len(S)
ans = 1
block = 0
for i in range(N):
if i == N - 1 or int(S[i]) + int(S[i + 1]) != 9:
if block > 0 and block % 2 == 0:
ans *= block // 2 + 1
block = 0
else:
block += 1
print(ans)
``` | output | 1 | 44,922 | 20 | 89,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321.
Submitted Solution:
```
import sys
def solve():
a = list(map(int, list(input())))
res = 1
curcount = 1
for i in range(1, len(a)):
if a[i] + a[i-1] == 9:
curcount += 1
else:
if curcount > 2 and curcount % 2 == 1:
res*=(curcount//2 + 1)
curcount = 1
if curcount > 2 and curcount % 2 == 1:
res*=(curcount//2 + 1)
return res
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
print(solve())
``` | instruction | 0 | 44,923 | 20 | 89,846 |
Yes | output | 1 | 44,923 | 20 | 89,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321.
Submitted Solution:
```
class CodeforcesTask374BSolution:
def __init__(self):
self.result = ''
self.number = []
def read_input(self):
self.number = [int(c) for c in input()]
def process_task(self):
nums = 1
x = 0
#factors = [1]
while x + 1 < len(self.number):
s = 1
while self.number[x] + self.number[x + 1] == 9:
s += 1
x += 1
if x + 1 >= len(self.number):
break
if s > 2:
if s % 2:
#factors.append(s - 1)
nums *= s // 2 + 1
x += 1
#print(factors)
self.result = str(nums)
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask374BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
``` | instruction | 0 | 44,924 | 20 | 89,848 |
Yes | output | 1 | 44,924 | 20 | 89,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321.
Submitted Solution:
```
a = [int(x) for x in input()]
ans = 1
len_run = 0
for i in range(0,len(a)-1):
if a[i] + a[i+1] == 9:
len_run += 1
elif len_run != 0:
if len_run % 2 == 0:
ans *= int(len_run/2) + 1
len_run = 0
if len_run != 0:
if len_run % 2 == 0:
ans *= int(len_run/2) + 1
print(ans)
``` | instruction | 0 | 44,925 | 20 | 89,850 |
Yes | output | 1 | 44,925 | 20 | 89,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321.
Submitted Solution:
```
p = 10
cnt = 0
r = 1
for c in input():
c = int(c)
if c + p == 9:
cnt += 1
else:
if cnt > 0 and cnt % 2 == 0:
r *= cnt//2 + 1
cnt = 0
p = c
if cnt > 0 and cnt % 2 == 0:
r *= cnt//2 + 1
print(r)
``` | instruction | 0 | 44,926 | 20 | 89,852 |
Yes | output | 1 | 44,926 | 20 | 89,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321.
Submitted Solution:
```
s = input()
n = len(s)
k = 1
p = 1
for i in range(n - 1):
if (int(s[i]) + int(s[i + 1])) % 9 == 0 and s[i] != '9' and s[i] != '0':
k += 1
else:
if k > 1 and k % 2 == 1:
p *= (k + 1) // 2
k = 1
if k > 1 and k % 2 == 1:
p *= (k + 1) // 2
print(p)
``` | instruction | 0 | 44,927 | 20 | 89,854 |
No | output | 1 | 44,927 | 20 | 89,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321.
Submitted Solution:
```
num = input()
ll = []
coint = 0
for id, char in enumerate(num):
for ind, j in enumerate(num):
if ind - id == 1:
if int(char) + int(j) == 9:
coint += 1
print(coint//2 +1)
``` | instruction | 0 | 44,928 | 20 | 89,856 |
No | output | 1 | 44,928 | 20 | 89,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321.
Submitted Solution:
```
a=input()
ans=1
l=len(a)
for i in range(l-4):
if (int(a[i])+int(a[i+1]))%9==0 and a[i]==a[i+2] and a[i+1]!=a[i+3]:
ans*=2
if l>=3 and (int(a[l-3])+int(a[l-2]))%9==0 and a[l-3]==a[l-1]:
ans*=2
print(ans)
``` | instruction | 0 | 44,929 | 20 | 89,858 |
No | output | 1 | 44,929 | 20 | 89,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.
For instance, Inna can alter number 14545181 like this: 14545181 β 1945181 β 194519 β 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.
Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.
Input
The first line of the input contains integer a (1 β€ a β€ 10100000). Number a doesn't have any zeroes.
Output
In a single line print a single integer β the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
369727
Output
2
Input
123456789987654321
Output
1
Input
1
Output
1
Note
Notes to the samples
In the first sample Inna can get the following numbers: 369727 β 99727 β 9997, 369727 β 99727 β 9979.
In the second sample, Inna can act like this: 123456789987654321 β 12396789987654321 β 1239678998769321.
Submitted Solution:
```
p = 10
cnt = 0
r = 0
for c in input():
c = int(c)
if c + p == 9:
cnt += 1
else:
if cnt > 0 and cnt % 2 == 0:
r += 1
cnt = 0
p = c
if cnt > 0 and cnt % 2 == 0:
r += 1
print(2**r)
``` | instruction | 0 | 44,930 | 20 | 89,860 |
No | output | 1 | 44,930 | 20 | 89,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | instruction | 0 | 45,079 | 20 | 90,158 |
Tags: binary search, brute force, dp, math
Correct Solution:
```
class ReallyBigNumbers:
def __init__(self, n, s):
self.n = n
self.s = s
self.binarySearch()
def binarySearch(self):
l = self.s
h = 10000000000000000000
while(l < h):
mid = (h + l) // 2
#print(mid, self.isReallyBig(mid))
if self.isReallyBig(mid):
h = mid
else:
l = mid + 1
self.x = int(l)
def isReallyBig(self, v):
cp = v
add = 0
while v > 0:
add += v % 10
v //= 10
#print('resta', cp-add, cp, add)
return (cp - add) >= self.s
def show(self):
if self.x <= self.n:
print(str(self.n - self.x + 1))
else:
print(0)
n, s = map(int, input().split())
rbg = ReallyBigNumbers(n, s)
#print(rbg.x)
rbg.show()
``` | output | 1 | 45,079 | 20 | 90,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | instruction | 0 | 45,080 | 20 | 90,160 |
Tags: binary search, brute force, dp, math
Correct Solution:
```
n,s = map(int,input().split())
l = n+1
for i in range(s,min(s+1000000, n)+1,1):
cur = sum([int(j) for j in str(i)])
if(i-cur>=s):
l = i; break
print(n-l+1)
``` | output | 1 | 45,080 | 20 | 90,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | instruction | 0 | 45,081 | 20 | 90,162 |
Tags: binary search, brute force, dp, math
Correct Solution:
```
def sum_dig(num):
num = str(num)
ans = 0
for i in range(len(num)):
ans += int(num[i])
return ans
n,s = map(int,input().split())
ans = 0
for i in range(s,n+1):
if i - sum_dig(i) >= s:
ans = n - i + 1
break
print(ans)
``` | output | 1 | 45,081 | 20 | 90,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | instruction | 0 | 45,082 | 20 | 90,164 |
Tags: binary search, brute force, dp, math
Correct Solution:
```
n,s=map(int,input().split())
lo,hi=s,n
ans=n+1
while lo<=hi:
mid=(lo+hi)//2
z=sum(map(int,str(mid)))
if mid>=s+z:
ans=mid
hi=mid-1
else:
lo=mid+1
print(n-ans+1)
``` | output | 1 | 45,082 | 20 | 90,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | instruction | 0 | 45,083 | 20 | 90,166 |
Tags: binary search, brute force, dp, math
Correct Solution:
```
n, s = map(int, input().split())
print(max(n-min(i for i in range(s, s+200)
if i-sum(map(int, str(i))) >= s)+1, 0))
``` | output | 1 | 45,083 | 20 | 90,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | instruction | 0 | 45,084 | 20 | 90,168 |
Tags: binary search, brute force, dp, math
Correct Solution:
```
n, s = map(int, input().split())
a, b, c = 0, n + 1, 0
while a < b:
c = (a + b) // 2
if c - sum([int(x) for x in str(c)]) < s:
a = c + 1
else:
b = c
print(n - b + 1)
``` | output | 1 | 45,084 | 20 | 90,169 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | instruction | 0 | 45,085 | 20 | 90,170 |
Tags: binary search, brute force, dp, math
Correct Solution:
```
n, s = map(int, input().split())
ans = 0
p = s
for i in range(163):
p = s + i
if p > n:
break
if p >= s + sum(map(int, str(p))):
ans += 1
if p <= n:
ans += n - p
print(ans)
``` | output | 1 | 45,085 | 20 | 90,171 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | instruction | 0 | 45,086 | 20 | 90,172 |
Tags: binary search, brute force, dp, math
Correct Solution:
```
arr = [int(x) for x in input().split()]
n = arr[0]
s = arr[1]
resp = 0
leng = len(str(s))
j = 0
for i in range(s, s + leng*9 + 1):
j = i
if i > n:
break
temp = 0
c = i
while c:
temp += c % 10
c //= 10
if i - temp >= s:
resp += 1
j += 1
if j > n:
print (resp)
else:
print (n - j + 1 + resp)
``` | output | 1 | 45,086 | 20 | 90,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9).
Submitted Solution:
```
def main():
def sumofdigit(n):
temp=0
while(n>0):
temp+=n%10
n=n//10
return temp
def F(x):
return x-sumofdigit(x)
def findout(s):
test=s-s%10+10
while(1):
if F(test)>=s:
break
else:
test+=10
return test
n,s=list(map(int,input().strip().split(' ')))
L=findout(s)
ans=n-L+1
if ans<0:
print(0)
else:
print(ans)
main()
``` | instruction | 0 | 45,087 | 20 | 90,174 |
Yes | output | 1 | 45,087 | 20 | 90,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9).
Submitted Solution:
```
n,s = map(int,input().split())
if s > n:
print('0')
else:
for i in range(s,n+2):
l = 0
for j in str(i):
l += int(j)
if i - l >= s:
break
print(n - i+1)
``` | instruction | 0 | 45,088 | 20 | 90,176 |
Yes | output | 1 | 45,088 | 20 | 90,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9).
Submitted Solution:
```
def bigNumber(n, s):
for i in range(s, n + 1):
sumVal = 0
num = i
while num:
sumVal += num % 10
num //= 10
if i - sumVal >= s:
print(n - i + 1)
return
print(0)
n, s = (int(x) for x in input().split())
bigNumber(n,s)
``` | instruction | 0 | 45,089 | 20 | 90,178 |
Yes | output | 1 | 45,089 | 20 | 90,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9).
Submitted Solution:
```
def forninho(miolo, s):
premiolo = miolo
temp = 0
while (miolo > 0):
temp += miolo % 10;
miolo = miolo // 10;
if (premiolo - temp >= s):
return 1
else:
return 0
entrada = input().split()
n = int(entrada[0])
s = int(entrada[1])
result = -1
l = 1
r = n
while (r-l >= 0):
miolo = (l + r) // 2
if(forninho(miolo,s) == 1):
r = miolo - 1
result = miolo
else:
l = miolo + 1
if (result == -1):
print("0")
else:
print(n - result + 1)
``` | instruction | 0 | 45,090 | 20 | 90,180 |
Yes | output | 1 | 45,090 | 20 | 90,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9).
Submitted Solution:
```
def suma(n):
res = 0
while n > 0:
res += n % 10
n //= 10
return res
n, s = map(int, input().split())
su = suma(n)
res = 0
maxS = n - su
if maxS >= s:
res += (n % 10) + 1
#print('ms', maxS)
#print('res p:', res)
maxS -= 9
#print('mS', maxS)
cant = max(0,(maxS // 9) - s)
res += cant * 10
print(res)
``` | instruction | 0 | 45,091 | 20 | 90,182 |
No | output | 1 | 45,091 | 20 | 90,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9).
Submitted Solution:
```
n, s = map(int, input().split())
s = (s // 9 + (s % 9 != 0)) * 9
a = n // 10 * 9
print(max(0, (a - s) // 9 * 10 + n % 10 + 1))
``` | instruction | 0 | 45,092 | 20 | 90,184 |
No | output | 1 | 45,092 | 20 | 90,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9).
Submitted Solution:
```
def cmp(x1 = [],x2 = []):
len1 = len(x1)
len2 = len(x2)
if len1 == len2:
for i in range(len1):
n1 = x1[len1 - 1 - i]
n2 = x2[len1 - 1 - i]
if n1 != n2:
return n1 > n2
else:
return len1 > len2
return True
def add(x1 = [],x2 = []):
if not cmp(x1,x2):
x1,x2 = x2,x1
len1 = len(x1)
len2 = len(x2)
for i in range(len1 - len2):
x2.append(0)
res = []
flag = 0
for n1,n2 in zip(x1,x2):
m = n1 + n2 + flag
flag = m // 10
res.append(m % 10)
if flag:
res.append(flag)
return res
def minus(x1 = [],x2 = []):
if not cmp(x1,x2):
x1,x2 = x2,x1
len1 = len(x1)
len2 = len(x2)
for i in range(len1 - len2):
x2.append(0)
res = []
flag = 0
for n1,n2 in zip(x1,x2):
m = n1 - n2 + flag
flag = 0 if m >= 0 else -1
res.append((m + 10) % 10)
while res and not res[-1]:
res.pop()
return res
def div(x1 = [], x2 = 9):
if x2 == 10:
return x1[1:]
else:
x1.reverse()
res = []
mod = 0
for n in x1:
res.append((n + mod * 10)// 9)
mod = (n + mod * 10) % 9
res.reverse()
while res and not res[-1]:
res.pop()
return res
def multi(x1 = [],x2 = 9):
x1_copy = x1.copy()
x1.insert(0,0)
if x2 == 10:
return x1
else:
return minus(x1,x1_copy)
if __name__ == "__main__":
input_str = input()
n,s = [a for a in input_str.split()]
nl = list([int(a) for a in list(n)])
sl = list([int(a) for a in list(s)])
nl.reverse()
sl.reverse()
# x = (sl + 8) // 9 * 9
x = multi(div(add(sl.copy(),[8]),9),9)
# y = (x + 9) // 10 * 10
y = multi(div(add(x.copy(),[9]),10),10)
# z = y + (x - y + sum(y)) * 10 // 9
sumy = list([int(a) for a in list(str(sum(y)))])
sumy.reverse()
z = add(y,multi(div(minus(minus(x,y),sumy),9),10))
if cmp(nl,z):
ans = add(minus(nl,z),[1])
else:
ans = [0]
ans.reverse()
ansstr = [str(a) for a in ans]
print("".join(ansstr))
``` | instruction | 0 | 45,093 | 20 | 90,186 |
No | output | 1 | 45,093 | 20 | 90,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 1018).
Output
Print one integer β the quantity of really big numbers that are not greater than n.
Examples
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9).
Submitted Solution:
```
from math import ceil
n, s = [int(i) for i in input().split()]
k = s // 9 if s % 9 == 0 else (s//9 + 1)
f = 10 * k
print(max(n - f + 1, 0))
``` | instruction | 0 | 45,094 | 20 | 90,188 |
No | output | 1 | 45,094 | 20 | 90,189 |
Provide a correct Python 3 solution for this coding contest problem.
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:
* In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.
For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.
You are given a positive integer K. Find the K-th smallest lunlun number.
Constraints
* 1 \leq K \leq 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer.
Examples
Input
15
Output
23
Input
1
Output
1
Input
13
Output
21
Input
100000
Output
3234566667 | instruction | 0 | 45,175 | 20 | 90,350 |
"Correct Solution:
```
k=int(input())
if k<9:print(k);exit()
t=[i for i in range(1,10)]
c=9
while c<k:
a=t.pop(0)
for i in range(max(0,a%10-1),min(10,a%10+2)):
t.append(a*10+i)
c+=1
print(t[-1-c+k])
``` | output | 1 | 45,175 | 20 | 90,351 |
Provide a correct Python 3 solution for this coding contest problem.
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:
* In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.
For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.
You are given a positive integer K. Find the K-th smallest lunlun number.
Constraints
* 1 \leq K \leq 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer.
Examples
Input
15
Output
23
Input
1
Output
1
Input
13
Output
21
Input
100000
Output
3234566667 | instruction | 0 | 45,176 | 20 | 90,352 |
"Correct Solution:
```
k=int(input())
l=[1,2,3,4,5,6,7,8,9]
for i in range(k):
x=l[i]
if x%10!=0:
l.append(10*x+x%10-1)
l.append(10*x+x%10)
if x%10!=9:
l.append(10*x+x%10+1)
print(x)
``` | output | 1 | 45,176 | 20 | 90,353 |
Provide a correct Python 3 solution for this coding contest problem.
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:
* In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.
For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.
You are given a positive integer K. Find the K-th smallest lunlun number.
Constraints
* 1 \leq K \leq 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer.
Examples
Input
15
Output
23
Input
1
Output
1
Input
13
Output
21
Input
100000
Output
3234566667 | instruction | 0 | 45,177 | 20 | 90,354 |
"Correct Solution:
```
K = int(input())
A = [1,2,3,4,5,6,7,8,9]
for i in A:
if K<len(A):
break
x = i%10
for j in range(max(x-1,0),min(x+2,10)):
A.append(10*i+j)
print(A[K-1])
``` | output | 1 | 45,177 | 20 | 90,355 |
Provide a correct Python 3 solution for this coding contest problem.
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:
* In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.
For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.
You are given a positive integer K. Find the K-th smallest lunlun number.
Constraints
* 1 \leq K \leq 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer.
Examples
Input
15
Output
23
Input
1
Output
1
Input
13
Output
21
Input
100000
Output
3234566667 | instruction | 0 | 45,178 | 20 | 90,356 |
"Correct Solution:
```
from collections import deque
k = int(input())
a = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(k-1):
b = a.popleft()
if b%10 != 0: a.append(b*10+b%10-1)
a.append(b*10+b%10)
if b%10 != 9: a.append(b*10+b%10+1)
print(a[0])
``` | output | 1 | 45,178 | 20 | 90,357 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.