description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
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
for _ in range(int(input())):
n = input()[:-1][::-1]
L = len(n)
dp = [[([0] * 2) for _ in range(2)] for _ in range(L + 1)]
dp[0][0][0] = 1
for i in range(L):
a = int(n[i]) + 1
b = 9 - int(n[i])
dp[i + 1][0][0] += a * dp[i][0][0]
dp[i + 1][0][1] += b * dp[i][0][0]
dp[i + 1][1][0] += a * dp[i][0][1]
dp[i + 1][1][1] += b * dp[i][0][1]
a = int(n[i])
b = 10 - int(n[i])
dp[i + 1][0][0] += a * dp[i][1][0]
dp[i + 1][0][1] += b * dp[i][1][0]
dp[i + 1][1][0] += a * dp[i][1][1]
dp[i + 1][1][1] += b * dp[i][1][1]
print(dp[L][0][0] - 2) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP 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$: | n = int(input())
for _ in range(n):
s = input()
a = "0"
b = "0"
for g in range(len(s)):
if g % 2 == 0:
a += s[g]
else:
b += s[g]
p = 1 + int(a)
q = 1 + int(b)
print(p * q - 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 ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR 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$: | for _ in range(int(input())):
n = int(input())
i = 1
a, b = 0, 0
while n:
a += n % 10 * i
n //= 10
b += n % 10 * i
n //= 10
i *= 10
if a == 0 or b == 0:
print(max(a - 1, b - 1))
else:
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 VAR NUMBER NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP 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$: | t = int(input())
for i in range(t):
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]
if a:
a = int(a)
if b:
b = int(b)
if not b:
b = 0
if not a:
a = 0
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 ASSIGN VAR VAR STRING 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 IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER IF 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$: | from sys import stdin
input = stdin.readline
def func(b, k):
if b >= k:
v = 1
flag = 0
t = a.copy()
for x in range(k - 1, -1, -1):
if o[x] == 0:
if t[x] < 0:
v = 0
break
v = v * (t[x] + 1)
else:
flag = 1
l = t[x] + 1
r = 9
if l <= r:
v = v * (r - l + 1)
if x >= 2:
t[x - 2] -= 1
else:
v = 0
break
if flag == 0:
v -= 2
res[-1] += v
return
o[b] = 0
func(b + 1, k)
o[b] = 1
func(b + 1, k)
for _ in range(int(input())):
n = input().rstrip()
a = list(map(int, n))
n = len(n)
k = len(a)
o = [0] * 21
res = [0]
func(2, k)
print(res[-1]) | ASSIGN VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR RETURN ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER VAR 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$: | t = int(input())
for _ in range(t):
s = input()[::-1]
odd = even = ""
k = len(s)
for i in range(0, k, 2):
odd += s[i]
if i + 1 < k:
even += s[i + 1]
odd = odd[::-1]
even = even[::-1]
if even == "":
even = "0"
odd = int(odd)
even = int(even)
ans = (odd + 1) * (even + 1) - 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING ASSIGN VAR STRING 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 |
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 answer():
n = list(input())
s1 = ""
s2 = ""
for i in range(len(n)):
if i % 2 == 0:
s1 += n[i]
else:
s2 += n[i]
if s2 == "":
print(int(n[0]) - 1)
return
ans = 0
x1 = int(s1)
x2 = int(s2)
if x2 == 0:
ans = x1 - 1
else:
ans = (x1 - 1) * (x2 + 1)
ans += 2 * x2
print(ans)
t = int(input())
for _ in range(t):
answer() | FUNC_DEF ASSIGN VAR FUNC_CALL 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 NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR 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$: | def cal():
s = list(input())
first = int("".join(s[0::2])) + 1
second = int("".join(s[1::2])) + 1 if len(s) > 1 else 1
print(first * second - 2)
def main():
t = int(input())
while t:
cal()
t -= 1
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL 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 = ["0"] + list(input())
evens = int("".join([i for i in n[::2]]))
odds = int("".join([i for i in n[1::2]]))
print((evens + 1) * (odds + 1) - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR 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$: | import sys
input = sys.stdin.readline
def solve():
s = "0" + input().strip()
a = int(s[0::2])
b = int(s[1::2])
return (a + 1) * (b + 1) - 2
for _ in range(int(input())):
print(solve()) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP STRING FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR 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$: | def conv(x):
if x == "":
return 1
return int(x) + 1
def main():
n = input()
l = len(n)
a, b = "", ""
for i in range(0, len(n), 2):
a += n[i]
for i in range(1, len(n), 2):
b += n[i]
print(conv(a) * conv(b) - 2)
t = int(input())
for i in range(t):
main() | FUNC_DEF IF VAR STRING RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING 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 EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR 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$: | import itertools as _itertools
import sys as _sys
def how_many_inputs_give_same_result_for_alice_addition(alice_additon_result):
if not isinstance(alice_additon_result, int):
raise TypeError
alice_additon_result = int(alice_additon_result)
if alice_additon_result < 2:
return 0
result = 0
digits_n = len(str(alice_additon_result))
for other_term_div_100_digits in _itertools.product("01", repeat=digits_n):
current_variants_n = 1
other_term_div_100 = int("".join(other_term_div_100_digits))
try:
mod_addition_result = _alice_sub(
alice_additon_result, 100 * other_term_div_100
)
except ValueError:
continue
for digits_sum_mod_10, digits_sum_div_10 in zip(
str(mod_addition_result).zfill(len(other_term_div_100_digits)),
other_term_div_100_digits,
):
digits_sum_mod_10 = int(digits_sum_mod_10)
digits_sum_div_10 = int(digits_sum_div_10)
if digits_sum_div_10 == 0:
first_digit_available = 0
last_digit_available = digits_sum_mod_10
else:
assert digits_sum_div_10 == 1
first_digit_available = digits_sum_mod_10 + 10 - 9
last_digit_available = 9
current_variants_n *= len(
range(first_digit_available, last_digit_available + 1)
)
result += current_variants_n
return result - 2
def _alice_sub(a, b):
assert b >= 0
if b > a:
raise ValueError
digits_n = len(str(a))
a_digits = [int(d) for d in str(a)]
b_digits = [int(d) for d in str(b).zfill(digits_n)]
result = 0
for power_of_10 in range(digits_n):
a_d = a_digits[-1 - power_of_10]
b_d = b_digits[-1 - power_of_10]
delta = a_d - b_d
result += delta % 10 * 10**power_of_10
if delta < 0:
try:
b_digits[-1 - power_of_10 - 2] += 1
except IndexError:
raise ValueError
return result
def _main():
[tests_n] = _read_ints()
for i_test in range(tests_n):
[alice_additon_result] = _read_ints()
result = how_many_inputs_give_same_result_for_alice_addition(
alice_additon_result
)
print(result)
def _read_ints(file=_sys.stdin):
return map(int, file.readline().split())
_main() | IMPORT IMPORT FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER FUNC_DEF VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN LIST VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF VAR RETURN FUNC_CALL VAR VAR FUNC_CALL 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 i in range(t):
n = input()
o = ""
e = ""
k = 1
for j in range(0, len(n)):
if k & 1:
o = o + n[j]
else:
e = e + n[j]
k += 1
if len(o) > 0:
o = int(o)
else:
o = 0
if len(e) > 0:
e = int(e)
else:
e = 0
if o == 0:
print(e - 1)
elif e == 0:
print(o - 1)
else:
print((o + 1) * (e + 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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())):
s = input()
n1 = s[::2]
n2 = s[1::2]
s1 = 1
if n1 != "":
s1 *= int(n1) + 1
if n2 != "":
s1 *= int(n2) + 1
print(s1 - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR 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$: | t = int(input())
for _ in range(t):
s = list(map(int, list(input())))
q = [(0, 1, [])]
result = 0
while q:
pos, pairs_count, ones_pos = q.pop(0)
if pairs_count == 0:
continue
add = int(pos in ones_pos)
if pos == len(s):
result += pairs_count
continue
target = s[-pos - 1] - add
target = target if target >= 0 else 10 + target
if target <= 8 and pos + 2 < len(s):
p = 9 - target
q.append((pos + 1, pairs_count * p, ones_pos + [pos + 2]))
if target == 9 and add:
if pos + 2 < len(s):
q.append((pos + 1, pairs_count * (target + 1), ones_pos + [pos + 2]))
else:
p = target + 1
q.append((pos + 1, pairs_count * p, ones_pos))
print(result - 2) | 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 LIST NUMBER NUMBER LIST ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR LIST BIN_OP VAR NUMBER IF VAR NUMBER VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR LIST BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP 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 prob():
s = input()
n = len(s)
if n == 1:
print(int(s) - 1)
return
a = ""
b = ""
for i in range(0, n, 2):
a += s[i]
for i in range(1, n, 2):
b += s[i]
x = int(a) + 1
y = int(b) + 1
print(x * y - 2)
t = 1
t = int(input())
for _ in range(0, t):
prob() | FUNC_DEF 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 RETURN ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER 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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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$: | numOfTestCases = int(input())
while numOfTestCases > 0:
numOfTestCases -= 1
aliceResult = input()
oddnumber = "0"
evenNumber = "0"
for i, c in enumerate(aliceResult):
if i % 2 == 0:
evenNumber += c
else:
oddnumber += c
oddnumber = int(oddnumber)
evenNumber = int(evenNumber)
print((oddnumber + 1) * (evenNumber + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR 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$: | d1 = {}
d2 = {(9): 0}
for i in range(10):
for j in range(10):
if i + j < 10:
if i + j not in d1:
d1[i + j] = 0
d1[i + j] += 1
else:
i1 = (i + j) % 10
if i1 not in d2:
d2[i1] = 0
d2[i1] += 1
f_dict = {(0): 1}
def process(n):
if n < 0:
return 0
if n in f_dict:
return f_dict[n]
answer = 0
n1 = n % 10
n2 = n // 10
answer = process(n // 10) * d1[n1]
if n2 >= 10:
n3 = list(str(n2))
m = len(n3)
works = False
while m - 2 >= 0:
if n3[m - 2] == "0":
n3[m - 2] = "9"
else:
n3[m - 2] = str(int(n3[m - 2]) - 1)
works = True
break
m -= 2
if works:
n3 = int("".join(n3))
answer += process(n3) * d2[n1]
f_dict[n] = answer
return answer
t = int(input())
for i in range(t):
n = int(input())
answer = process(n)
print(answer - 2) | ASSIGN VAR DICT ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN 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 FUNC_CALL 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 = b = 0
place = 1
while n:
a += n % 10 * place
n //= 10
b += n % 10 * place
n //= 10
place *= 10
return (a + 1) * (b + 1) - 2
for t in range(int(input())):
n = int(input())
print(solve(n)) | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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$: | def rec(pos, c, count_before, a_before, b_before):
global count
if pos < -l:
if a_before != 0 and b_before != 0:
count += count_before
return
c1 = c.copy()
c2 = c.copy()
c2[pos - 2] += 1
count1 = 0
count2 = 0
count0 = 0
for a in range(10):
a_now = a_before * 10 + a
b = (d[pos] - a - c[pos]) % 10
b_now = b_before * 10 + b
if a + b + c[pos] == d[pos]:
if a_now != 0 and b_now != 0:
count1 += 1
else:
rec(pos - 1, c1, count_before, a_now, b_now)
elif a + b + c[pos] == d[pos] + 10:
if -(pos - 2) <= l:
if a_now != 0 and b_now != 0:
count2 += 1
else:
rec(pos - 1, c2, count_before, a_now, b_now)
if count1 > 0:
rec(pos - 1, c1, count_before * count1, 1, 1)
if count2 > 0:
rec(pos - 1, c2, count_before * count2, 1, 1)
return
T = int(input())
for testcase in range(1, T + 1):
count = 0
n = int(input())
d = [int(x) for x in str(n)]
c = [(0) for x in range(len(d) + 3)]
l = len(d)
rec(-1, c, 1, 0, 0)
print(count) | FUNC_DEF IF VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER 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():
k = input()
if len(k) == 1:
print(int(k) - 1)
return
print((int(k[::2]) + 1) * (int(k[1::2]) + 1) - 2)
n = int(input())
for i in range(n):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN 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 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$: | def solve():
s = input()
f = 0
a = "0"
b = "0"
for c in s:
if f:
a += c
else:
b += c
f ^= 1
print((int(a) + 1) * (int(b) + 1) - 2)
def main():
tc = int(input())
for _ in range(tc):
solve()
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR 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 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$: | for _ in range(int(input())):
n = input()
if len(n) == 1:
print(int(n) - 1)
else:
n1 = ""
n2 = ""
for i in range(len(n)):
if i % 2 == 0:
n1 += n[i]
else:
n2 += n[i]
ans = (int(n1) + 1) * (int(n2) + 1) - 2
print(ans) | 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 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 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$: | t = int(input())
for _ in range(t):
sn = input()
s1 = sn[::2]
s2 = sn[1::2]
c1 = 0
for c in s1:
c1 = c1 * 10 + ord(c) - ord("0")
c2 = 0
for c in s2:
c2 = c2 * 10 + ord(c) - ord("0")
print((c1 + 1) * (c2 + 1) - 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR STRING 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 = 0
try:
a = int(s[1::2])
except:
a = 0
print((int(s[::2]) + 1) * (a + 1) - 2) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER 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):
s = input()
n = len(s)
s1 = ""
s2 = ""
for i in range(0, n, 2):
s1 += s[i]
for i in range(1, n, 2):
s2 += s[i]
k1 = int(s1)
k2 = 0 if s2 == "" else int(s2)
print((k1 + 1) * (k2 + 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 NUMBER VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING NUMBER 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$: | from sys import stdin, stdout
nmbr = lambda: int(input())
lst = lambda: list(map(int, input().split()))
for _ in range(nmbr()):
s = input()
n = len(s)
even = 0
odd = 0
for i in range(n):
if i & 1 == 0:
even = even * 10 + int(s[i])
else:
odd = odd * 10 + int(s[i])
ans = (even + 1) * (odd + 1) - 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR 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 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$: | def solve():
nn = input()
n1 = "0"
n2 = "0"
for i in range(len(nn)):
if i % 2 == 0:
n1 += nn[i]
else:
n2 += nn[i]
n1 = int(n1)
n2 = int(n2)
print((n1 + 1) * (n2 + 1) - 2)
t = int(input())
for _ in range(t):
solve() | FUNC_DEF 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 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$: | def main(n):
vals = [0, 0]
idx = 0
l = 0
while n:
d = n % 10
vals[idx] += d * pow(10, l)
n //= 10
idx ^= 1
if idx == 0:
l += 1
if vals[0] == 0 or vals[1] == 0:
return max(vals) - 1
else:
return (vals[0] + 1) * (vals[1] + 1) - 2
t = int(input())
ans = []
for i in range(t):
ans.append(main(int(input())))
for e in ans:
print(e) | FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
curr = 0
for i in a:
curr += i
ans |= i | curr
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | from sys import stdin
input = stdin.readline
MAX = 60
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
done = set()
for j in range(MAX):
asd = 1 << j
if asd >= a[i]:
break
x = a[i] % asd
if x != 0 and x not in done:
a.append(x)
done.add(x)
p = [0] * MAX
for i in a:
p[i.bit_length() - 1] += 1
for i in range(1, MAX):
p[i] += p[i - 1] >> 1
s = 0
for i in range(MAX):
if p[i]:
s += 1 << i
print(s) | ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for i in range(int(input())):
o = 0
s = 0
input()
l = map(int, input().split())
for j in l:
s += j
o = o | s | j
print(o) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | l1 = int(input())
for _ in range(l1):
n = int(input())
s = list(map(int, input().split()))
count = 0
a = []
for i in s:
a.append(count + i)
count += i
f = a[0]
for i in range(n):
f = f | a[i]
f = f | s[i]
print(f) | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
for _ in range(t):
bits = [0] * 50
n = int(input())
l = list(map(int, input().split()))
for i in range(n):
j = l[i]
index = 0
while j > 0:
val = j % 2
bits[index] += val
index += 1
j //= 2
ans = 0
cur = 0
for i in range(50):
val = bits[i] + cur
if val:
ans += 2**i
cur = val // 2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
l.sort()
m = [s - l[0]]
for i in range(1, n):
m.append(m[-1] - l[i])
for i in range(n):
s = s | m[i]
for i in range(n):
s = s | l[i]
print(s) | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ans = s
prefsum = 0
for i in range(n):
prefsum += a[i]
ans = ans | prefsum
ans = ans | a[i]
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
N = int(input())
temp = 0
sum = 0
arr = map(int, input().split())
for x in arr:
sum += x
temp = temp | x | sum
print(temp) | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().strip().split()))
ans = 0
bits = 0
for i in range(30):
for j in range(n):
if a[j] >> i & 1:
bits += 1
if bits > 0:
ans |= 1 << i
bits >>= 1
i = 30
while bits > 0:
ans |= 1 << i
bits >>= 1
i += 1
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
while t != 0:
n = int(input())
arr = list(map(int, input().split()))
ans = 0
sm = 0
while n > 0:
ans = ans | arr[n - 1]
sm = sm + arr[n - 1]
ans = ans | sm
n -= 1
print(ans)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | def answer():
bits = [0] * 61
ans = 0
for i in range(60):
for v in a:
if v >> i & 1:
bits[i] += 1
bits[i + 1] += bits[i] // 2
if bits[i]:
ans |= 1 << i
return ans
for T in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
print(answer()) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | def hello_bhai():
for i in range(n):
parameter = bin(hi[i])[2:]
le = len(parameter)
for j in range(le):
good_night[j] += int(parameter[-j - 1])
def kaisa_hai():
for i in range(100000):
if good_night[i] > 1:
byee(i)
def byee(i):
good_night[i + 1] += good_night[i] // 2
good_night[i] = 1
M = 100001
t = int(input())
for w in range(t):
n = int(input())
hi = list(map(int, input().split()))
good_night = [0] * M
hello_bhai()
kaisa_hai()
print(int("0b" + "".join(list(map(str, good_night[::-1]))), 2)) | FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = [(0) for x in range(30)]
for i in range(n):
x = a[i]
j = 0
while x > 0:
b[j] = b[j] + x % 2
x = x // 2
j += 1
k = 0
rep = 1
ans = 0
for i in range(30):
k = k // 2 + b[i]
if k > 0:
ans = ans + rep
rep = rep * 2
k = k // 2
while k > 0:
ans = ans + rep
rep = rep * 2
k = k // 2
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
sum = 0
r = 0
for j in range(n):
r |= a[j]
sum += a[j]
r |= sum
print(r) | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
finalOr = 0
numOfBits = 0
carryOverBits = 0
for i in range(50):
for j in l:
temp = j
temp = temp >> i
numOfBits += temp & 1
if numOfBits + carryOverBits >= 1:
finalOr = finalOr | 1 << i
carryOverBits = (numOfBits + carryOverBits) // 2
numOfBits = 0
print(finalOr) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | import sys
def main():
test_cases = int(sys.stdin.readline())
for _ in range(test_cases):
N = int(sys.stdin.readline())
A = [int(i) for i in sys.stdin.readline().split()]
max_bit = 50
bits_set = [(0) for _ in range(max_bit)]
for a in A:
for b in range(max_bit):
mask = 1 << b
if a & mask:
bits_set[b] += 1
soln = 0
for b in range(max_bit):
if bits_set[b] > 0:
mask = 1 << b
carry = bits_set[b] // 2
if b + 1 < max_bit:
bits_set[b + 1] += carry
soln |= mask
print(soln)
main() | IMPORT FUNC_DEF 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().strip().split()))
m = max(a).bit_length()
i = ans = bits = 0
while i < m or bits > 0:
for j in range(n):
if a[j] >> i & 1:
bits += 1
if bits > 0:
ans |= 1 << i
bits >>= 1
i += 1
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
s = 0
l = a.copy()
for i in range(n):
s = s + a[i]
l.append(s)
k = l[0]
for i in range(1, len(l)):
k = k | l[i]
print(k) | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for i in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
sm = 0
smm = []
for j in a:
sm += j
smm.append(sm)
ans = 0
for k in smm:
ans = ans | k
for k in a:
ans = ans | k
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
def abc(l, n, i, x):
if i == n:
return x
return abc(l, n, i + 1, x) | abc(l, n, i + 1, x + l[i])
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
ans = 0
l.sort()
c = 0
for i in l:
c += i
ans = ans | i
ans = ans | c
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR 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 NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
while t > 0:
t -= 1
n = int(input())
l1 = [int(i) for i in input().split(" ")]
l2 = []
k = 0
for i in l1:
k += i
l2.append(k)
ans = 0
for i in range(n):
ans = ans | l2[i]
ans = ans | l1[i]
print(ans) | 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 VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
arr = [int(c) for c in input().split()]
dp = [(0) for i in range(50)]
for i in range(50):
count = 0
for j in arr:
if j & 1 << i:
count += 1
dp[i] = count + dp[i - 1] // 2
ans = 0
s = sum(arr)
for i in range(50):
if dp[i]:
ans = ans | 1 << i
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
for i in range(t):
n = int(input())
a = [int(x) for x in input().split()]
sum = 0
s = 0
b = []
for i in range(len(a)):
sum += a[i]
b.append(sum)
for i in range(len(b)):
s = s | b[i] | a[i]
print(s) | 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
r = 0
t = 0
for i in range(n):
r = r | a[i]
t += a[i]
r = r | t
print(t | r) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
g = [0] * 75
b = 1
for j in range(n):
b = 1
c = 0
while a[j] > 0:
g[c] = g[c] + a[j] % 2 * b
a[j] = a[j] // 2
c = c + 1
b = b * 2
b = 1
sumo = 0
sum1 = 0
for j in range(75):
sumo = sumo + g[j]
if sumo >= b:
sum1 = sum1 + b
b = b * 2
print(sum1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | def log(a):
c = 0
while a > 0:
a >>= 1
c += 1
return c
def sso(arr, n, brr, l):
for i in range(l):
count = 0
for j in range(n):
if arr[j] >> i & 1 == 1:
count += 1
if i == 0:
brr[0] = count
else:
brr[i] = count + brr[i - 1] // 2
res = 0
for i in range(l):
if brr[i] > 0:
res += 1 << i
return res
t = int(input())
while t > 0:
n = int(input())
arr = list(map(int, input().split()))
s = 0
for i in arr:
s += i
l = log(s)
brr = [0] * l
print(sso(arr, n, brr, l))
t -= 1 | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
num = [0] * 100000
for i in l:
x = bin(i)[2:]
for j in range(len(x)):
num[j] += int(x[-j - 1])
for i in range(100000):
if num[i] > 1:
num[i + 1] += num[i] // 2
num[i] = 1
print(int("0b" + "".join(list(map(str, num[::-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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | I = lambda: list(map(int, input().split()))
(t,) = I()
for _ in range(t):
(n,) = I()
l = I()
an = 0
x = 1
pr = 0
for i in range(57):
ct = 0
for j in range(n):
if x & l[j]:
ct += 1
if ct:
an += x
elif pr >= x:
an += x
pr += ct * x
x *= 2
print(an) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for tc in range(int(input())):
n = int(input())
li = list(map(int, input().strip().split()))
a = [0] * n
a[0] = li[0]
for i in range(1, n):
a[i] = a[i - 1] + li[i]
c = 0
for i in range(n):
c = c | a[i]
c = c | li[i]
print(c) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
p = [l[0]]
for i in l[1:]:
p.append(p[-1] + i)
x = 0
for i in p:
x |= i
for i in l:
x |= i
print(x) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
s = 0
l = list(map(int, input().split()))
ans = l[0]
for i in l:
ans |= i
s += i
ans |= s
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().strip().split()))
s = sum(a)
m = 0
while s > 0:
s >>= 1
m += 1
ans = 0
bits = 0
for i in range(m):
for j in range(n):
if a[j] >> i & 1:
bits += 1
if bits > 0:
ans |= 1 << i
bits >>= 1
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | for _ in range(int(input())):
n = int(input())
A = list(map(int, input().split()))
B = A.copy()
for i in range(1, n):
A[i] = A[i] + A[i - 1]
bitsum = 0
for i in A:
bitsum = bitsum | i
for x in B:
bitsum = bitsum | x
print(bitsum) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | from sys import setrecursionlimit as srl
from sys import stdin as stin
from sys import stdout as stout
def get_ints():
return map(int, stin.readline().split())
def get_list():
return list(map(int, stin.readline().split()))
def get_int():
return int(stin.readline())
def get_str():
return stin.readline()
for _ in range(get_int()):
n = get_int()
nums = get_list()
ans = 0
s = 0
for i in nums:
ans |= i
s += i
ans |= s
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N}$ subsequences and write down the sum of elements of this subsequence, what will the bitwise OR of the written integers be?
Yes, you read it right, but can you solve it?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the bitwise OR of sums of all subsequences.
------ Constraints ------
$1 β€ T β€ 5$
$1 β€ N β€ 10^{5}$
$1 β€ a_{i} < 2^{30}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
2
2
1 1
3
1 9 8
----- Sample Output 1 ------
3
27 | t = int(input())
while t > 0:
n = int(input())
a = list(map(int, input().split()))
s = []
ans = 0
s = 0
for x in a:
s = s + x
ans |= x
ans |= s
print(ans)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess β all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag β her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Π‘artesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 β€ n β€ 24) β the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number β the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0 | xs, ys = map(float, input().split())
n = int(input())
dist = [([0] * (n + 1)) for i in range(n + 1)]
dist2 = [([0] * n) for i in range(n)]
objects = [list(map(float, input().split())) for i in range(n)] + [[xs, ys]]
for i in range(n + 1):
for j in range(n + 1):
dist[i][j] = (objects[i][0] - objects[j][0]) ** 2 + (
objects[i][1] - objects[j][1]
) ** 2
for i in range(n):
for j in range(n):
dist2[i][j] = dist[n][i] + dist[i][j] + dist[j][n]
dp = [1000000.0] * (1 << n)
vis = set([0])
dp[0] = 0
for i in range((1 << n) - 1):
if i in vis:
for j in range(n):
if i & 1 << j == 0:
newi = i + (1 << j)
dp[newi] = min(dp[newi], dp[i] + 2 * dist[n][j])
vis.add(newi)
for k in range(j + 1, n):
if i & 1 << k == 0:
newi |= 1 << k
dp[newi] = min(dp[newi], dp[i] + dist2[j][k])
vis.add(newi)
newi ^= 1 << k
break
curr = (1 << n) - 1
path = [0]
while curr:
for i in range(n):
if curr & 1 << i:
if dp[curr] == dp[curr - (1 << i)] + 2 * dist[n][i]:
path.extend([i + 1, 0])
curr ^= 1 << i
for j in range(i + 1, n):
if curr & 1 << j:
if dp[curr] == dp[curr - (1 << i) - (1 << j)] + dist2[i][j]:
path.extend([j + 1, i + 1, 0])
curr ^= (1 << i) + (1 << j)
print(int(dp[(1 << n) - 1]))
print(*path[::-1]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER WHILE VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess β all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag β her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Π‘artesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 β€ n β€ 24) β the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number β the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0 | x0, y0 = map(int, input().split())
n = int(input())
arr = [[x0, y0]]
for i in range(0, n):
x, y = map(int, input().split())
arr.append([x, y])
dist = [[(0) for j in range(0, n + 1)] for i in range(0, n + 1)]
for i in range(0, n + 1):
for j in range(0, n + 1):
dist[i][j] = (arr[i][0] - arr[j][0]) ** 2 + (arr[i][1] - arr[j][1]) ** 2
def dfs(status, memo, pp):
if memo[status] != None:
return memo[status]
if status < 0:
return 100000000.0
res = 100000000.0
prev = []
for i in range(1, n + 1):
if status & 1 << i - 1 == 0:
continue
t1 = status ^ 1 << i - 1
temp = dfs(t1, memo, pp) + dist[0][i] * 2
if temp < res:
res = temp
prev = [i, 0]
for j in range(i + 1, n + 1):
if j == i:
continue
if t1 & 1 << j - 1 == 0:
continue
next = t1 ^ 1 << j - 1
temp = dfs(next, memo, pp) + dist[0][j] + dist[j][i] + dist[i][0]
if temp < res:
res = temp
prev = [i, j, 0]
break
memo[status] = res
pp[status] = prev
return res
memo = [None for i in range(0, 1 << n)]
pp = [None for i in range(0, 1 << n)]
memo[0] = 0
pp[0] = []
start = 0
end = 0
for i in range(0, n):
end += 1 << i
res = dfs(end, memo, pp)
path = [0]
cur = end
while cur > 0:
prev = pp[cur]
path.extend(prev)
for i in range(len(prev) - 1):
cur -= 1 << prev[i] - 1
print(res)
print(" ".join(map(str, path))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER FUNC_DEF IF VAR VAR NONE RETURN VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess β all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag β her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Π‘artesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
Input
The first line of the input file contains the handbag's coordinates xs, ys. The second line contains number n (1 β€ n β€ 24) β the amount of objects the girl has. The following n lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
Output
In the first line output the only number β the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to n), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Examples
Input
0 0
2
1 1
-1 1
Output
8
0 1 2 0
Input
1 1
3
4 3
3 4
0 0
Output
32
0 1 2 0 3 0 | import sys
def main():
BITS = [(1 << sh) for sh in range(24)]
B2N = {v: u for u, v in enumerate(BITS)}
def getPt():
return tuple(map(int, input().split()))
def dist(ptA, ptB):
return sum((u - v) ** 2 for u, v in zip(ptA, ptB))
def getBits(val):
return tuple(filter(lambda x: x & val, BITS))
def chooseTwo(pool):
n = len(pool)
for i in range(n):
for j in range(i + 1, n):
yield pool[i], pool[j]
ori = getPt()
pts = []
N = int(input())
for _ in range(N):
pts.append(getPt())
vis = set([0])
mint = [0] + [100000000.0] * (1 << N)
pres = [None] * (1 << N)
allb = (1 << N) - 1
B2P = {BITS[u]: v for u, v in enumerate(pts)}
B2P[0] = ori
alld = {u: {v: dist(B2P[u], B2P[v]) for v in B2P} for u in B2P}
getDP = lambda x: mint[x]
newDist = (
lambda stt, p: mint[stt] + alld[p[0]][p[1]] + alld[p[0]][0] + alld[p[1]][0]
)
for stt in range(1 << N):
if stt not in vis:
continue
bits = getBits(~stt & allb)
sb = bits[0] if bits else None
for bit in bits:
newstt = stt | sb | bit
nd = newDist(stt, (sb, bit))
if getDP(newstt) > nd:
mint[newstt] = nd
pres[newstt] = sb | bit
vis.add(newstt)
print(mint[allb])
path = ["0"]
stt = allb
while stt:
bits = getBits(pres[stt])
for bit in bits:
path.append(str(B2N[bit] + 1))
path.append("0")
stt ^= pres[stt]
print(" ".join(path))
main() | IMPORT FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NONE FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST STRING ASSIGN VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | mod = 10**9 + 7
def power(a, b):
if b == 0:
return 1
ax = power(a, int(b / 2))
ax = ax * ax % mod
if b % 2 == 1:
ax = ax * a % mod
return ax
p = int(input())
for _ in range(p):
n = input().split(" ")
n, k = int(n[0]), int(n[1])
m = 0
for i in range(k):
x = input().split()
m = m | int(x[2])
ans = power(2, n - 1)
print(m * ans % mod) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | mod = 1000000007
for _ in range(int(input())):
n, m = list(map(int, input().split()))
y = 0
for i in range(m):
l, r, x = list(map(int, input().split()))
y |= x
t = 0
for i in range(32):
if y & 1 << i:
t += (1 << i) * pow(2, n - 1, mod)
print(t % mod) | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | def power_of_two(base, n):
mod = 1000000007
if n == 1:
return 2
if n == 0:
return 1
if n % 2 == 0:
val = power_of_two(base, n / 2)
return val % mod * (val % mod) % mod
else:
val = 2 * (power_of_two(base, n - 1) % mod) % mod
return val % mod
t = int(input())
for i in range(0, t):
mod = 1000000007
l1 = [int(x) for x in input().split()]
n = l1[0]
m = l1[1]
or_val = 0
for j in range(0, m):
l2 = [int(x) for x in input().split()]
or_val = or_val | l2[2]
powerval = power_of_two(2, n - 1)
ans = powerval % mod * (or_val % mod) % mod
print(ans) | FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | import sys
input = sys.stdin.readline
mod = 10**9 + 7
for _ in " " * int(input()):
n, m = map(int, input().split())
res = 0
for _ in " " * m:
l, r, x = map(int, input().split())
res |= x
print(res * pow(2, n - 1, mod) % mod) | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR BIN_OP STRING VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | t = int(input())
rajawat = 10**9 + 7
for test in range(t):
n, m = map(int, input().split())
temp = 0
for k in range(m):
lks = list(map(int, input().split()))
temp |= lks[-1]
print(temp * 2 ** (n - 1) % rajawat) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | p = int(input())
for _ in range(p):
n = input().split(" ")
n, k = int(n[0]), int(n[1])
m = 0
mod = 10**9 + 7
for i in range(k):
x = input().split()
m = m | int(x[2])
n = n - 1
ans = 1
res = 2
while n > 0:
if n & 1:
ans = ans * res % mod
res = res * res % mod
n = n >> 1
print(m * ans % mod) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | MOD, T = 10**9 + 7, int(input())
for CASE in range(T):
n, m = map(int, input().split())
a = 0
for i in range(m):
l, r, x = map(int, input().split())
a = a | x
print(a * pow(2, n - 1, MOD) % MOD) | ASSIGN VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | M = 10**9 + 7
def xorSum(arr, n):
bits = 0
for i in range(len(arr)):
bits |= arr[i]
ans = bits * pow(2, n - 1)
ans %= M
return ans
for _ in range(int(input())):
n, m = map(int, input().split())
arr = []
for i in range(m):
l, r, val = map(int, input().split())
arr.append(val)
print(xorSum(arr, n)) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | for _ in range(int(input())):
n, m = map(int, input().split(" "))
here = 0
mod = int(1000000000.0 + 7)
for y in range(m):
l, r, x = map(int, input().split(" "))
here |= x
print(pow(2, n - 1, mod) * here % mod) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | t = int(input())
for i in range(t):
n, m = map(int, input().split())
X = 0
for j in range(m):
l, r, x = map(int, input().split())
X |= x
ans = X * 2 ** (n - 1)
print(ans % (10**9 + 7)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | def power(x, MOD):
ans = 1
for i in range(x):
ans = ans * 2 % MOD
return ans
t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
ans = 0
MOD = pow(10, 9) + 7
totalOr = 0
for j in range(k):
a, b, c = [int(x) for x in input().split()]
totalOr = c | totalOr
temp = totalOr * power(n - 1, MOD) % MOD
ans = (ans + temp) % MOD
print(ans) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | I = lambda: [*map(int, input().split())]
M = 10**9 + 7
for _ in [0] * I()[0]:
n, m = I()
o = 0
for i in range(m):
o |= I()[2]
print(o * 2 ** (n - 1) % M) | ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | for iiii in range(int(input())):
n, m = map(int, input().split())
x = 0
for i in range(m):
a, b, c = map(int, input().split())
x = x | c
per = 1000000000 + 7
cou = x % per
for i in range(n - 1):
cou = cou % per * 2 % per
print(cou) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | t = int(input())
while t > 0:
n, m = [int(x) for x in input().split()]
ans = 0
for i in range(m):
ip = [int(x) for x in input().split()]
l = ip[0]
r = ip[1]
x = ip[2]
ans = ans | x
for i in range(n - 1):
ans = ans % 1000000007 * 2 % 1000000007
print(ans % 1000000007)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | t = int(input())
while t:
t -= 1
b = list(map(int, input().split()))
x = 0
for i in range(b[1]):
a = list(map(int, input().split()))
x = x | a[2]
x = x % 1000000007
y = 1
for i in range(b[0] - 1):
y = y * 2 % 1000000007
print(x * y % 1000000007) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | for _ in range(int(input())):
n, m = map(int, input().split())
x = 0
for j in range(m):
l, r, o = map(int, input().split())
x |= o
mod = 1000000007
c = pow(2, n - 1, mod) % mod
c = c % mod * x % mod % mod
print(c) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | import sys
input = sys.stdin.readline
def solve(n, m, Q):
mo = 10**9 + 7
curr = 0
for l, r, x in Q:
curr |= x
print(curr * pow(2, n - 1, mo) % mo)
for _ in range(int(input())):
n, m = map(int, input().split())
Q = [tuple(map(int, input().split())) for _ in range(m)]
solve(n, m, Q) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | def hehe(n):
res = 1
for i in range(n - 1):
res = res * 2 % 1000000007
return res
for _ in range(int(input())):
n, m = map(int, input().split())
l = []
ans = 0
for i in range(m):
temp = list(map(int, input().split()))
l.append(temp)
for i in range(m):
ans = ans | l[i][2]
print(hehe(n) * ans % 1000000007) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | mod = 1000000007
def f():
n, m = map(int, input().split())
s = 0
for i in range(m):
l, r, x = map(int, input().split())
s |= x
return int(s * pow(2, n - 1, mod)) % mod
for _ in range(int(input())):
print(f()) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | for _ in range(int(input())):
n, m = map(int, input().split())
bits = 0
mod = 10**9 + 7
a, b, c = map(int, input().split())
ans = c
for i in range(m - 1):
d, e, f = map(int, input().split())
ans |= f
print(ans % mod * (pow(2, n - 1) % mod) % mod) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | for _ in range(int(input())):
y, [n, m] = 0, map(int, input().split())
for i in range(m):
y |= [int(x) for x in input().split()][2]
print(2 ** (n - 1) * y % (10**9 + 7)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | for _ in range(int(input())):
n, m = map(int, input().split())
xor = 0
for i in range(m):
A = list(map(int, input().split()))
xor = xor | A[2]
ans = 2 ** (n - 1) * xor
print(ans % 1000000007) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | t = int(input())
mod = 1000000007
def power(n):
if n == 1:
return 2
if n == 0:
return 1
ans = power(n // 2)
if n % 2 != 0:
return ans * (ans * 2) % mod % mod
else:
return ans * ans % mod
while t > 0:
n, m = list(map(int, input().split()))
total_or = 0
for i in range(m):
tmp = list(map(int, input().split()))
total_or |= tmp[2]
ans = total_or * power(n - 1) % mod
print(ans)
t = t - 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | mod = 1000000007
def inp():
return list(map(int, input().split()))
_t = int(input())
for _ in range(_t):
n, m = inp()
bit = 0
for i in range(m):
l, r, x = inp()
bit |= x
ans = bit * pow(2, n - 1, mod=mod)
print(ans % mod) | ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | import sys
input = sys.stdin.readline
def inp():
return int(input())
def st():
return input().rstrip("\n")
def lis():
return list(map(int, input().split()))
def ma():
return map(int, input().split())
t = inp()
while t:
t -= 1
n, m = ma()
p = 10**9 + 7
x = 0
for i in range(m):
l, r, x1 = ma()
x = x | x1
x = x * 2 ** (n - 1)
x %= p
print(x) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | mod = 10**9 + 7
for i in range(int(input())):
n, m = list(map(int, input().split()))
fullOr = 0
for i in range(m):
_, _, x = list(map(int, input().split()))
fullOr |= x
print(fullOr * 2 ** (n - 1) % mod) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | for _ in range(int(input())):
n, m = map(int, input().split())
oor = -1
for i in range(m):
l, r, x = map(int, input().split())
if i == 0:
oor = x
else:
oor = oor | x
print(2 ** (n - 1) * oor % (10**9 + 7)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | t = int(input())
for i in range(t):
n, m = map(int, input().split(" "))
l = [(0) for theta in range(m)]
r = [(0) for delta in range(m)]
all_and = 0
for j in range(m):
l[j], r[j], x = map(int, input().split(" "))
all_and = all_and | x
p = 10**9 + 7
all_and = all_and % p
temp = pow(2, n - 1, p)
ans = temp * all_and % p
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | mod = 10**9 + 7
def mpow(a, b):
ans = 1
while b:
if b & 1:
ans = ans * a % mod
a = a * a % mod
b >>= 1
return ans
for _ in range(int(input())):
n, m = map(int, input().split())
a = []
for i in range(m):
a.append([int(x) for x in input().split()])
sm = 0
for i in range(m):
sm |= a[i][2]
ans = mpow(2, n - 1)
ans *= sm
ans %= mod
print(ans) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | for t in range(int(input())):
n, m = list(map(int, input().split()))
l, r, xx = list(map(int, input().split()))
for i in range(m - 1):
l, r, x = list(map(int, input().split()))
xx = xx | x
print(2 ** (n - 1) * xx % 1000000007) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | def input_int():
return int(input())
def input_multiple():
return map(int, input().split())
t = input_int()
while t > 0:
n, m = input_multiple()
or_value = 0
for i in range(m):
l, r, x = input_multiple()
or_value |= x
print(or_value * 2 ** (n - 1) % 1000000007)
t -= 1 | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER |
Once Divan analyzed a sequence $a_1, a_2, \ldots, a_n$ consisting of $n$ non-negative integers as follows. He considered each non-empty subsequence of the sequence $a$, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence $a$.
A sequence $c$ is a subsequence of a sequence $d$ if $c$ can be obtained from $d$ by deletion of several (possibly, zero or all) elements. For example, $[1, \, 2, \, 3, \, 4]$, $[2, \, 4]$, and $[2]$ are subsequences of $[1, \, 2, \, 3, \, 4]$, but $[4, \, 3]$ and $[0]$ are not.
Divan was very proud of his analysis, but now he lost the sequence $a$, and also the coziness value! However, Divan remembers the value of bitwise OR on $m$ contiguous subsegments of the sequence $a$. It turns out that each element of the original sequence is contained in at least one of these $m$ segments.
Divan asks you to help find the coziness of the sequence $a$ using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo $10^9 + 7$.
-----Input-----
The first line contains one integer number $t$ ($1 \le t \le 10^3$) β the number of test cases.
The first line of each test case contains two integer numbers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) β the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following $m$ lines describe the segments, one per line.
Each segment is described with three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $0 \le x \le 2^{30} - 1$) β the first and last elements of the segment and the bitwise OR of $a_l, a_{l + 1}, \ldots, a_r$, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$.
-----Output-----
For each test case print the coziness any suitable sequence $a$ modulo $10^9 + 7$.
-----Examples-----
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
-----Note-----
In first example, one of the sequences that fits the constraints is $[0, 2]$. Consider all its non-empty subsequences:
$[0]$: the bitwise XOR of this subsequence is $0$;
$[2]$: the bitwise XOR of this subsequence is $2$;
$[0, 2]$: the bitwise XOR of this subsequence is $2$.
The sum of all results is $4$, so it is the answer.
In second example, one of the sequences that fits the constraints is $[0, \, 5, \, 5]$.
In third example, one of the sequences that fits the constraints is $[5, \, 6, \, 7, \, 0, \, 2]$. | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, m = list(map(int, input().split()))
xor = 0
mod = 1000000007
def fun(n):
if n == 0:
return 1
if n == 1:
return 2
t = fun(n // 2)
if n % 2 == 0:
return t * t % mod
return t * (t * 2) % mod % mod
for i in range(m):
l = list(map(int, input().split()))
xor |= l[2]
print(fun(n - 1) * xor % mod) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR |
Moamen and Ezzat are playing a game. They create an array $a$ of $n$ non-negative integers where every element is less than $2^k$.
Moamen wins if $a_1 \,\&\, a_2 \,\&\, a_3 \,\&\, \ldots \,\&\, a_n \ge a_1 \oplus a_2 \oplus a_3 \oplus \ldots \oplus a_n$.
Here $\&$ denotes the bitwise AND operation , and $\oplus$ denotes the bitwise XOR operation .
Please calculate the number of winning for Moamen arrays $a$.
As the result may be very large, print the value modulo $1000000\,007$ ($10^9 + 7$).
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 5$)β the number of test cases.
Each test case consists of one line containing two integers $n$ and $k$ ($1 \le n\le 2\cdot 10^5$, $0 \le k \le 2\cdot 10^5$).
-----Output-----
For each test case, print a single value β the number of different arrays that Moamen wins with.
Print the result modulo $1000000\,007$ ($10^9 + 7$).
-----Examples-----
Input
3
3 1
2 1
4 0
Output
5
2
1
-----Note-----
In the first example, $n = 3$, $k = 1$. As a result, all the possible arrays are $[0,0,0]$, $[0,0,1]$, $[0,1,0]$, $[1,0,0]$, $[1,1,0]$, $[0,1,1]$, $[1,0,1]$, and $[1,1,1]$.
Moamen wins in only $5$ of them: $[0,0,0]$, $[1,1,0]$, $[0,1,1]$, $[1,0,1]$, and $[1,1,1]$. | import sys
input = sys.stdin.readline
MAX = 2 * 10**5 + 100
MOD = 10**9 + 7
fact = [0] * MAX
inv = [0] * MAX
finv = [0] * MAX
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def C(n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
for _ in range(int(input())):
n, k = map(int, input().split())
dp = [([0] * 2) for _ in range(k + 1)]
dp[0][0] = 1
coef00 = 0
for i in range(0, n, 2):
coef00 += C(n, i)
coef00 %= MOD
coef01 = 0
for i in range(1, n, 2):
coef01 += C(n, i)
coef01 %= MOD
coef10 = 1 if n % 2 == 0 else 0
coef11 = 1 if n % 2 == 1 else 0
for i in range(k):
dp[i + 1][0] += dp[i][0] * coef00 % MOD
dp[i + 1][0] %= MOD
dp[i + 1][1] += dp[i][1] * coef00 % MOD
dp[i + 1][1] %= MOD
dp[i + 1][1] += dp[i][1] * coef01 % MOD
dp[i + 1][1] %= MOD
dp[i + 1][1] += dp[i][0] * coef10
dp[i + 1][1] %= MOD
dp[i + 1][1] += dp[i][1] * coef10
dp[i + 1][1] %= MOD
dp[i + 1][0] += dp[i][0] * coef11
dp[i + 1][0] %= MOD
dp[i + 1][1] += dp[i][1] * coef11
dp[i + 1][1] %= MOD
print(sum(dp[k]) % MOD) | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.