description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
tot = sum(A)
if tot % 2:
print(0)
else:
target = tot // 2
dp = [0] * (target + 1)
dp[0] = 1
for a in A:
for i in range(target, a - 1, -1):
dp[i] |= dp[i - a]
if not dp[-1]:
print(0)
else:
odd = [i for i, a in enumerate(A, 1) if a % 2]
even = [i for i, a in enumerate(A, 1) if not a % 2]
if odd:
print(1)
print(odd[0])
else:
while True:
x, y = [], []
for i in even:
A[i - 1] //= 2
if A[i - 1] % 2:
x.append(i)
else:
y.append(i)
if x:
break
even = y
print(1)
print(x[0]) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
SUM = sum(A)
DP = {0}
for a in A:
NDP = set()
for d in DP:
NDP.add(a + d)
DP |= NDP
if SUM % 2 == 1 or not SUM // 2 in DP:
print(0)
exit()
TWO = [0] * n
for i in range(n):
count = 0
while A[i] % 2 == 0:
count += 1
A[i] //= 2
TWO[i] = count
MIN = min(TWO)
x = TWO.index(MIN)
print(1)
print(x + 1) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | n = int(input())
xs = [int(x) for x in input().split()]
while all(x % 2 == 0 for x in xs):
xs = [(x // 2) for x in xs]
sm = sum(xs)
if sum(xs) % 2 == 1:
print(0)
exit()
dp = set([0])
good = True
for x in xs:
toadd = set()
for s in dp:
num = x + s
if num == sm // 2:
good = False
break
toadd.add(num)
dp = dp.union(toadd)
if good:
print(0)
else:
print(1)
for i, x in enumerate(xs):
if x % 2 == 1:
print(i + 1)
break | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR WHILE FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | def putin():
return map(int, input().split())
def ord(n):
answer = 0
while n % 2 == 0:
n //= 2
answer += 1
return answer
def check_knapsack(A):
S = sum(A) // 2
st = {0}
for elem in A:
for el in st.copy():
if el + elem < S:
st.add(el + elem)
if el + elem == S:
return True
return False
def sol():
n = int(input())
A = list(putin())
S = sum(A)
mn = float("inf")
mn = ord(A[0])
mn_ind = 0
for i in range(len(A)):
if ord(A[i]) < mn:
mn = ord(A[i])
mn_ind = i
S //= 2**mn
if S % 2 == 0 and check_knapsack(A):
print(1, mn_ind + 1, sep="\n")
else:
print(0)
sol() | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | def findsubarr(s, n, e):
if n == 1:
return {0, e}
else:
p = list(findsubarr(s, n - 1, a[n - 2]))
q = set()
for x in range(len(p)):
sum1 = p[x] + 0
sum2 = p[x] + e
if sum1 <= s:
q.add(sum1)
if sum2 <= s:
q.add(sum2)
return q
n = int(input())
a = list(map(int, input().split()))
q = min(a)
s = sum(a)
p = 1
if s % 2 == 0:
if (s / 2 in findsubarr(int(s / 2), n, a[n - 1])) == False:
print(0)
exit()
while True:
t = pow(2, p)
if s % t != 0:
print(0)
exit()
else:
for x in range(n):
if a[x] % t != 0:
print(1)
print(x + 1)
exit()
p = p + 1 | FUNC_DEF IF VAR NUMBER RETURN NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | import sys
input = sys.stdin.readline
def check(a, n, x, dp):
if x == 0:
return True
elif n == 0:
return False
elif dp[n][x] != -1:
return dp[n][x]
else:
dp[n][x] = check(a, n - 1, x, dp) or check(a, n - 1, x - a[n - 1], dp)
return dp[n][x]
n = int(input())
a = list(map(int, input().split()))
x = sum(a)
if x % 2 == 1:
print(0)
else:
x = x // 2
dp = [[(-1) for i in range(x + 1)] for j in range(n + 1)]
if not check(a, n, x, dp):
print(0)
else:
f = 0
ans = -1
for i in range(n):
if a[i] % 2 == 1:
f = 1
ans = i + 1
break
if f == 0:
ans = -1
while True:
gt = 0
for i in range(n):
if a[i] % 2 == 1:
ans = i + 1
gt = 1
break
a[i] = a[i] // 2
if gt == 1:
break
if gt == 1:
break
print(1)
print(ans) | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | def solve(arr):
n = len(arr)
mask = 0
for a in arr:
mask |= a
d = 0
while mask & 1 << d == 0:
d += 1
for i in range(n):
arr[i] >>= d
total = sum(arr)
if total & 1:
return 0
target = total // 2
f = [False] * (target + 1)
f[0] = True
for a in arr:
if a <= target and f[target - a]:
f[-1] = True
break
for x in range(target, a - 1, -1):
f[x] |= f[x - a]
if f[-1]:
print(1)
for i, a in enumerate(arr, 1):
if a & 1:
return i
return 0
input()
arr = list(map(int, input().split()))
print(solve(arr)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | def findPartition(arr, n):
sum = 0
i, j = 0, 0
for i in range(n):
sum += arr[i]
if sum % 2 != 0:
return False
part = [[(True) for i in range(n + 1)] for j in range(sum // 2 + 1)]
for i in range(0, n + 1):
part[0][i] = True
for i in range(1, sum // 2 + 1):
part[i][0] = False
for i in range(1, sum // 2 + 1):
for j in range(1, n + 1):
part[i][j] = part[i][j - 1]
if i >= arr[j - 1]:
part[i][j] = part[i][j] or part[i - arr[j - 1]][j - 1]
return part[sum // 2][n]
for _ in range(1):
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
if not findPartition(arr, n):
print(0)
else:
f = 0
for i in range(n):
if arr[i] % 2 == 1:
c = i
f = 1
break
if f:
print(1)
print(c + 1)
else:
f = 0
c = 0
while f == 0:
for i in range(n):
arr[i] //= 2
if arr[i] % 2 == 1:
c = i
f = 1
print(1)
print(c + 1) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | n = int(input())
(*arr,) = map(int, input().split())
while all(v % 2 == 0 for v in arr):
arr = [(v // 2) for v in arr]
s = sum(arr)
inf = n + 1
dp = [inf] * (sum(arr) + 1)
dp[0] = 0
for v in arr:
for i in range(len(dp) - 1, -1, -1):
if dp[i] != inf:
dp[i + v] = min(dp[i] + 1, dp[i + v])
def f():
if s % 2 or dp[s // 2] == inf:
return []
else:
found = -1
for i, v in enumerate(arr):
if v % 2:
found = i
break
assert found != -1
return [found]
ans = f()
print(len(ans))
print(*[(v + 1) for v in ans]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN LIST VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | from sys import stdin, stdout
input = stdin.readline
def main():
t = 1
for z in range(t):
n = int(input())
ai = list(map(int, input().split()))
num2 = sum(ai)
if num2 % 2 != 0:
print(0)
return
num3 = num2 // 2
n2 = 1000 * n
ar = [0] * (n2 + 2001)
ar[0] = 1
for i in range(n):
for j in range(n2 - 1, -1, -1):
ar[j + ai[i]] |= ar[j]
if ar[num3] == 0:
print(0)
return
num = 2
while 1:
ai2 = [(i % num) for i in ai]
if max(ai2):
print(1)
print(ai2.index(num // 2) + 1)
return
num *= 2
main() | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN VAR NUMBER EXPR FUNC_CALL VAR |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | n = int(input())
l = list(map(int, input().split()))
idx, min_cnt = 0, 1 << 30
s = sum(l)
if s % 2:
print(0)
else:
dp = [0] * (s // 2 + 1)
for i in range(n):
for j in range(s // 2, l[i] - 1, -1):
if dp[j - l[i]] or j == l[i]:
dp[j] = 1
for i in range(n):
cnt = 0
while l[i] % 2 == 0:
cnt += 1
l[i] //= 2
if cnt < min_cnt:
min_cnt = cnt
idx = i + 1
if dp[-1]:
print(1)
print(idx)
else:
print(0) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | def helper2(a, tar):
pool = [0] * 200005
pool[0] = 1
for i in range(len(a)):
child = []
for j in range(tar):
if pool[j] == 1:
child.append(j + a[i])
for c in child:
pool[c] = 1
return pool[tar] == 1
def helper(a):
if sum(a) % 2 == 1:
return -1
if helper2(a, sum(a) // 2):
while True:
for i in range(len(a)):
if a[i] % 2 == 1:
return i
a[i] = a[i] // 2
else:
return -1
n = int(input())
a = list(map(int, input().split(" ")))
res = helper(a)
if res == -1:
print(0)
print()
else:
print(1)
print(res + 1) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR VAR NUMBER FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | from sys import stdin, stdout
input = stdin.readline
def findPartiion(arr, n):
Sum = 0
for i in range(n):
Sum += arr[i]
if Sum % 2 != 0:
return 0
part = [0] * (Sum // 2 + 1)
for i in range(Sum // 2 + 1):
part[i] = 0
for i in range(n):
for j in range(Sum // 2, arr[i] - 1, -1):
if part[j - arr[i]] == 1 or j == arr[i]:
part[j] = 1
return part[Sum // 2]
t = 1
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
if sum(a) % 2:
print(0)
continue
if not findPartiion(a, n):
print(0)
continue
l = 0
r = n - 1
while l <= r:
vals = a[:]
i = l
del vals[i]
if not findPartiion(vals, n - 1):
print(1)
print(i + 1)
break
vals = a[:]
i = r
del vals[i]
if not findPartiion(vals, n - 1):
print(1)
print(i + 1)
break
l += 1
r -= 1
else:
assert 1 == 2 | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
if s % 2:
ans = 0
else:
ans = 1
dp = [([0] * (s + 1)) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
ai = a[i]
for j in range(s + 1):
dp[i + 1][j] |= dp[i][j]
for j in range(s - ai):
dp[i + 1][j + ai] |= dp[i][j]
y = 0
for i in range(n + 1):
y |= dp[i][s // 2]
if not y:
ans = 0
if ans:
for i in range(n):
si = s - a[i]
if si % 2:
x = i + 1
break
y = 0
for j in range(n + 1):
y |= dp[j][si // 2]
if not y:
x = i + 1
break
print(ans)
if ans:
print(x) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | import sys
def find_least_significant_bit(x):
binary = bin(x)
bit_location = binary.rfind("1")
return len(binary) - bit_location
n = int(input())
a = list(map(int, input().split()))
sums = {0}
for e in a:
sums_with_e = {(s + e) for s in sums}
sums.update(sums_with_e)
total = sum(a)
if total % 2 == 0 and total // 2 in sums:
print(1)
least_significant_set_bits = [find_least_significant_bit(e) for e in a]
print(least_significant_set_bits.index(min(least_significant_set_bits)) + 1)
else:
print(0)
print() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING RETURN BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a$ so that it becomes a good array. Can you help him?
A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into $2$ subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 100$) β the length of the array $a$.
The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 2000$) β the elements of the array $a$.
-----Output-----
The first line should contain the minimum number of elements you need to remove.
The second line should contain the indices of the elements you're removing, separated by spaces.
We can show that an answer always exists. If there are multiple solutions, you can print any.
-----Examples-----
Input
4
6 3 9 12
Output
1
2
Input
2
1 2
Output
0
-----Note-----
In the first example, you can partition the array into $[6,9]$ and $[3,12]$, so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements. | n = int(input())
a = [int(i) for i in input().split()]
sm = sum(a)
if sm % 2 == 1:
print(0)
else:
target = sm // 2
dp = [[(0) for j in range(target + 1)] for i in range(n + 1)]
dp[0][0] = 1
x = []
c = {(0): []}
boo = True
for i in range(1, n + 1):
for j in range(target):
if dp[i - 1][j]:
dp[i][j] = 1
if j + a[i - 1] <= target:
dp[i][j + a[i - 1]] = 1
if not dp[-1][-1]:
print(0)
exit()
while boo:
for i in range(n):
if a[i] % 2:
print(1)
print(i + 1)
exit()
a[i] /= 2 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR DICT NUMBER LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | MAX_T_SHIRT = 100
t_shirts_elephant_map = []
dp = []
def find(mask, t_shirt_id):
if mask == 0:
return 1
if t_shirt_id < 0:
return 0
if dp[mask][t_shirt_id] != -1:
return dp[mask][t_shirt_id]
ans = find(mask, t_shirt_id - 1)
for e_id in t_shirts_elephant_map[t_shirt_id]:
if mask & 1 << e_id > 0:
ans += find(mask ^ 1 << e_id, t_shirt_id - 1)
ans %= 1000000007
dp[mask][t_shirt_id] = ans
return ans
for t in range(int(input())):
elephant_count = int(input())
t_shirts_elephant_map = [list() for i in range(MAX_T_SHIRT)]
dp = [[(-1) for i in range(MAX_T_SHIRT)] for i in range(1 << elephant_count)]
for elephant_id in range(elephant_count):
t_shirts = [int(x) for x in input().split()]
for t_shirt in t_shirts:
t_shirts_elephant_map[t_shirt - 1].append(elephant_id)
print(find((1 << elephant_count) - 1, MAX_T_SHIRT - 1)) | ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | import sys
sys.setrecursionlimit(1000000)
t, mod = int(sys.stdin.readline()), 1000000007
while t:
n = int(sys.stdin.readline())
a = [[(0) for _ in range(101)] for _ in range(n + 1)]
for i in range(n):
cur = [int(x) for x in sys.stdin.readline().split()]
for x in cur:
a[i][x] = 1
t -= 1
lim = 1 << n
dp = [[(-1) for _ in range(lim + 1)] for _ in range(101)]
def tshirt(shirt, mask):
if mask == lim - 1:
return 1
if shirt > 100:
return 0
if dp[shirt][mask] != -1:
return dp[shirt][mask]
ans = 0
for ppl in range(n):
chk = 1 << ppl
if chk & mask:
continue
if not a[ppl][shirt]:
continue
ans += tshirt(shirt + 1, chk | mask) % mod
ans += tshirt(shirt + 1, mask) % mod
dp[shirt][mask] = ans
return ans
print(tshirt(0, 0)) | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | m = 10**9 + 7
def bitmask(mask, tid):
if mask == 2**n - 1:
return 1
if tid == 101:
return 0
if dp[mask][tid] != -1:
return dp[mask][tid]
ans = bitmask(mask, tid + 1)
for h in ts[tid]:
if mask & 1 << h:
continue
ans = (ans % m + bitmask(mask | 1 << h, tid + 1) % m) % m
dp[mask][tid] = ans
return ans
for _ in range(int(input())):
n = int(input())
dp = [([-1] * 102) for o in range(1024)]
ts = [[] for i in range(101)]
for j in range(n):
l = list(map(int, input().split()))
for k in l:
ts[k].append(j)
print(bitmask(0, 0)) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | MOD = 1000000007
n = tshirt = dp = None
ass = set()
def allocate(mask, tid):
if mask == (1 << n) - 1:
return 1
if tid == 101:
return 0
if dp[mask][tid] != -1:
return dp[mask][tid]
ans = allocate(mask, tid + 1)
for p in tshirt[tid]:
if mask >> p & 1:
continue
ans += allocate(mask | 1 << p, tid + 1)
dp[mask][tid] = ans % MOD
return ans % MOD
for _ in range(int(input())):
tshirt = [[] for _ in range(101)]
n = int(input())
for p in range(n):
for t in map(int, input().split()):
tshirt[t].append(p)
dp = [([-1] * 101) for _ in range(1 << n)]
print(allocate(0, 1)) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NONE ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | I = input
t = int(I())
mod = int(1000000000.0 + 7)
end = 0
dp = []
def fun(mask, tid, ls):
if mask == end:
return 1
if tid == 101:
return 0
if not dp[mask][tid] == -1:
return dp[mask][tid]
ans = 0
ans += fun(mask, tid + 1, ls)
for p in ls[tid]:
if not mask >> p & 1:
ans += fun(mask | 1 << p, tid + 1, ls)
ans %= mod
dp[mask][tid] = ans
return ans
while t:
n = int(I())
end = (1 << n) - 1
ls = []
dp = []
for i in range(1025):
dp.append([-1] * 101)
for i in range(101):
ls.append([])
for i in range(n):
str = list(map(int, I().strip().split(" ")))
for j in str:
ls[j].append(i)
print(fun(0, 1, ls))
t -= 1 | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | md = 10**9 + 7
book = dict()
ids = [set()] * 10
n = 0
def poss(i, a):
if (i, tuple(a)) in book.keys():
return book[i, tuple(a)]
elif i == 101:
if all(a):
return 1
else:
return 0
else:
res = poss(i + 1, a)
for j in range(n):
if i in ids[j] and not a[j]:
b = a.copy()
b[j] = True
res = (res + poss(i + 1, b)) % md
book[i, tuple(a)] = res
return res
for _ in range(int(input())):
N = int(input())
n = N
idlst = []
for k in range(N):
e = set(list(map(int, input().split())))
idlst.append(e)
ids = idlst
print(poss(1, [False] * N) % md)
book.clear() | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR RETURN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP LIST NUMBER VAR VAR EXPR FUNC_CALL VAR |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | dp = []
mod = 1000000007
p = 0
def solve(shirtNum, li, mask):
if shirtNum == 101:
if mask == p - 1:
return 1
else:
return 0
if dp[shirtNum][mask] != -1:
return dp[shirtNum][mask]
count = solve(shirtNum + 1, li, mask)
for i in li[shirtNum]:
if mask & 1 << i:
continue
count += solve(shirtNum + 1, li, mask | 1 << i)
dp[shirtNum][mask] = count % mod
return count % mod
for _ in range(int(input())):
n = int(input())
li = [[]] * 101
dp = [([-1] * (1 << n)) for i in range(102)]
p = 1 << n
for i in range(n):
for ele in list(map(int, input().split())):
if li[ele]:
li[ele].append(i)
else:
li[ele] = [i]
print(solve(1, li, 0)) | ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | MOD = 1000000007
T = int(input())
SHIRTS = 101
for t in range(T):
N = int(input())
owns = [([False] * SHIRTS) for _ in range(N)]
for i in range(0, N):
for s in map(int, input().split()):
owns[i][s] = True
dp = [([0] * (1 << N)) for _ in range(SHIRTS)]
dp[0][0] = 1
for s in range(1, SHIRTS):
for m in range(1 << N):
dp[s][m] = dp[s - 1][m]
for b in range(N):
if m & 1 << b and owns[b][s]:
dp[s][m] = (dp[s][m] + dp[s - 1][m ^ 1 << b]) % MOD
print(dp[SHIRTS - 1][(1 << N) - 1]) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | M, Mod = 105, 1000000007
T = int(input())
for _ in range(0, T):
n = int(input())
b = [[] for i in range(M)]
for i in range(0, n):
a = list(map(int, input().split()))
for j in range(0, len(a)):
b[a[j]].append(i)
dp = [[0] for i in range(M)]
for i in range(0, M):
dp[i] = [0] * (1 << n)
dp[0][0] = 1
for i in range(1, 101):
for S in range(0, 1 << n):
if dp[i - 1][S] == 0:
continue
dp[i][S] = (dp[i][S] + dp[i - 1][S]) % Mod
for x in b[i]:
if S & 1 << x:
continue
dp[i][S | 1 << x] = (dp[i][S | 1 << x] + dp[i - 1][S]) % Mod
print(dp[100][(1 << n) - 1]) | ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | import sys
t = int(sys.stdin.readline().strip())
for tc in range(t):
n = int(sys.stdin.readline().strip())
A = []
for i in range(n):
A.append(set([int(c) for c in sys.stdin.readline().split()]))
DP = []
DP.append([1] + [0] * 100)
for i in range(1, 2**n):
DP.append([0] * 101)
for t in range(1, 101):
for mask in range(2**n):
DP[mask][t] = DP[mask][t - 1]
for mask in range(2**n):
for p in range(n):
if DP[mask][t - 1] == 0:
continue
if mask & 1 << p > 0:
continue
if t not in A[p]:
continue
DP[mask | 1 << p][t] += DP[mask][t - 1]
print(DP[2**n - 1][100] % 1000000007) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | MOD = 1000000007
def findAns(mask, tid, n, people, dp):
if mask == (1 << n) - 1:
return 1
if tid >= 101:
return 0
if dp[tid][mask] != -1:
return dp[tid][mask]
ans = findAns(mask, tid + 1, n, people, dp)
for i in range(n):
if mask & 1 << i:
continue
if tid in people[i]:
ans += findAns(mask | 1 << i, tid + 1, n, people, dp)
ans %= MOD
dp[tid][mask] = ans
return dp[tid][mask] % MOD
for _ in range(int(input())):
n = int(input())
people = []
dp = [[(-1) for i in range(1 << n)] for j in range(101)]
for j in range(n):
arr = [int(c) for c in input().split()]
s = set(arr)
people.append(s)
print(findAns(0, 1, n, people, dp) % MOD) | ASSIGN VAR NUMBER FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | t = int(input())
while t > 0:
t -= 1
n = int(input())
a = []
mod = 10**9 + 7
ff = {}
a = [[] for i in range(105)]
for i in range(n):
b = [int(x) for x in input().split()]
for j in b:
a[j].append(i)
ff[j] = 1
dp = [[(0) for i in range(1025)] for j in range(105)]
dp[0][0] = 1
for i in range(1, 101):
dp[i][0] = 1
for j in range(len(a[i])):
for mask in range(1024):
if dp[i - 1][mask]:
if mask & 1 << a[i][j] == 0:
dp[i][mask | 1 << a[i][j]] += dp[i - 1][mask]
for mask in range(1, 1024):
if dp[i - 1][mask]:
dp[i][mask] += dp[i - 1][mask]
c = 0
c = dp[100][(1 << n) - 1]
c %= mod
print(c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | for _ in range(int(input())):
n = int(input())
arr = [[] for j in range(100)]
memo = {}
for i in range(n):
for j in input().split():
arr[int(j) - 1].append(i)
arr = [i for i in arr if i]
def helper(index, mask):
if index == len(arr):
return 1 if not mask else 0
if not mask:
return 1
if (index, mask) in memo:
return memo[index, mask]
count = 0
for i in arr[index]:
if mask & 1 << i:
count += helper(index + 1, mask ^ 1 << i)
count += helper(index + 1, mask)
memo[index, mask] = count % 1000000007
return memo[index, mask]
print(helper(0, (1 << n) - 1) % 1000000007) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN VAR NUMBER NUMBER IF VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | import sys
sys.setrecursionlimit(10**6)
ip = sys.stdin.readline
op = sys.stdout.write
def recursive_thinking(shirts, n, t_id, mask, tb):
if mask == 2**n - 1:
return 1
if t_id == 101:
return 0
if (t_id, mask) in tb:
return tb[t_id, mask]
ways = recursive_thinking(shirts, n, t_id + 1, mask, tb)
for j in range(n):
if mask & 1 << j == 0 and t_id in shirts[j]:
ways += recursive_thinking(shirts, n, t_id + 1, mask | 1 << j, tb)
tb[t_id, mask] = ways
return ways
t = int(ip())
res = []
mod = 1000000007
for _ in range(t):
n = int(ip())
shirts = {}
for i in range(n):
lst = [int(x) for x in ip().split()]
shirts[i] = set(lst)
ways = recursive_thinking(shirts, n, 1, 0, {})
res.append(ways % mod)
for val in res:
op(str(val) + "\n") | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER DICT EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | MOD = 1000000007
adj = [[] for x in range(101)]
dp = {}
def solve(tid, mask, n):
if mask == (1 << n) - 1:
return 1
if tid >= 101:
return 0
if (tid, mask) in dp:
return dp[tid, mask] % MOD
c = 0
c += solve(tid + 1, mask, n)
for x in adj[tid]:
if not 1 << x & mask:
c = (c + solve(tid + 1, mask | 1 << x, n) % MOD) % MOD
dp[tid, mask] = c % MOD
return c % MOD
test = int(input())
for _ in range(test):
n = int(input())
mask = 0
dp = {}
adj = [[] for x in range(101)]
for t in range(n):
for x in input().split(" "):
adj[int(x)].append(t)
print(solve(1, mask, n) % MOD) | ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | mod = 1000000007
def solve(shirt, people, dp, mask, n):
if mask == 0:
return 1
if shirt > 100:
return 0
if dp[shirt][mask] != -1:
return dp[shirt][mask]
ans = 0
for i in range(1, n + 1):
if mask & 1 << i - 1 != 0 and people[i][shirt]:
ans = ans + solve(shirt + 1, people, dp, mask ^ 1 << i - 1, n) % mod
ans = (ans + solve(shirt + 1, people, dp, mask, n)) % mod
dp[shirt][mask] = ans
return ans
t = int(input())
for _ in range(t):
n = int(input())
people = []
dp = []
for i in range(101):
dp.append([(-1) for j in range(1025)])
for i in range(11):
people.append([(False) for j in range(101)])
for i in range(1, n + 1):
temp = list(map(int, input().split()))
for x in temp:
people[i][x] = True
print(solve(1, people, dp, (1 << n) - 1, n)) | ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | t = int(input())
m = int(1000000000.0) + 7
allmask = 0
def solve(tss, dp, mask, tid):
if mask == allmask:
return 1
if tid > 100:
return 0
if dp[mask][tid] != -1:
return dp[mask][tid]
ways = solve(tss, dp, mask, tid + 1)
size = len(tss[tid])
for j in range(size):
if mask & 1 << tss[tid][j]:
continue
else:
ways += solve(tss, dp, mask | 1 << tss[tid][j], tid + 1)
ways %= m
dp[mask][tid] = ways
return ways
while t > 0:
t -= 1
n = int(input())
tss = [[] for i in range(101)]
for i in range(n):
for tshirt in map(int, input().split()):
tss[tshirt].append(i)
dp = [[(-1) for _ in range(101)] for _ in range((1 << n) + 1)]
allmask = (1 << n) - 1
print(solve(tss, dp, 0, 1)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | mod = int(1000000000.0 + 7)
n = 0
def solve(mask, i, tshirt, dp):
if mask == (1 << n) - 1:
return 1
if i > 100:
return 0
if dp[mask][i] != -1:
return dp[mask][i]
ways = solve(mask, i + 1, tshirt, dp)
for j in tshirt[i]:
j -= 1
if mask & 1 << j:
continue
ways += solve(mask | 1 << j, i + 1, tshirt, dp)
ways = ways % mod
dp[mask][i] = ways
return ways
for i in range(int(input())):
tshirt = [[] for i in range(102)]
dp = [[(-1) for i in range(102)] for j in range((1 << 10) + 2)]
n = int(input())
for i in range(1, n + 1):
l = list(map(int, input().split()))
for j in l:
tshirt[j].append(i)
print(solve(0, 1, tshirt, dp)) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR |
Read problems statements in Mandarin Chinese and Russian.
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
------ Input ------
First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts i^{th} person has.
------ Output ------
For each test case, print in single line the required number of ways modulo 1000000007 = 10^{9}+7.
------ Constraints ------
$1 β€ T β€ 10$
$1 β€ N β€ 10$
------ Example ------
Input:
2
2
3 5
8 100
3
5 100 1
2
5 100
Output:
4
4
------ Explanation ------
For the first case, 4 possible ways are (3,8), (3,100), (5,8) and (5,100).For the second case, 4 possible ways are (5,2,100), (100,2,5), (1,2,100), and (1,2,5). | def cek(mask, n):
if mask == maxmask:
return 1
if n > 100:
return 0
if dp[mask][n] != -1:
return dp[mask][n]
ans = cek(mask, n + 1)
for i in shirts[n]:
if mask & 1 << i == 0:
ans += cek(mask | 1 << i, n + 1)
ans %= 10**9 + 7
dp[mask][n] = ans
return ans
t = int(input())
for _ in range(t):
n = int(input())
shirts = [[] for x in range(101)]
maxmask = (1 << n) - 1
dp = [[(-1) for x in range(101)] for y in range((1 << n) + 1)]
for i in range(n):
for j in sorted(map(int, input().split())):
shirts[j].append(i)
print(cek(0, 1)) | FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def check(num, i):
ans = 1
b = [0, 0]
for j in range(8):
b.append(i & 1)
i = i >> 1
flag = True
for j in range(9, -1, -1):
t = num[j] + (b[j + 2] * 10 if j + 2 < 10 else 0)
if b[j] == 1 and t == 0:
return 0
tmp = t - b[j]
if tmp > 9:
flag = False
ans *= tmp + 1 if tmp < 10 else 19 - tmp
return ans - (2 if flag else 0)
for test in range(int(input())):
n = int(input())
num = [(n // 10**i % 10) for i in range(10)]
ans = 0
for i in range(2**8):
ans += check(num, i)
print(ans) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def int_input():
a = int(input())
return a
def int_list_input():
a = list(map(int, input().split()))
return a
def solve():
n = input()
a = ""
b = ""
for i in range(0, len(n), 2):
a += n[i]
for i in range(1, len(n), 2):
b += n[i]
ans = int(a) + 1
if b != "":
ans = ans * (int(b) + 1)
print(ans - 2)
for _ in range(int(input())):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for q in range(t):
a = input()
t = "0"
s = "0"
for i in range(len(a)):
if i % 2 == 0:
t += a[i]
else:
s += a[i]
print((int(t) + 1) * (int(s) + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
while t > 0:
n = input()
l1 = []
l2 = []
for i in range(len(n)):
if i % 2 == 0:
l1.append(n[i])
else:
l2.append(n[i])
n1 = n2 = 0
if len(l1) > 0:
n1 = int("".join(l1))
if len(l2) > 0:
n2 = int("".join(l2))
sol = (n1 + 1) * (n2 + 1) - 2
print(sol)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | n = int(input())
def get_n(n):
s = str(n)
res_c = ""
res_n = ""
for j in range(len(str(n))):
if j % 2 == 0:
res_n += s[j]
else:
res_c += s[j]
res_c = int(res_c) + 1
res_n = int(res_n) + 1
return res_c, res_n
def get_res(number):
if number < 10:
return number - 1
n, m = get_n(number)
t = n
n = m
m = t
if n == 1 or m == 1:
return n - 2
else:
return n * (m - 2) + (n - 1) * 2
res = []
for i in range(n):
res.append(get_res(int(input())))
for elem in res:
print(elem) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | tc = int(input())
for _ in range(tc):
n = input().strip()
n = n[::-1]
a = ""
b = ""
for i in range(len(n)):
if i % 2 == 0:
a = n[i] + a
else:
b = n[i] + b
if a == "":
a = 0
else:
a = int(a)
if b == "":
b = 0
else:
b = int(b)
ans = (a + 1) * (b + 1) - 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | n = int(input())
for i in range(n):
r = input()
if len(r) == 1:
print(int(r) - 1)
else:
a = int(r[::2])
b = int(r[1::2])
print((a + 1) * (b + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def div_num(N):
num = str(N)
n1 = num[::2]
n2 = num[1::2]
return int(n1), int(n2)
for i in range(int(input())):
n = int(input())
if n < 10:
ans = n - 1
else:
num1, num2 = div_num(n)
ans = (num1 + 1) * (num2 + 1) - 2
print(ans) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | import sys
input = sys.stdin.readline
def solve():
s = input().strip()
n = len(s)
even = [0, 0]
odd = [0, 0]
if int(s) < 10:
return int(s) - 1
s = s[::-1]
d0, d1 = int(s[0]), int(s[1])
dp = [[d0 + 1, 9 - d0], [d1 + 1, 9 - d1]]
for i in range(2, n):
d = int(s[i])
dp[i % 2] = [
(d + 1) * dp[i % 2][0] + d * dp[i % 2][1],
(9 - d) * dp[i % 2][0] + (9 - d + 1) * dp[i % 2][1],
]
return dp[0][0] * dp[1][0] - 2
for _ in range(int(input())):
print(solve()) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST BIN_OP VAR NUMBER BIN_OP NUMBER VAR LIST BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER LIST BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | import sys
strings = iter(sys.stdin.read().split())
ints = (int(x) for x in strings)
sys.setrecursionlimit(3000)
def f(a, carry=0):
ans = 0
if len(a) == 0:
ans += carry == 0
else:
*b, msd = a
if carry == 0:
ans += (msd + 1) * f(b)
if msd:
ans += msd * f(b, carry=1)
elif carry == 2:
if 9 - msd:
ans += (9 - msd) * f(b, carry=0)
ans += (10 - msd) * f(b, carry=1)
elif carry == 3:
if 9 - msd:
ans += (9 - msd) * f(b, carry=2)
ans += (10 - msd) * f(b, carry=3)
else:
assert carry == 1
ans += (msd + 1) * f(b, carry=2)
if msd:
ans += msd * f(b, carry=3)
return ans
def main():
ntc = next(ints)
for tc in range(1, ntc + 1):
a = tuple([int(c) for c in next(strings)][::-1])
print(f(a) - 2)
return
main() | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | a = {
(-1): 0,
(0): 1,
(1): 2,
(2): 3,
(3): 4,
(4): 5,
(5): 6,
(6): 7,
(7): 8,
(8): 9,
(9): 10,
(10): 9,
(11): 8,
(12): 7,
(13): 6,
(14): 5,
(15): 4,
(16): 3,
(17): 2,
(18): 1,
(19): 0,
}
def f(n, s):
r = 1
for i in range(len(s) - 1, -1, -1):
n, c = divmod(n, 10)
if s[i] == 1:
c -= 1
if i > 1:
if s[i - 2] == 1:
c += 10
r *= a[c]
return r
for _ in range(int(input())):
n = int(input())
ans = 0
if len(str(n)) < 3:
ans = f(n, "0" * len(str(n)))
else:
for mask in range(2 ** (len(str(n)) - 2)):
m = list(map(int, bin(mask)[2:].zfill(len(str(n)) - 2)))
while len(m) < len(str(n)):
m.append(0)
ans += f(n, m)
print(ans - 2) | ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def solve(n):
a = 0
b = 0
s = str(n)
for i in range(len(s)):
if i % 2 == 0:
a = a * 10 + int(s[i])
else:
b = b * 10 + int(s[i])
return (a + 1) * (b + 1) - 2
t = int(input())
for _ in range(t):
n = int(input())
print(solve(n)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
while t:
a = ""
b = ""
n = str(input())
for i in range(1, len(n), 2):
b += n[i]
for i in range(0, len(n), 2):
a += n[i]
if a == "":
a = 0
if b == "":
b = 0
print((int(a) + 1) * (int(b) + 1) - 2)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for tt in range(t):
s = list(input())
s1 = ""
s2 = ""
n = len(s)
for i in range(0, n, 2):
s1 += s[i]
for i in range(1, n, 2):
s2 += s[i]
if s1:
s1 = int(s1)
else:
s1 = 0
if s2:
s2 = int(s2)
else:
s2 = 0
print((s1 + 1) * (s2 + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | digit_map = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
def count(n, crr_neg, crr_pos):
n_ = [int(x) for x in list(str(n))]
assert len(crr_neg) == len(n_)
assert len(crr_pos) == len(n_)
v = 1
for idx, (d, c_neg, c_pos) in enumerate(zip(n_, crr_neg, crr_pos)):
d += c_neg + 10 * c_pos
if d < 0 or d >= 19:
return 0
v *= digit_map[d]
return v
def generate_carry_patterns(n):
if n > 2:
for i in range(2 ** (n - 2)):
crr_neg = [(int(x) * -1) for x in bin(i)[2:]] + [0, 0]
while len(crr_neg) < n:
crr_neg = [0] + crr_neg
crr_pos = [0] * len(crr_neg)
for j in range(n - 3, -1, -1):
if crr_neg[j] == -1:
crr_pos[j + 2] += 1
yield crr_neg, crr_pos
else:
yield [0] * n, [0] * n
def count_all(N):
num_digits = len(str(N))
tot = 0
for crr_neg, crr_pos in generate_carry_patterns(num_digits):
s = count(N, crr_neg, crr_pos)
tot += s
return tot - 2
T = int(input())
while T > 0:
T -= 1
n = int(input())
cnt = count_all(n)
print(cnt) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER LIST NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR VAR VAR EXPR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for i in range(t):
n = int(input())
arr = str(n)
ans = ""
ans1 = ""
for i in range(len(arr)):
if i % 2 == 0:
ans += arr[i]
else:
ans1 += arr[i]
if len(arr) == 1:
print(int(ans) - 1)
else:
a = (int(ans) + 1) * (int(ans1) + 1)
print(a - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = int(input())
s = str(n)
e = ""
o = ""
for i in range(len(s)):
if i % 2 == 0:
e = e + s[i]
else:
o = o + s[i]
if len(e) >= 1 and len(o) >= 1:
q = int(e)
t = int(o)
print((q + 1) * (t + 1) - 2)
else:
q = int(e)
print(q + 1 - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
while t:
t -= 1
n = input()
s1 = ""
s2 = ""
for i in range(len(n)):
if i % 2 == 0:
s1 += str(n[i])
else:
s2 += str(n[i])
i = j = 0
while i < len(s1) and s1[i] == "0":
i += 1
while j < len(s2) and s2[j] == "0":
j += 1
s1 = s1[i:]
s2 = s2[j:]
if len(s1) == 0:
s1 = 0
else:
s1 = int(s1)
if len(s2) == 0:
s2 = 0
else:
s2 = int(s2)
print((int(s1) + 1) * (int(s2) + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | T = int(input())
for _ in range(T):
n = input()
even = 0
odd = 0
for i in range(len(n)):
if i % 2 == 0:
even = even * 10 + int(n[i])
else:
odd = odd * 10 + int(n[i])
print((even + 1) * (odd + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def solver(num1, num2):
num1 = int(num1)
num2 = int(num2)
total1 = num1 + 1
total2 = num2 + 1
total = total1 * total2
tosub = 0
if num1 != 0 and num2 != 0:
return total - 2
if num1 == 0 and num2 != 0:
return total - 2
if num1 != 0 and num2 == 0:
return total - 2
if num1 == 0 and num2 == 0:
return 0
def lastsolver(train):
length = len(train)
if len(train) == 1:
if int(train) > 1:
print(int(train) - 1)
return int(train) - 1
else:
print(0)
return 0
if len(train) % 2 == 0:
l1 = length // 2
l2 = length // 2
num1 = ""
num2 = ""
for i in range(l1):
num1 = num1 + str(train[2 * i])
for i in range(l2):
num2 = num2 + str(train[2 * i + 1])
print(solver(num1, num2))
return solver(num1, num2)
else:
l1 = length // 2
l2 = length // 2 + 1
num1 = ""
num2 = ""
for i in range(l1):
num1 = num1 + str(train[2 * i + 1])
for i in range(l2):
num2 = num2 + str(train[2 * i])
print(solver(num1, num2))
return solver(num1, num2)
t = int(input())
for i in range(t):
current = input()
lastsolver(current) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for iter in range(t):
c = list(input())
c.reverse()
c = "".join(c)
s = c
a0 = dict()
a0[-1] = 0
a0[0] = 1
a0[1] = 2
a0[2] = 3
a0[3] = 4
a0[4] = 5
a0[5] = 6
a0[6] = 7
a0[7] = 8
a0[8] = 9
a0[9] = 10
a1 = dict()
a1[-1] = 10
a1[0] = 9
a1[1] = 8
a1[2] = 7
a1[3] = 6
a1[4] = 5
a1[5] = 4
a1[6] = 3
a1[7] = 2
a1[8] = 1
a1[9] = 0
a00 = dict()
a00[-1] = 0
a00[0] = 0
a00[1] = 2
a00[2] = 3
a00[3] = 4
a00[4] = 5
a00[5] = 6
a00[6] = 7
a00[7] = 8
a00[8] = 9
a00[9] = 10
a10 = dict()
a10[-1] = 10
a10[0] = 9
a10[1] = 8
a10[2] = 7
a10[3] = 6
a10[4] = 5
a10[5] = 4
a10[6] = 3
a10[7] = 2
a10[8] = 1
a10[9] = 0
ans = dict()
ans[-1] = [1, 0, 0, 0]
for i in range(len(s)):
local_ans = [0, 0, 0, 0]
last_ans = ans[i - 1]
local_ans[0] += last_ans[0] * a0[int(s[i])]
local_ans[1] += last_ans[0] * a1[int(s[i])]
local_ans[3] += last_ans[1] * a1[int(s[i])]
local_ans[2] += last_ans[1] * a0[int(s[i])]
local_ans[0] += last_ans[2] * a0[int(s[i]) - 1]
local_ans[1] += last_ans[2] * a1[int(s[i]) - 1]
local_ans[3] += last_ans[3] * a1[int(s[i]) - 1]
local_ans[2] += last_ans[3] * a0[int(s[i]) - 1]
ans[i] = local_ans
print(ans[len(s) - 1][0] - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = int(input())
n1 = 0
n2 = 0
idx = 0
p1 = 0
p2 = 0
while n != 0:
rem = n % 10
if idx % 2 == 0:
n1 += rem * pow(10, p1)
p1 += 1
else:
n2 += rem * pow(10, p2)
p2 += 1
n = n // 10
idx += 1
n1 -= 1
n2 -= 1
ans = n2 * n1 + n1 * 2 + n2 * 2 + 2
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def func():
n = input()
n1 = ""
n2 = ""
l = len(n)
for i in range(l):
if i % 2 == 0:
n1 += n[i]
else:
n2 += n[i]
if len(n2) == 0:
print(int(n1) - 1)
return
n1 = int(n1)
n2 = int(n2)
print((n1 + 1) * (n2 + 1) - 2)
t = int(input())
for i in range(t):
func() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | ways = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
def solve(n, d=0, c=[]):
if n == 0:
return len(c) == 0
num = n % 10
if d in c:
num -= 1
c.remove(d)
s1 = solve(n // 10, d + 1, c[:])
s2 = solve(n // 10, d + 1, c + [d + 2])
return (ways[num] * s1 if num >= 0 else 0) + (
ways[10 + num] * s2 if 10 + num <= 18 else 0
)
t = int(input())
for _ in range(t):
n = int(input())
print(solve(n) - 2) | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF NUMBER LIST IF VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR LIST BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | import sys
input = sys.stdin.readline
def quants(n, p):
l = int(n[-1])
if len(n) == 1:
if p[0] == 1:
return 0
return l - p[1] + 1
l = l - p[1]
ans = 0
if l + 1 > 0:
ans += (l + 1) * quants(n[:-1], [0, p[0]])
if 9 - l > 0:
ans += (9 - l) * quants(n[:-1], [1, p[0]])
return ans
for _ in range(int(input())):
print(quants(input().strip(), [0, 0]) - 2) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER LIST NUMBER VAR NUMBER IF BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR NUMBER LIST NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | import sys
read = lambda: sys.stdin.readline()
for _ in range(int(read())):
a = read()
if int(a) < 10:
print(int(a) - 1)
continue
num1 = int("".join([a[i] for i in range(0, len(a), 2)]))
num2 = int("".join([a[i] for i in range(1, len(a), 2)]))
print((num1 + 1) * (num2 + 1) - 2) | IMPORT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = input()
a = int("0" + "".join([n[i] for i in range(len(n)) if i % 2 == 0]))
b = int("0" + "".join([n[i] for i in range(len(n)) if i % 2 != 0]))
print((a + 1) * (b + 1) - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for i in range(t):
n = input()
if len(n) == 1:
print(int(n) - 1)
else:
ns = [char for char in n]
se = ""
so = ""
for i in range(len(ns)):
if i % 2 == 0:
se += ns[i]
else:
so += ns[i]
se = int(se) + 1
so = int(so) + 1
print(se * so - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
while t > 0:
t -= 1
s = input().strip()
a, b = "", ""
for i in range(len(s)):
if i % 2 == 0:
a += s[i]
else:
b += s[i]
if b == "":
b = 0
else:
b = int(b)
a = int(a)
print((a + 1) * (b + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
s = input()
s1 = ""
s2 = ""
for i in range(len(s)):
if i % 2 == 0:
s1 += s[i]
else:
s2 += s[i]
if s2 == "":
print(int(s1) - 1)
else:
s1, s2 = int(s1) + 1, int(s2) + 1
print(s1 * s2 - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for i in range(t):
n = input()
a = 0
b = 0
i = 0
state = False
for x in range(1, len(n) + 1):
digit = int(n[-1 * x])
if state:
b += 10**i * digit
else:
a += 10**i * digit
if state:
i += 1
state = not state
ans = (a + 1) * (b + 1) - 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | import sys
input = sys.stdin.readline
t = int(input())
pow2 = [1]
for _ in range(12):
pow2.append(2 * pow2[-1])
c = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0]
for _ in range(t):
n = list(input().rstrip())
n.reverse()
for i in range(len(n)):
n[i] = int(n[i])
l = len(n) - 2
if l <= 0:
ans = 1
for i in n:
ans *= i + 1
ans -= 2
else:
ans = 0
for i in range(pow2[l]):
ok = 1
n0 = list(n)
for j in range(l):
if pow2[j] & i:
n0[j] += 10
n0[j + 2] -= 1
if min(n0) < 0:
continue
cnt = 1
for j in n0:
cnt *= c[j]
ans += cnt
ans -= 2
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def solve():
n = str(input())
a = ""
b = ""
if len(n) == 1:
a = int(n)
b = 0
else:
for i in range(len(n)):
if i % 2 == 0:
a = a + n[i]
else:
b = b + n[i]
a = int(a)
b = int(b)
result = (a + 1) * (b + 1) - 2
print(result)
t = int(input())
for i in range(t):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | ans = []
for _ in range(int(input())):
s = list(map(int, list(input())))
n = len(s)
cnt = 0
for msk in range(max(1, 2 ** (n - 2))):
x = [0] * n
for j in range(n - 2):
if msk & 2**j > 0:
x[j] = 1
p = [0] * n
for j in range(n):
sm = s[j]
if j > 1 and x[j - 2] == 1:
sm += 10
if x[j] > sm:
continue
sm -= x[j]
if sm > 9:
p[j] = 9 - (sm - 9) + 1
else:
p[j] = sm + 1
for j in range(1, n):
p[j] *= p[j - 1]
cnt += p[-1]
ans.append(cnt - 2)
print("\n".join(map(str, ans))) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | import sys
def solve(num):
a = str(num)
b = a[::2]
if not b:
even = 0
else:
even = int(b)
c = a[1::2]
if not c:
odd = 0
else:
odd = int(c)
return (odd + 1) * (even + 1) - 2
first = True
for line in sys.stdin.readlines():
if first:
first = False
continue
n = int(line)
print(solve(n)) | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | n = int(input())
for _ in range(n):
x = input().zfill(10)
x1 = int(x[::2]) + 1
x2 = int(x[1::2]) + 1
print(x1 * x2 - 2)
exit() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = input()
l = len(n)
if l == 1:
print(int(n) - 1)
else:
a, b = int(n[::2]), int(n[1::2])
if l & 1 == 0:
a, b = b, a
print((a + 1) * (b + 1) - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | from sys import stdin
input = stdin.readline
rn = lambda: int(input())
rns = lambda: map(int, input().split())
rl = lambda: list(map(int, input().split()))
rs = lambda: input().strip()
YN = lambda x: print("YES") if x else print("NO")
mod = 10**9 + 7
for _ in range(rn()):
n = rs()
a = ""
b = ""
for i in range(len(n)):
if i & 1:
a += n[i]
else:
b += n[i]
def f(s):
if not s:
return 1
return int(s) + 1
ans = f(a) * f(b)
print(max(ans - 2, 0)) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = input()
flag = True
i = 0
a = ""
b = ""
while i < len(n):
if flag == True:
a += n[i]
i += 1
flag = False
else:
b += n[i]
i += 1
flag = True
a = int(a) if a != "" else 0
b = int(b) if b != "" else 0
print((a + 1) * (b + 1) - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | j = int(input())
for k in range(j):
t = input()
a = ""
b = ""
for i in range(len(t)):
if i % 2:
a += t[i]
else:
b += t[i]
if len(a) > 0:
c = int(a)
else:
c = 0
if len(b) > 0:
d = int(b)
else:
d = 0
print((c + 1) * (d + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def ii():
return int(input())
def si():
return input()
def mi():
return map(int, input().split())
def msi():
return map(str, input().split())
def li():
return list(mi())
t = ii()
for _ in range(t):
n = si()
a = int("0" + "".join([n[i] for i in range(0, len(n), 2)]))
b = int("0" + "".join([n[i] for i in range(1, len(n), 2)]))
print((a + 1) * (b + 1) - 2) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def solve(x):
o, e = "", ""
for i in range(len(x)):
if i % 2 == 0:
e += x[i]
else:
o += x[i]
if o == "":
o = 0
if e == "":
e = 0
print((int(e) + 1) * (int(o) + 1) - 2)
for _ in range(int(input())):
x = input()
solve(x) | FUNC_DEF ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def recursion(a, i, prev):
if i >= 0:
if i - 2 >= 0:
if a[i] == 0 and prev == "carry":
x = 9
y = d[x]["normal"]
r1 = recursion(a, i - 2, "carry")
ans = r1 * y
return ans
else:
if prev == "carry":
x = a[i] - 1
else:
x = a[i]
y = d[x]["normal"]
r1 = recursion(a, i - 2, "normal")
ans = r1 * y
y = d[x]["carry"]
r2 = recursion(a, i - 2, "carry")
ans += r2 * y
return ans
elif prev == "carry":
if a[i] == 0:
return 0
else:
return d[a[i] - 1]["normal"]
else:
return d[a[i]]["normal"]
else:
return 1
d = {}
for i in range(10):
d[i] = {"normal": 1 + i, "carry": 10 - i - 1}
for _ in range(int(input())):
a = list(map(int, list(input())))
n = len(a)
ans = recursion(a, n - 1, "normal")
ans *= recursion(a, n - 2, "normal")
print(ans - 2) | FUNC_DEF IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR RETURN VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR VAR RETURN VAR IF VAR STRING IF VAR VAR NUMBER RETURN NUMBER RETURN VAR BIN_OP VAR VAR NUMBER STRING RETURN VAR VAR VAR STRING RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR DICT STRING STRING BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for i in range(0, t):
n = input()
a = [None] * 1
b = [None] * 1
count = 0
for j in n:
if count == 0:
a[0] = j
elif count % 2 == 0:
a.append(j)
elif count == 1:
b[0] = j
else:
b.append(j)
count += 1
if a[0] != None:
a = int("".join(a))
else:
a = 0
if b[0] != None:
b = int("".join(b))
else:
b = 0
total = (a + 1) * (b + 1) - 2
print(total) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR NUMBER NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for _ in range(t):
n = str(input())
a, b = "", ""
n = n[::-1]
odd = False
for c in n:
if odd:
b += c
else:
a += c
odd = not odd
a = int("0" + a[::-1])
b = int("0" + b[::-1])
print((a + 1) * (b + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def solve():
s = input()
s1, s2 = "", ""
for i in range(len(s)):
if i % 2 == 0:
s1 += s[i]
else:
s2 += s[i]
if not s2:
print(int(s1) - 1)
else:
print((int(s1) + 1) * (int(s2) + 1) - 2)
return
t = int(input())
while t > 0:
t -= 1
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def read_int():
return int(input())
def read_ints():
return map(int, input().split(" "))
def calc(num):
return max(0, 10 - abs(num - 9))
t = read_int()
for case_num in range(t):
n = read_int()
digits = [int(ch) for ch in str(n)][::-1]
m = len(digits)
ans = 0
for state in range(1 << max(0, m - 2)):
i = state << 2
carry = [0] * m
s = list(digits)
for j in range(m):
if i & 1 << j:
carry[j] = 1
s[j - 2] += 10
choice = 1
for j in range(m):
num = s[j] - carry[j]
choice *= calc(num)
if choice == 0:
break
ans += choice
print(ans - 2) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for _ in range(t):
n = input()
j = 0
odd = ""
eve = ""
for i in reversed(range(len(n))):
if j % 2 == 0:
odd = n[i] + odd
else:
eve = n[i] + eve
j += 1
if len(eve) == 0:
eve = "0"
if len(odd) == 0:
odd = "0"
print((int(odd) + 1) * (int(eve) + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = int(input())
s = str(n)
len2 = len(s) - 2
if len(s) == 1:
print(int(s[-1]) - 1)
continue
if len(s) == 2:
print((int(s[-1]) + 1) * (int(s[-2]) + 1) - 2)
continue
ans = -2
for x in range(1 << len2):
b = "0b" + bin(x)[:1:-1] + "0" * 10
cur = 1
failed = False
for i in range(2):
if i + 2 < len(s) and b[i + 2] == "1":
cur *= int(s[i])
else:
cur *= int(s[i]) + 1
for i in range(2, len(s)):
if b[i] == "1" and s[i - 2] == "0" and b[i - 2] != "1":
failed = True
break
if b[i] == "1":
if i + 2 < len(s) and b[i + 2] == "1":
cur *= 10 - int(s[i])
else:
if s[i] == "9":
failed = True
break
cur *= 9 - int(s[i])
elif i + 2 < len(s) and b[i + 2] == "1":
cur *= int(s[i])
else:
cur *= int(s[i]) + 1
if not failed:
ans += cur
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | import sys
input = sys.stdin.readline
def main():
t = int(input())
for _ in range(t):
n = input()[:-1]
odd = 0
even = 0
for i, x in enumerate(n):
if i % 2:
even += int(x)
even *= 10
else:
odd += int(x)
odd *= 10
print((even // 10 + 1) * (odd // 10 + 1) - 2)
main() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def read_line():
return [int(x) for x in input().split()]
def read_int():
return int(input())
def solve():
n = read_int()
s = str(n)
a = ""
b = ""
for i in range(0, len(s)):
if i & 1:
a += s[i]
else:
b += s[i]
if a:
a = int(a)
else:
a = 0
if b:
b = int(b)
else:
b = 0
print((a + 1) * (b + 1) - 2)
t = read_int()
while t > 0:
solve()
t -= 1 | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = "0" + input()
a = int(n[0::2])
b = int(n[1::2])
print((a + 1) * (b + 1) - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
s = input()
a = ""
b = ""
for i in range(len(s)):
if i % 2 == 0:
a += s[i]
else:
b += s[i]
if len(b) == 0:
print(int(a) - 1)
else:
print((int(a) + 1) * (int(b) + 1) - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
num = str(input())
e, n_e = "", ""
for ind in range(len(num)):
if ind % 2 == 0:
e += num[ind]
else:
n_e += num[ind]
if n_e == "":
ans = int(e) - 1
else:
ans = (int(e) + 1) * (int(n_e) + 1) - 2
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def f(p, n, carries, acc):
if p == -1:
return acc
ret = 0
for carry in range(2):
if p < 2 and carry == 1:
continue
target = n[p] - carry + carries[p + 2] * 10
if target < 0:
continue
if target >= 10:
curr = 19 - target
else:
curr = target + 1
if curr > 0:
carries[p] = carry
ret += f(p - 1, n, carries, acc * curr)
return ret
T = int(input())
for _ in range(T):
n = tuple(map(int, reversed(input())))
carries = [0] * 12
answer = f(len(n) - 1, n, carries, 1) - 2
print(answer) | FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def solve():
s = "0" + input()
a, b = int(s[0::2]) + 1, int(s[1::2]) + 1
print(a * b - 2)
def main():
tc = int(input())
for _ in range(tc):
solve()
main() | FUNC_DEF ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | T = int(input())
for t in range(T):
n = input()
a = ""
b = ""
for i, c in enumerate(n[::-1]):
if i % 2 == 0:
a = c + a
else:
b = c + b
a = int(a)
if b:
b = int(b)
else:
b = 0
res = (a + 1) * (b + 1) - 2
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | t = int(input())
for aslkdjaskdj in range(t):
n = input()
flag = 0
j = "0"
o = "0"
for i in n:
if flag == 0:
o += i
else:
j += i
flag = 1 - flag
j = int(j)
o = int(o)
print((j + 1) * (o + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = int(input())
c1 = 1
c2 = 1
i = 0
a = 0
b = 0
while n:
r = int(n % 10)
if int(i % 2) == 0:
a = r * c1 + a
c1 *= 10
else:
b = r * c2 + b
c2 *= 10
n = int(n / 10)
i += 1
print((a + 1) * (b + 1) - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def main():
s = input()
n = len(s)
ans = ""
for i in range(0, n, 2):
ans += s[i]
n1 = int(ans)
ans = ""
for i in range(1, n, 2):
ans += s[i]
if ans == "":
ans = "0"
n2 = int(ans)
ans = (n1 + 1) * (n2 + 1) - 2
print(ans)
t = 1
t = int(input())
for ii in range(t):
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | T = int(input())
for i in range(T):
k = input()
t = len(k)
s = ""
r = ""
for i in range(t - 1, -1, -1):
if i % 2 == 0:
s = k[i] + s
else:
r = k[i] + r
s = "0" + s
r = "0" + r
print((int(s) + 1) * (int(r) + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | T = int(input())
for t in range(T):
N = input()
num1 = ""
for i in range(0, len(N), 2):
num1 = num1 + N[i]
num1 = int(num1)
num2 = ""
for i in range(1, len(N), 2):
num2 = num2 + N[i]
if num2 == "":
print(num1 - 1)
else:
num2 = int(num2)
print((num1 + 1) * (num2 + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | for _ in range(int(input())):
n = input()
a = ""
b = ""
for i in range(len(n)):
if i % 2 == 0:
a += n[i]
else:
b += n[i]
if len(a) > 0 and len(b) > 0:
print((int(a) + 1) * (int(b) + 1) - 2)
elif len(a) > 0:
print(int(a) - 1)
else:
print(int(b) - 1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | def helper(x):
l = []
while x > 0:
l.append(x % 10)
x = x // 10
l.reverse()
xe = 0
xo = 0
for i in range(len(l)):
if i % 2 == 0:
xe = 10 * xe + l[i]
else:
xo = 10 * xo + l[i]
return (xo + 1) * (xe + 1) - 2
t = int(input())
for xx in range(t):
n = int(input())
print(helper(n)) | FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β instead of carrying to the next column, she carries to the column two columns to the left.
For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
However, Alice evaluates it as shown:
In particular, this is what she does:
add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
add $1$, $2$ and $2$ to make $5$;
add $1$ to make $1$.
Thus, she ends up with the incorrect result of $15005$.
Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases. The description of the test cases follows.
The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) β the number Alice shows Bob.
-----Output-----
For each test case, output one integer β the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
-----Examples-----
Input
5
100
12
8
2021
10000
Output
9
4
7
44
99
-----Note-----
In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$: | import sys
tc = int(sys.stdin.readline())
cache1 = {
(0): 1,
(1): 2,
(2): 3,
(3): 4,
(4): 5,
(5): 6,
(6): 7,
(7): 8,
(8): 9,
(9): 10,
}
cache2 = {
(0): 9,
(1): 8,
(2): 7,
(3): 6,
(4): 5,
(5): 4,
(6): 3,
(7): 2,
(8): 1,
(9): 0,
}
for _ in range(tc):
arr = list(sys.stdin.readline().rstrip())
size = len(arr)
ans = 0
for i in range(1 << size):
temp = 1
for j in range(size):
if i & 1 << j != 0:
if j > 1:
if j + 2 < size and i & 1 << j + 2:
now = int(arr[size - 1 - j]) - 1
if now >= 0:
temp *= cache2[now]
else:
temp *= cache1[now % 10]
else:
now = int(arr[size - 1 - j]) - 1
if now >= 0:
temp *= cache1[now]
else:
temp = 0
else:
temp = 0
elif j + 2 < size and i & 1 << j + 2:
now = int(arr[size - 1 - j])
if now >= 0:
temp *= cache2[now]
else:
temp = 0
else:
now = int(arr[size - 1 - j])
temp *= cache1[now]
ans += temp
print(ans - 2) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.