description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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]$.
P = 10**9 + 7 Q = P - 1 i2 = 1 + P >> 1 T = int(input()) for _ in range(T): n, k = map(int, input().split()) if n % 2: print(pow(pow(2, n - 1, P) + 1, k, P)) else: i2n = pow(i2, n, P) p2n1 = pow(2, n - 1, P) - 1 print( ( pow(2, n * (k - 1) % Q, P) * (1 - pow(p2n1 * i2n, k, P)) % P * pow((1 - p2n1 * i2n) % P, P - 2, P) + pow(p2n1, k, P) ) % P )
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER 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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR 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]$.
mod = 10**9 + 7 for _ in range(int(input())): n, k = map(int, input().split()) total = pow(2, n, mod) h = pow(2, n - 1, mod) if k == 0: print(1) continue if n % 2 == 0: c = 0 t = 1 p = {} prev = 1 for i in range(k + 1): p[i] = prev prev = prev * total % mod for i in range(k): c += t * p[k - i - 1] c %= mod t = t * (h - 1) % mod c += t c %= mod print(c) else: print(pow(h + 1, k, 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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]$.
p = int(1000000000.0 + 7) def sol(n, k): o = n % 2 b = (1 << n - 1) % p tn = (b << 1) % p kn = 1 c = 1 for i in range(1, k + 1): c = (c * b + c) % p if o else (c * b + kn - c) % p kn = kn * tn % p return c for _ in range(int(input())): n, k = map(int, input().split()) print(sol(n, k))
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR 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]$.
def ksm(a, b, c=int(1000000000.0 + 7)): if b == 0: return 1 a = a % c res = 1 while b: if b % 2 == 1: res = res * a % c a = a * a % c b = b // 2 return res p = int(1000000000.0 + 7) mi = [1] for i in range(211111): mi.append(mi[i] * 2 % p) for _ in range(int(input())): n, k = map(int, input().split()) if n % 2 == 1: da = 0 den0 = ksm(2, n - 1) den1 = 1 else: da = 1 den0 = ksm(2, n - 1) - 1 den1 = 0 res = 0 if n % 2 == 0: cz0 = 1 cz1 = ksm(2, n) for i in range(1, k + 1): res = (res + ksm(cz1, k - i) * cz0) % p cz0 = cz0 * den0 % p res = (res + ksm(den1 + den0, k)) % p if k == 0: print(1) else: print(res)
FUNC_DEF FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER 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 RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL 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 rem = 1000000007 for _ in range(int(input())): n, k = map(int, input().split()) ans = 0 if k == 0: print(1) elif n % 2 == 0: dp = [0] * k dp[0] = pow(2, n - 1, rem) xx = pow(2, n - 1, rem) - 1 yy = pow(2, n, rem) for i in range(1, k): dp[i] = (dp[i - 1] * xx % rem + pow(yy, i, rem)) % rem print(dp[-1]) else: dp = [0] * k dp[0] = (pow(2, n - 1, rem) + 1) % rem xx = pow(2, n - 1, rem) + 1 for i in range(1, k): dp[i] = dp[i - 1] * xx % rem print(dp[-1])
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
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]$.
def powmod(b, e, n): accum = 1 i = 0 bpow2 = b while e >> i > 0: if e >> i & 1: accum = accum * bpow2 % n bpow2 = bpow2 * bpow2 % n i += 1 return accum def memoize(function): cache = {} def decorated_function(*args): try: return cache[args] except KeyError: val = function(*args) cache[args] = val return val return decorated_function @memoize def inverseMod(n, mod): if 1 == n: return 1 return (mod - mod // n) * inverseMod(mod % n, mod) % mod M = 10**9 + 7 F = [1, 1] for n in range(2, 2 * 10**5 + 1): F.append(F[-1] * n % M) RF = [1, 1] for n in range(2, 2 * 10**5 + 1): RF.append(RF[-1] * inverseMod(n, M) % M) def C(n, k): return F[n] * (RF[n - k] * RF[k] % M) % M def count(n, k): if k == 0: return 1 if n == 1: return powmod(2, k, M) r0 = powmod(2, n - 1, M) + (1 if n % 2 == 1 else 0) - 1 r = 1 + r0 b = powmod(2, n, M) bn = b for e in range(2, k + 1): if n % 2 == 0: r = r0 * r % M + bn bn = bn * b % M else: r = r + r0 * r % M r %= M return r % M T = int(input()) for _ in range(T): n, k = map(int, input().split(" ")) print(count(n, k))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT FUNC_DEF RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF NUMBER VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR 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]$.
mod = 10**9 + 7 powers = [1] for i in range(1, 200000 + 1): powers.append(powers[-1] * 2 % mod) for nt in range(int(input())): n, k = map(int, input().split()) add = [1] for i in range(k): add.append(add[-1] * powers[n] % mod) if n % 2: ans = pow(2, n * k, mod) for i in range(k): ans -= ( pow(powers[n - 1] + 1, i, mod) * (powers[n - 1] - 1) % mod * add[k - i - 1] % mod ) ans = ans % mod print(ans) else: ans = pow(2, n * k, mod) for i in range(k): ans -= ( pow(powers[n - 1] - 1, i, mod) * powers[n - 1] % mod * add[k - i - 1] % mod ) ans = ans % mod print(ans)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL 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 MOD = 10**9 + 7 def main(): n, k = map(int, input().split()) if k == 0: print(1) return if n == 1: print(pow(2, k, MOD)) return if n % 2 == 1: print(pow(pow(2, n - 1, MOD) + 1, k, MOD)) else: ans = pow(pow(2, n - 1, MOD) - 1, k, MOD) for i in range(k): ans += pow(pow(2, n - 1, MOD) - 1, i, MOD) * pow( pow(2, n, MOD), k - 1 - i, MOD ) ans %= MOD print(ans) for _ in range(int(input())): main()
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR RETURN IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL 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]$.
t = int(input()) for i in range(t): [n, k] = [int(x) for x in input().split()] p = 10**9 + 7 pow2 = pow(2, n - 1, p) prev = 1 if n % 2 == 0: prev = pow2 else: prev = pow2 + 1 z = 1 mu = 2 * pow2 % p for h in range(2, k + 1): z = z * mu % p if n % 2 == 0: prev = (z + (pow2 - 1) * prev % p) % p else: prev = (pow2 + 1) * prev % p if k == 0: print(1) else: print(prev % p)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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]$.
mod = 10**9 + 7 def odd(k): if k == 0: return 1 else: oddd = [(1) for _ in range(k + 1)] for a in range(k, 0, -1): if a == k: oddd[a] = (tno + 1) % mod else: oddd[a] = (tno + 1) * oddd[a + 1] % mod return oddd[1] def even(k): if k == 0: return 1 else: eveen = [(1) for _ in range(k + 1)] for a in range(k, 0, -1): if a == k: eveen[a] = tno else: eveen[a] = (tro[a] + (tno - 1) * eveen[a + 1]) % mod return eveen[1] for _ in range(int(input())): n, k = map(int, input().split()) tno = 2 ** (n - 1) % mod tnt = 2 * tno % mod tro = [(0) for _ in range(k + 1)] pip = 1 for a in range(k, 0, -1): tro[a] = pip pip = pip * tnt % mod if n % 2 != 0: print(odd(k)) else: print(even(k))
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR NUMBER 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 BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL 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]$.
t = int(input()) modval = int(1000000000.0 + 7) for _ in range(t): n, k = [int(x) for x in input().split(" ")] if not k: print("1") continue dp = [(1) for _ in range(k + 1)] ndigsequal = pow(2, n - 1, modval) allopts = pow(2, n, modval) st = 1 if n & 1: isodd = True ndigsequal += 1 else: isodd = False ndigsequal -= 1 for i in range(1, k + 1): ans = ndigsequal * dp[i - 1] ans %= modval if not isodd: ans += st ans %= modval st *= allopts st %= modval dp[i] = ans print(dp[k])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR 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]$.
MOD = 10**9 + 7 for _ in range(int(input())): n, k = map(int, input().split()) ans = 1 if n % 2: ans = pow(1 + 2 ** (n - 1), k, MOD) else: for i in range(k): ans = (pow(2, n - 1, MOD) - 1) * ans ans %= MOD ans += pow(pow(2, i, MOD), n, MOD) ans %= MOD print(ans)
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL 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]$.
real_ans = 0 def abc(x, n, k): global real_ans if len(x) == n: a = x[0] b = x[0] for j in x[1:]: a &= j b ^= j if a >= b: real_ans += 1 return for j in range(2**k): abc(x + [j], n, k) mod = 10**9 + 7 e = 2 * 10**5 + 1 fact = [1] * e for j in range(1, e): fact[j] = j * fact[j - 1] % mod def ncr(a, b): if a <= 0 or a < b: return 0 x = fact[a] y = pow(fact[b] * fact[a - b], mod - 2, mod) return x * y % mod t = int(input()) for _ in range(t): n, k = map(int, input().split()) if k == 0: print(1) else: b = pow(2, n - 1, mod) d = 1 e = pow(2, n, mod) ans = 1 for j in range(k): y = ans if n % 2: ans = (ans + y) % mod else: ans = (ans + d) % mod ans = (ans + b * y - y - y * (1 if n % 2 == 0 else 0)) % mod d = d * e % mod print(ans % mod)
ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR VAR 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR 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 BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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]$.
for _ in range(int(input())): n, k = map(int, input().split()) m = 10**9 + 7 if k == 0: print(1) continue if n % 2 == 0: dp = [(0) for i in range(k)] dp[0] = pow(2, n - 1, m) c = pow(2, n, m) for i in range(1, k): dp[i] = (pow(c, i, m) + dp[i - 1] * (pow(2, n - 1, m) - 1) % m) % m print(dp[-1]) else: q = (pow(2, n - 1, m) + 1) % m print(pow(q, k, m))
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 BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR 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]$.
mod = 10**9 + 7 def modDivide(a, b, m): inv = pow(b, m - 2, m) return inv * a % m for _ in range(int(input())): n, k = map(int, input().split()) if k == 0: print(1) continue if n % 2 == 1: print(pow(1 + pow(2, n - 1, mod), k, mod)) else: t = pow(pow(2, n - 1, mod) - 1, k, mod) a = pow(2, n * k, mod) b = (pow(2, n - 1, mod) + 1) % mod a = modDivide((a - t + mod) % mod, b, mod) t = (t + a) % mod print(t)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL 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]$.
mod = int(1000000000.0 + 7) t = int(input()) for _ in range(t): n, k = [int(i) for i in input().split()] if n & 1: print(pow(pow(2, n - 1) + 1, k, mod)) else: equal = pow(pow(2, n - 1, mod) - 1, k, mod) al = pow(2, n * k, mod) - equal al *= pow(pow(2, n - 1, mod) + 1, mod - 2, mod) al += equal al %= mod print(al)
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER 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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL 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]$.
M = 10**9 + 7 def mul(a, b): a %= M b %= M - 1 k = 1 s = bin(b)[2:] for x in s: k = k * k % M if x == "1": k = k * a % M return k def sex(n, k): if k == 0: return 1 p = mul(2, n - 1) if n % 2 == 1: return mul(p + 1, k) x = [0] * (k + 1) x[0] = 1 for i in range(1, k + 1): x[i] = (p - 1) * x[i - 1] + mul(2 * p, i - 1) x[i] %= M return x[k] t = int(input()) for _ in range(t): n, k = map(int, input().split()) print(sex(n, k))
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR 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]$.
MOD = 1000000007 def power(a, n): res = 1 while n > 0: if n & 1: res = res * a % MOD a = a * a % MOD n >>= 1 return res for _ in range(int(input())): n, k = map(int, input().split()) if k == 0: print(1) continue poww = power(2, n - 1) if n % 2: print(power(poww + 1, k) % MOD) else: ans = poww y = poww * 2 poww -= 1 for i in range(1, k): ans = (ans * poww % MOD + y % MOD) % MOD y = 2 * y * (poww + 1) % MOD print(ans)
ASSIGN VAR NUMBER FUNC_DEF 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 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL 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]$.
def func(): t = int(input().strip()) cases = [] for _ in range(t): n, k = map(int, input().strip().split()) cases.append((n, k)) for case in cases: n, k = case print(and_xor(n, k)) def and_xor(n, k): mod = 1000000007 if n % 2: ans = pow(2, n - 1, mod) + 1 return pow(ans, k, mod) if k == 0: return 1 tmp = pow(2, n - 1, mod) - 1 ans = tmp + 1 res = cnt = pow(2, n, mod) for i in range(1, k): ans = (ans * tmp % mod + res) % mod res = res * cnt % mod ans %= mod return ans func()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL 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 readline = sys.stdin.readline M = 10**9 + 7 def bin_exp(num, k): ans = 1 num %= M while k > 0: if k % 2 == 1: ans *= num ans %= M num *= num num %= M k //= 2 return ans t = int(readline()) for _ in range(t): n, k = map(int, readline().split()) if k == 0: print(1) continue two_n_1 = bin_exp(2, n - 1) if n % 2 == 1: two_n_1 = (two_n_1 + 1) % M print(bin_exp(two_n_1, k) % M) else: dp = [0] * k dp[0] = two_n_1 two_n = 2 * two_n_1 % M two_n_1 -= 1 if two_n_1 < 0: two_n_1 += M two_n_k = 1 for i in range(1, k): dp[i] = dp[i - 1] * two_n_1 % M two_n_k *= two_n two_n_k %= M dp[i] += two_n_k dp[i] %= M print(dp[k - 1] % M)
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER 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]$.
KMAX, NMAX, MOD = 2 * 10**5, 2 * 10**5, 10**9 + 7 powers = [1] * (NMAX + 1) for j in range(1, NMAX + 1): powers[j] = 2 * powers[j - 1] % MOD t = int(input()) for _ in range(t): n, k = (int(x) for x in input().split()) if k: npowers = [1] * (k + 1) for j in range(1, k + 1): npowers[j] = npowers[j - 1] * powers[n] % MOD ways = [0] * k ways[0] = (powers[n - 1] + n % 2) % MOD for j in range(1, k): if n % 2 == 0: ways[j] = (powers[n - 1] - 1) * ways[j - 1] % MOD ways[j] = (ways[j] + npowers[j]) % MOD else: ways[j] = (powers[n - 1] + 1) * ways[j - 1] % MOD print(ways[-1]) else: print(1)
ASSIGN VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER 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 IF VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
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]$.
from sys import stdin, stdout m = 1000000007 twotothe = [1] facts = [1] for i in range(1, 200001): facts.append(facts[-1] * i % m) twotothe.append(twotothe[-1] * 2 % m) invnums = [0] * 200001 invfacts = [0] * 200001 invnums[0] = 1 invnums[1] = 1 for i in range(2, 200001): invnums[i] = invnums[m % i] * (m - m // i) % m invfacts[0] = 1 invfacts[1] = 1 for i in range(2, 200001): invfacts[i] = invnums[i] * invfacts[i - 1] % m def comb(n, r): return facts[n] * invfacts[n - r] * invfacts[r] % m for _ in range(int(stdin.readline())): n, k = map(int, stdin.readline().split()) if k == 0: stdout.write("1\n") continue sm = sum(comb(n, r) for r in range(0, n, 2)) % m if n & 1: stdout.write(str(pow(sm + 1, k, m)) + "\n") continue ans = 1 last = 1 for i in range(k): ans = (last + sm * ans) % m last = last * twotothe[n] % m stdout.write(str(ans) + "\n")
ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR 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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
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 def comb(n, r, mod): if r < 0 or r > n: return 0 return g1[n] * g2[r] * g2[n - r] % mod mod = 10**9 + 7 N = 2 * 10**5 + 1 g1 = [1, 1] g2 = [1, 1] inv = [0, 1] for i in range(2, N + 1): g1.append(g1[-1] * i % mod) inv.append(-inv[mod % i] * (mod // i) % mod) g2.append(g2[-1] * inv[-1] % mod) t = int(input()) for _ in range(t): n, k = map(int, input().split()) dp = [([0] * 2) for i in range(k + 1)] dp[0][0] = 1 p2 = pow(2, n, mod) s = 0 for j in range(0, n, 2): s += comb(n, j, mod) s %= mod if n % 2: s += 1 for i in range(1, k + 1): if n % 2 == 0: dp[i][1] = (dp[i - 1][1] * p2 + dp[i - 1][0]) % mod else: dp[i][1] += dp[i - 1][1] * p2 % mod dp[i][0] = dp[i - 1][0] * s % mod print(sum(dp[k]) % mod)
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR 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 BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR 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 = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(2 * 10**5 + 10) write = lambda x: sys.stdout.write(x + "\n") debug = lambda x: sys.stderr.write(x + "\n") writef = lambda x: print("{:.12f}".format(x)) M = 10**9 + 7 N = 2 * 10**5 + 10 g1 = [0] * (N + 1) g2 = [0] * (N + 1) inverse = [0] * (N + 1) g1[0] = g1[1] = g2[0] = g2[1] = 1 inverse[0], inverse[1] = [0, 1] for i in range(2, N + 1): g1[i] = g1[i - 1] * i % M inverse[i] = -inverse[M % i] * (M // i) % M g2[i] = g2[i - 1] * inverse[i] % M def cmb(n, r, M=M): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] % M * g2[n - r] % M def perm(n, r, M=M): if r < 0 or r > n: return 0 return g1[n] * g2[n - r] % M def sub(n, k): ans = 0 for v in range(1 << k): for v2 in range(1 << k): if v & v2 >= v ^ v2: ans += 1 return ans def sub3(n, k): ans = 0 for v in range(1 << k): for v2 in range(1 << k): for v3 in range(1 << k): if v & v2 & v3 >= v ^ v2 ^ v3: ans += 1 return ans def sub2(n, k): val = 0 for i in range(0, n + 1, 2): val += cmb(n, i) if val > M: val -= M if k == 0: ans = 1 elif n % 2 == 1: ans = pow(1 + val, k, M) else: ans = 0 v = 1 v2 = pow(2, n * (k - 1), M) inv = pow(pow(2, n, M), M - 2, M) for i in range(k): ans += v * v2 % M v *= val - 1 v %= M v2 *= inv v2 %= M if ans > M: ans -= M ans += pow(val - 1, k, M) return ans t = int(input()) res = [] for _ in range(t): n, k = list(map(int, input().split())) ans = sub2(n, k) res.append(ans % M) write("\n".join(map(str, res)))
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR 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 VAR IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_DEF VAR IF VAR NUMBER VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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 pri = pow(10, 9) + 7 input = sys.stdin.readline a = int(input()) for i in range(a): n, k = map(int, input().split()) g1 = pow(2, n, pri) g2 = pow(2, n, pri) if k == 0: print(1) continue ans = [(0) for i in range(k)] if n % 2 == 0: ways = pow(2, n - 1, pri) else: ways = pow(2, n - 1, pri) ways += 1 ans[0] = ways for i in range(1, k): if n % 2 == 0: ways = pow(2, n - 1, pri) else: ways = pow(2, n - 1, pri) ways += 1 ways %= pri if n % 2 == 0: ans[i] = ans[i - 1] * (ways - 1) % pri ans[i] += g2 ans[i] %= pri g2 = g2 * g1 g2 %= pri else: ans[i] = ans[i - 1] * ways ans[i] %= pri print(ans[-1])
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR 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 FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
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]$.
MOD = 10**9 + 7 def f(n, k): good = n - 1 & 1 maybe = (pow(2, n - 1, MOD) + 1 - 2 * good) % MOD all_ = pow(2, n, MOD) return ( good * (pow(all_, k, MOD) - pow(maybe, k, MOD)) * pow(all_ - maybe, MOD - 2, MOD) + pow(maybe, k, MOD) ) % MOD t = int(input()) for _ in range(t): n, k = map(int, input().split()) print(f(n, k))
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR 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]$.
p = 10**9 + 7 def power(x, y, p): b = bin(y)[2:] start = x % p answer = 1 for i in range(len(b)): if b[len(b) - 1 - i] == "1": answer = answer * start % p start = start * start % p return answer def invert(x, p): return power(x, p - 2, p) def process(n, k): a1 = power(2, n * k, p) if n % 2 == 0: a2 = power(2, n - 1, p) % p a3 = (a2 - 1) % p R = (invert(2, p) - invert(power(2, n, p), p)) % p num1 = (power(R, k + 1, p) - R) % p den1 = (R - 1) % p num = a2 * a1 * num1 % p den = a3 * den1 % p entry = num * invert(den, p) % p return (a1 - entry) % p else: a2 = (power(2, n - 1, p) - 1) % p a3 = (a2 + 2) % p R = (invert(2, p) + invert(power(2, n, p), p)) % p num1 = (power(R, k + 1, p) - R) % p den1 = (R - 1) % p num = a2 * a1 * num1 % p den = a3 * den1 % p entry = num * invert(den, p) % p return (a1 - entry) % p t = int(input()) for i in range(t): n, k = [int(x) for x in input().split()] print(process(n, k))
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR 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]$.
for s in [*open(0)][1:]: M = 10**9 + 7 P = pow n, k = map(int, s.split()) p = P(2, n - 1, M) print( [(P(2 * p, k, M) + p * P(~-p, k, M)) * P(p + 1, -1, M) % M, P(p + 1, k, M)][ n & 1 ] )
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER
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]$.
t = int(input()) mod = 1000000007 for i in range(t): n, k = map(int, input().split()) K = pow(2, n - 1, mod) if n & 1: ans = pow(K + 1, k, mod) else: R = pow(K + 1, mod - 2, mod) s = (pow(2, n * k, mod) - pow(K - 1, k, mod)) % mod * R % mod s += pow(K - 1, k, mod) ans = s % mod print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL 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]$.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) tmp1 = 2 ** (n - 1) % 1000000007 tmp2 = 1 ans = 0 if k == 0: ans = 1 elif k >= 1: if n % 2 == 0: ans = 2 ** (n - 1) % 1000000007 else: ans = (2 ** (n - 1) + 1) % 1000000007 for i in range(2, k + 1): tmp2 = tmp2 * tmp1 * 2 % 1000000007 if n % 2 == 0: ans = (tmp2 + (tmp1 - 1) * ans) % 1000000007 else: ans = (tmp1 + 1) * ans % 1000000007 if n == 1: ans = 2**k % 1000000007 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 ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL 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]$.
T = int(input()) for _ in range(T): n, k = map(int, input().split()) p = 10**9 + 7 if n & 1 == 1: answer = pow(pow(2, n - 1, p) + 1, k, p) else: answer = 1 pow_ = 1 _2_n_1 = pow(2, n - 1, p) for i in range(k): answer = answer * (_2_n_1 - 1) % p answer = (answer + pow_) % p pow_ = pow_ * _2_n_1 * 2 % p print(answer)
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 BIN_OP BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL 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]$.
MOD = 1000000007 def solve(n, k): if n % 2: ks = pow(2, n - 1, MOD) + 1 return pow(ks, k, MOD) else: ks = pow(2, n - 1, MOD) - 1 if k == 0: return 1 else: ans = 1 + ks cg = pow(2, n, MOD) binn = cg for i in range(1, k): ans = (ans * ks % MOD + binn) % MOD binn = binn * cg % MOD ans %= MOD return ans t = int(input()) for alskfjlakfja in range(t): n, k = [int(i) for i in input().split()] print(solve(n, k))
ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR 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]$.
inf = float("inf") mod = 10**9 + 7 def get_list(): return [int(i) for i in input().split()] def yn(a): print("YES" if a else "NO") ceil = lambda a, b: (a + b - 1) // b t = int(input()) for i in range(t): n, k = [int(i) for i in input().split()] dp = [(1) for i in range(k + 1)] muleven = pow(2, n - 1, mod) twon = pow(2, n, mod) mulodd = pow(2, n - 1, mod) + 1 if n % 2 == 0: for i in range(1, k + 1): dp[i] = dp[i - 1] * (muleven - 1) % mod dp[i] = (pow(twon, i - 1, mod) + dp[i]) % mod print(dp[-1]) else: for i in range(1, k + 1): dp[i] = dp[i - 1] * mulodd % mod print(dp[-1])
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER 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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
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 def solve(): n, k = map(int, input().split()) m = 10**9 + 7 val = pow(2, n - 1, m) if n % 2: val += 1 val %= m return pow(val, k, m) else: R = pow(val + 1, m - 2, m) ans = (pow(2, n * k, m) - pow(val - 1, k, m)) % m * R % m ans += pow(val - 1, k, m) ans %= m return ans for _ in range(int(input())): print(solve())
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL 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]$.
t = int(input()) pow2 = [(1) for x in range(2 * 100000 + 1)] mod = 10**9 + 7 for i in range(1, 200000 + 1): pow2[i] = pow2[i - 1] * 2 pow2[i] %= mod def solve(k, n): if k == 0: return 1 if dp[k] != -1: return dp[k] if n % 2 == 0: ans = pow22[k - 1] - solve(k - 1, n) ans += solve(k - 1, n) * pow2[n - 1] ans %= mod else: ans = solve(k - 1, n) ans += solve(k - 1, n) * pow2[n - 1] ans %= mod dp[k] = ans return ans while t: t -= 1 n, k = [int(x) for x in input().split()] pow22 = [(1) for x in range(k + 1)] for i in range(1, k + 1): pow22[i] = pow22[i - 1] * pow2[n] pow22[i] %= mod if k == 0: print(1) continue dp = [(-1) for x in range(k + 1)] for i in range(1, k): solve(i, n) print(solve(k, n))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR RETURN VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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]$.
t = int(input()) def tavan(a, b): global div nat = 1 for i in range(b): nat = nat * a % div return nat % div for i in range(t): n, k = list(map(int, input().split())) div = 1000000007 two = pow(2, n - 1, div) if n % 2 == 1: print(pow(two + 1, k, div)) else: two1 = pow(two - 1, k, div) nat = two1 for i in range(k): nat = ( nat + pow(two - 1, i, div) * pow(two * 2, k - i - 1, div) % div ) % div print(nat % div)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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]$.
MODULO = 1000000007 def calc(n, k): K = pow(2, n - 1, MODULO) if n & 1: return pow(K + 1, k, MODULO) else: R = pow(K + 1, MODULO - 2, MODULO) s = (pow(2, n * k, MODULO) - pow(K - 1, k, MODULO)) % MODULO * R % MODULO s += pow(K - 1, k, MODULO) return s % MODULO for i in range(int(input())): n, k = input().split() print(calc(int(n), int(k)))
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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]$.
mod = 1000000007 T = int(input()) fpow = pow for i in range(T): ans = 1 n, k = map(int, input().split()) if n % 2 != 0: ans = fpow(2, n - 1, mod) + 1 ans = fpow(ans, k, mod) else: ans = 1 pow_ = 1 _2_n_1 = pow(2, n - 1, mod) for i in range(k): ans = ans * (_2_n_1 - 1) % mod ans = (ans + pow_) % mod pow_ = pow_ * _2_n_1 * 2 % mod print(ans)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL 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]$.
MOD = 10**9 + 7 for _ in range(int(input())): n, k = map(int, input().split()) COEFF_WINS = 2**n % MOD COEFF_Q = 2 ** (n - 1) % MOD wins = 0 q = 1 for i in range(k): wins *= COEFF_WINS wins %= MOD if n % 2 == 0: wins += q q *= COEFF_Q - 1 else: q *= COEFF_Q + 1 q %= MOD wins += q print(wins % 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP 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]$.
M = 1000000007 def solve(n, k): if k == 0: return 1 p = pow(2, n - 1, M) q = pow(2, n, M) if n % 2 == 0: p -= 1 d0 = 0 d1 = 0 for i in range(k): if i == 0: d0 = p d1 = 1 else: d1 = (d1 * q + d0) % M d0 = d0 * p % M return (d0 + d1) % M else: return pow(p + 1, k, M) t = int(input()) for i in range(t): n, k = map(int, input().split()) print(solve(n, k))
ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR 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 INF = int(1000000000.0) + 7 def power(x, y): if y == 0: return 1 semi_result = power(x, y // 2) % INF if y % 2 == 0: return semi_result * semi_result % INF else: return x * semi_result * semi_result % INF for _ in range(int(input())): n, k = map(int, input().split()) dp = [1] * (k + 1) g = power(2, n - 1) a = g * 2 % INF cache = [1] * (k + 1) for i in range(2, k + 1): cache[i] = cache[i - 1] * a % INF for i in range(1, k + 1): if n % 2 == 0: dp[i] = (cache[i] + dp[i - 1] * (g - 1)) % INF else: dp[i] = (dp[i - 1] + g * dp[i - 1]) % INF print(dp[k])
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP 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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR 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 mod = 10**9 + 7 for _ in range(int(input())): n, k = map(int, input().split()) ans = 0 x = pow(2, n - 1, mod) if n % 2: ans = pow(x + 1, k, mod) print(ans) else: cur = 1 for i in range(k): r = k - i - 1 ans += pow(pow(2, r, mod), n, mod) * cur % mod ans %= mod cur = cur * (x - 1) % mod print((ans + cur) % mod)
IMPORT ASSIGN VAR VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR 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]$.
MOD = 10**9 + 7 t = int(input()) for _ in range(t): N, k = map(int, input().split()) x = pow(2, N - 1, MOD) y = pow(2, N, MOD) if N % 2 == 1: print(pow(x + 1, k, MOD)) else: res = pow(x - 1, k, MOD) for i in range(k): res = (res + pow(x - 1, i, MOD) * 1 * pow(y, k - i - 1, MOD)) % MOD print(res)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL 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]$.
def power(base, num): bin_num = bin(num)[2:] store = [base] for _ in range(len(bin_num) - 1): store.append(store[-1] ** 2 % (10**9 + 7)) curr = 1 for idx, ch in enumerate(bin_num[::-1]): if ch == "1": curr = curr * store[idx] % (10**9 + 7) return curr t = int(input()) for i in range(1, t + 1): n, k = list(map(int, input().split())) if k == 0: print(1) else: if n % 2 == 0: perm = power(2, n - 1) - 1 perf = power(2, n) else: perm = power(2, n - 1) + 1 res = 1 if n % 2 == 1: print(power(perm, k)) else: curr = 1 curr_perf = 1 for i in range(k): curr = curr * perm + curr_perf curr_perf *= perf curr = curr % (10**9 + 7) curr_perf = curr_perf % (10**9 + 7) print(curr)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL 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 for _ in range(int(input())): n, k = map(int, input().split()) m, ans = 10**9 + 7, 1 if n % 2: ans = pow(pow(2, n - 1, m) + 1, k, m) else: for i in range(k): ans = pow(pow(2, i, m), n, m) + (pow(2, n - 1, m) - 1) * ans ans %= m print(ans)
IMPORT ASSIGN 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 VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL 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 def main(): MOD = 10**9 + 7 t = int(input()) for _ in range(t): N, K = [int(x) for x in input().split()] ans = 0 if N % 2 == 1: ans += pow(pow(2, N - 1, MOD) + 1, K, MOD) print(ans) continue for i in range(K): ans += pow(pow(2, N - 1, MOD) - 1, i, MOD) * pow( pow(2, N, MOD), K - i - 1, MOD ) ans %= MOD ans += pow(pow(2, N - 1, MOD) - 1, K, MOD) ans %= MOD print(ans % MOD) main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for tc in range(int(input())): n, x = map(int, input().split()) arr = list(map(int, input().split())) globsame, globdiff = 0, 0 for i in range(1, n): same = max( globsame + (arr[i] ^ arr[i - 1]), globdiff + (arr[i] ^ arr[i - 1] + x) ) diff = max( globsame + (arr[i] + x ^ arr[i - 1]), globdiff + (arr[i] + x ^ arr[i - 1] + x), ) globsame = max(same, globsame) globdiff = max(diff, globdiff) print(max(globsame, globdiff))
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 ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): a, b = map(int, input().split()) aa = [([0] * 2) for i in range(a)] dp = list(map(int, input().split())) for i in range(1, a): aa[i][0] = max( aa[i - 1][0] + (dp[i - 1] ^ dp[i]), aa[i - 1][1] + (dp[i - 1] + b ^ dp[i]) ) aa[i][1] = max( aa[i - 1][0] + (dp[i - 1] ^ dp[i] + b), aa[i - 1][1] + (dp[i - 1] + b ^ dp[i] + b), ) print(max(aa[-1][0], aa[-1][1]))
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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
T = int(input()) for _ in range(T): N, X = map(int, input().split()) flag = 200001 check = 1 bool = True arr = list(map(int, input().split())) Bool = False dp = [[0, 0] for i in range(N)] for i in range(1, N): flag += check check ^= flag dp[i][0] = max( dp[i - 1][0] + (arr[i - 1] ^ arr[i]), dp[i - 1][1] + (arr[i - 1] + X ^ arr[i]), ) check -= flag dp[i][1] = max( dp[i - 1][0] + (arr[i - 1] ^ arr[i] + X), dp[i - 1][1] + (arr[i - 1] + X ^ arr[i] + X), ) bool = False Bool = True print(str(max(dp[N - 1][0], dp[N - 1][1])))
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
def rec(i, A, X, N, prev): if i == 0: return 0 if i == N: return max(rec(i - 1, A, X, N, 1), rec(i - 1, A, X, N, 0)) if prev == 1: return max( (A[i - 1] + X ^ A[i] + X) + rec(i - 1, A, X, N, 1), (A[i - 1] ^ A[i] + X) + rec(i - 1, A, X, N, 0), ) else: return max( (A[i - 1] + X ^ A[i]) + rec(i - 1, A, X, N, 1), (A[i - 1] ^ A[i]) + rec(i - 1, A, X, N, 0), ) T = int(input()) for _ in range(T): N, X = map(int, input().split()) A = list(map(int, input().split())) dp = [[(-1) for j in range(2)] for i in range(N + 1)] for j in range(2): dp[0][j] = 0 for i in range(1, N + 1): for j in range(2): if i == N: dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]) elif j == 0: dp[i][j] = max( (A[i - 1] + X ^ A[i]) + dp[i - 1][1], (A[i - 1] ^ A[i]) + dp[i - 1][0], ) else: dp[i][j] = max( (A[i - 1] + X ^ A[i] + X) + dp[i - 1][1], (A[i - 1] ^ A[i] + X) + dp[i - 1][0], ) print(max(dp[N]))
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
T = int(input()) for t in range(0, T): N, X = map(int, input().split()) arr = list(map(int, input().split())) dp1 = [(0) for i in range(0, N)] dp2 = [(0) for i in range(0, N)] for i in range(1, N): dp1[i] = max( dp1[i - 1] + (arr[i - 1] ^ arr[i]), dp2[i - 1] + (arr[i - 1] + X ^ arr[i]) ) dp2[i] = max( dp1[i - 1] + (arr[i - 1] ^ arr[i] + X), dp2[i - 1] + (arr[i - 1] + X ^ arr[i] + X), ) ans = max(dp1[N - 1], dp2[N - 1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, x = map(int, input().split()) inputArray = list(map(int, input().split())) dynamic = [[(0) for i in range(2)] for j in range(n)] for i in range(1, n): [prev0, prev1] = dynamic[i - 1] p0, p1 = inputArray[i], inputArray[i - 1] dynamic[i][1] = max(prev0 + (p1 ^ p0 + x), prev1 + (p1 + x ^ p0 + x)) dynamic[i][0] = max(prev0 + (p1 ^ p0), prev1 + (p1 + x ^ p0)) print(max(dynamic[n - 1][0], dynamic[n - 1][1]))
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN LIST VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
T = int(input()) for tr in range(T): N, X = map(int, input().split(" ")) A = list(map(int, input().split(" "))) dp = [[-1, -1] for i in range(N)] for i in range(N): if i == 0: dp[0][0] = 0 dp[0][1] = 0 else: dp[i][1] = max( int(A[i] + X ^ A[i - 1]) + dp[i - 1][0], int(A[i] + X ^ A[i - 1] + X) + dp[i - 1][1], ) dp[i][0] = max( int(A[i] ^ A[i - 1]) + dp[i - 1][0], int(A[i] ^ A[i - 1] + X) + dp[i - 1][1], ) print(max(dp[N - 1][0], dp[N - 1][1]))
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, x = map(int, input().split()) a = list(map(int, input().split())) if n > 1: prevdp0 = prevdp1 = 0 for i in range(n - 1): dp0 = max(prevdp0 + (a[i] ^ a[i + 1]), prevdp1 + (a[i] + x ^ a[i + 1])) dp1 = max( prevdp0 + (a[i] ^ a[i + 1] + x), prevdp1 + (a[i] + x ^ a[i + 1] + x) ) prevdp0, prevdp1 = dp0, dp1 print(max(dp0, dp1)) else: print(0)
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 IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
T = int(input()) for t in range(T): n, x = map(int, input().split()) l = list(map(int, input().split())) l.insert(0, 0) mat = [] for i in range(n + 1): q = [0] * 2 mat.append(q) for i in range(2, n + 1): mat[i][0] = max( mat[i - 1][0] + (l[i - 1] ^ l[i]), mat[i - 1][1] + (l[i - 1] + x ^ l[i]) ) mat[i][1] = max( mat[i - 1][0] + (l[i - 1] ^ l[i] + x), mat[i - 1][1] + (l[i - 1] + x ^ l[i] + x), ) print(max(mat[n][0], mat[n][1]))
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
maxx = 2 * 10**5 arr = [0] * maxx arr2 = [([0] * 2) for i in range(maxx)] for _ in range(int(input())): n1, n2 = map(int, input().split()) l = list(map(int, input().split())) for i in range(1, len(l) + 1): arr[i] = l[i - 1] for i in range(2, n1 + 1): arr2[i][0] = max( arr2[i - 1][0] + (arr[i - 1] ^ arr[i]), arr2[i - 1][1] + (arr[i - 1] + n2 ^ arr[i]), ) arr2[i][1] = max( arr2[i - 1][0] + (arr[i - 1] ^ arr[i] + n2), arr2[i - 1][1] + (arr[i - 1] + n2 ^ arr[i] + n2), ) print(max(arr2[n1][0], arr2[n1][1]))
ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
from sys import stdin input = stdin.readline for _ in range(int(input())): n, x = map(int, input().split()) arr = [int(x) for x in input().split()] arr1 = [(i + x) for i in arr] dp = [[0, 0] for i in range(n)] for i in range(1, n): dp[i][0] = max( dp[i - 1][0] + (arr[i - 1] ^ arr[i]), dp[i - 1][1] + (arr1[i - 1] ^ arr[i]) ) dp[i][1] = max( dp[i - 1][0] + (arr[i - 1] ^ arr1[i]), dp[i - 1][1] + (arr1[i - 1] ^ arr1[i]), ) print(max(dp[-1][0], dp[-1][1]))
ASSIGN 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for t in range(int(input())): n, x = list(map(int, input().split())) arr = list(map(int, input().split())) dp2 = [[0, 0], [0, 0]] for i in range(2, n + 1): dp2[0].append( max( dp2[0][i - 1] + (arr[i - 2] ^ arr[i - 1]), dp2[1][i - 1] + (arr[i - 2] + x ^ arr[i - 1]), ) ) dp2[1].append( max( dp2[0][i - 1] + (arr[i - 2] ^ arr[i - 1] + x), dp2[1][i - 1] + (arr[i - 2] + x ^ arr[i - 1] + x), ) ) print(max(dp2[0][n], dp2[1][n]))
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
import sys sys.setrecursionlimit(10**6) def sol(prev, i): if i == N: return 0 if (prev, i) in dp: return dp[prev, i] num1 = arr[i - 1] if prev == 1: num1 = arr[i - 1] + X dp[prev, i] = max( (arr[i] ^ num1) + sol(0, i + 1), (arr[i] + X ^ num1) + sol(1, i + 1) ) return dp[prev, i] T = int(input()) for _ in range(T): N, X = [int(x) for x in input().split()] arr = [int(s) for s in input().split()] dp = {} ans1 = sol(1, 1) dp = {} ans2 = sol(0, 1) print(max(ans1, ans2))
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
T = int(input()) for _ in range(T): n, x = [int(i) for i in input().split()] A = [int(i) for i in input().split()] dp = [[0, 0] for _ in range(n)] for i in range(1, n): cur_val = A[i] prev_val = A[i - 1] a1 = cur_val ^ prev_val + x a2 = cur_val ^ prev_val dp[i][0] = max(dp[i - 1][1] + a1, dp[i - 1][0] + a2) b1 = cur_val + x ^ prev_val + x b2 = cur_val + x ^ prev_val dp[i][1] = max(dp[i - 1][1] + b1, dp[i - 1][0] + b2) print(max(dp[-1][0], dp[-1][1]))
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
t = int(input()) while t > 0: t -= 1 n, x = map(int, input().split()) a = list(map(int, input().split())) if n == 1: print(0) continue if n == 2: print(max([a[0] ^ a[1], a[0] + x ^ a[1], a[0] ^ a[1] + x, a[0] + x ^ a[1] + x])) continue xors = [(a[i] ^ a[i + 1]) for i in range(n - 1)] matrix = [[(0) for i in range(n - 1)] for _ in range(4)] for i in range(n - 1): matrix[1][i] = (a[i] + x ^ a[i + 1]) - xors[i] for i in range(n - 1): matrix[2][i] = (a[i] ^ a[i + 1] + x) - xors[i] for i in range(n - 1): matrix[3][i] = (a[i] + x ^ a[i + 1] + x) - xors[i] for i in range(n - 3, -1, -1): matrix[3][i] = matrix[3][i] + max(matrix[1][i + 1], matrix[3][i + 1]) matrix[2][i] = matrix[2][i] + max(matrix[1][i + 1], matrix[3][i + 1]) matrix[1][i] = matrix[1][i] + max(matrix[0][i + 1], matrix[2][i + 1]) matrix[0][i] = matrix[0][i] + max(matrix[0][i + 1], matrix[2][i + 1]) print(sum(xors) + max(0, max([matrix[i][0] for i in range(4)])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, x = list(map(int, input().split())) a = list(map(int, input().split())) if n == 1: print(0) continue incl = max(a[n - 2] + x ^ a[n - 1], a[n - 2] + x ^ a[n - 1] + x) excl = max(a[n - 2] ^ a[n - 1], a[n - 2] ^ a[n - 1] + x) for i in range(n - 3, -1, -1): incl, excl = max( incl + (a[i] + x ^ a[i + 1] + x), excl + (a[i] + x ^ a[i + 1]) ), max(incl + (a[i] ^ a[i + 1] + x), excl + (a[i] ^ a[i + 1])) print(max(incl, excl))
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) dp = [[(0) for i in range(n)] for i in range(2)] dp[0][0] = 0 dp[1][0] = 0 for i in range(1, n): cur = l[i] prev = l[i - 1] dp[0][i] = max((cur ^ prev) + dp[0][i - 1], (cur ^ prev + k) + dp[1][i - 1]) dp[1][i] = max( (cur + k ^ prev) + dp[0][i - 1], (cur + k ^ prev + k) + dp[1][i - 1] ) print(max(dp[0][n - 1], dp[1][n - 1]))
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
def gcd(a, b): if b == 0: return a return gcd(a % b, a) def swap(a, b): a, b = b, a return a, b def fact(n): if n == 1: return 1 return n * fact(n - 1) def cbits(n): count = 0 while n: n = n & n - 1 count += 1 return count def solve(n, x, arr): dp = [([0] * 2) for i in range(n + 1)] for i in range(1, n): dp[i][0] = max( dp[i - 1][0] + (arr[i - 1] ^ arr[i]), dp[i - 1][1] + (arr[i - 1] + x ^ arr[i]), ) dp[i][1] = max( dp[i - 1][0] + (arr[i - 1] ^ arr[i] + x), dp[i - 1][1] + (arr[i - 1] + x ^ arr[i] + x), ) return max(dp[n - 1][0], dp[n - 1][1]) t = int(input()) while t > 0: n, x = map(int, input().split()) arr = list(map(int, input().split())) print(solve(n, x, arr)) t -= 1
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
def sol(a, n, x): r = 0 for i in range(n - 1): r += a[i] ^ a[i + 1] if x == 0: return r dp1 = [0] * (n + 1) dp0 = [0] * (n + 1) for i in range(2, n + 1): dp0[i] = max( dp1[i - 1] + (a[i - 1] ^ a[i - 2] + x), dp0[i - 1] + (a[i - 1] ^ a[i - 2]) ) dp1[i] = max( dp1[i - 1] + (a[i - 1] + x ^ a[i - 2] + x), dp0[i - 1] + (a[i - 1] + x ^ a[i - 2]), ) return max(dp1[n], dp0[n]) for _ in range(int(input())): n, x = [int(x) for x in input().split()] a = [int(x) for x in input().split()] print(sol(a, n, x))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
t = int(input()) for k in range(t): n, x = input().split() n, x = int(n), int(x) s = input().split() if n == 1: print(0) continue for i in range(n): s[i] = int(s[i]) dp = [] for i in range(n): dp.append([-1, -1]) dp[1] = [ max(s[0] ^ s[1], s[0] + x ^ s[1]), max(s[0] ^ s[1] + x, s[0] + x ^ s[1] + x), ] for i in range(2, n): dp[i][0] = max( (s[i] ^ s[i - 1]) + dp[i - 1][0], (s[i] ^ s[i - 1] + x) + dp[i - 1][1] ) dp[i][1] = max( (s[i] + x ^ s[i - 1]) + dp[i - 1][0], (s[i] + x ^ s[i - 1] + x) + dp[i - 1][1], ) print(max(dp[n - 1][0], dp[n - 1][1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER LIST FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, x = map(int, input().split(" ")) arr = list(map(int, input().split(" "))) s = 0 if n == 1: print(0) else: change = 0 unchange = 0 for i in range(1, n): temp1 = change temp2 = unchange change = max( temp2 + (arr[i - 1] ^ arr[i] + x), temp1 + (arr[i - 1] + x ^ arr[i] + x) ) unchange = max( temp2 + (arr[i - 1] ^ arr[i]), temp1 + (arr[i - 1] + x ^ arr[i]) ) print(max(change, unchange))
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): N, X = map(int, input().split()) A = list(map(int, input().split())) dp = [[[(0) for _ in range(2)] for _ in range(2)] for _ in range(N)] for i in range(N - 1): for j in range(2): for k in range(2): for l in range(2): dp[i + 1][l][k] = max( dp[i + 1][l][k], dp[i][k][j] + (A[i] + k * X ^ A[i + 1] + l * X) ) res = 0 for i in range(2): for j in range(2): res = max(res, dp[N - 1][i][j]) print(res)
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
t = int(input()) for _ in range(t): n, x = map(int, input().split()) a = list(map(int, input().split())) dp = [[(0) for i in range(n)] for j in range(2)] dp[0][0] = 0 dp[1][0] = 0 for i in range(1, n): val1 = dp[0][i - 1] + (a[i] ^ a[i - 1]) val2 = dp[1][i - 1] + (a[i] ^ a[i - 1] + x) dp[0][i] = max(val1, val2) val1 = dp[0][i - 1] + (a[i] + x ^ a[i - 1]) val2 = dp[1][i - 1] + (a[i] + x ^ a[i - 1] + x) dp[1][i] = max(val1, val2) print(max(dp[0][n - 1], dp[1][n - 1]))
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
t = int(input()) for _ in range(t): n, x = map(int, input().split()) a = [int(s) for s in input().split()] dp = [] for _ in range(n): dp.append([0, 0]) for i in range(1, n): dp1 = dp[i - 1][0] + (a[i - 1] ^ a[i]) dp2 = dp[i - 1][1] + (a[i - 1] + x ^ a[i]) dp[i][0] = max(dp1, dp2) dp1 = dp[i - 1][0] + (a[i - 1] ^ a[i] + x) dp2 = dp[i - 1][1] + (a[i - 1] + x ^ a[i] + x) dp[i][1] = max(dp1, dp2) print(max(dp[-1][0], dp[-1][1]))
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
t = int(input()) for _ in range(t): n, x = map(int, input().split()) arr = list(map(int, input().split())) if n == 1: print(0) continue dp = [[0, 0] for i in range(n + 1)] for i in range(n - 1, -1, -1): if i == n - 1: dp[i][0] = 0 dp[i][1] = 0 else: dp[i][0] = max( (arr[i] ^ arr[i + 1]) + dp[i + 1][0], (arr[i] ^ arr[i + 1] + x) + dp[i + 1][1], ) dp[i][1] = max( (arr[i] + x ^ arr[i + 1]) + dp[i + 1][0], (arr[i] + x ^ arr[i + 1] + x) + dp[i + 1][1], ) print(max(dp[0][0], dp[0][1]))
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
t = int(input()) res = [] for _ in range(t): n, X = [int(x) for x in input().split()] nums = [int(x) for x in input().split()] dp = [[(0) for _ in range(2)] for _ in range(n)] for i in range(1, n): choice1 = dp[i - 1][1] + (nums[i - 1] + X ^ nums[i]) choice2 = dp[i - 1][1] + (nums[i - 1] + X ^ nums[i] + X) choice3 = dp[i - 1][0] + (nums[i - 1] ^ nums[i] + X) choice4 = dp[i - 1][0] + (nums[i - 1] ^ nums[i]) dp[i][0] = max(choice1, choice4) dp[i][1] = max(choice2, choice3) res.append(max(dp[-1][0], dp[-1][1])) for val in res: print(val)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, k = list(map(int, input().split())) a = list(map(int, input().split())) added, notAdded = 0, 0 for i in range(1, n): v1, v2 = a[i - 1], a[i] added, notAdded = max((v2 + k ^ v1) + notAdded, (v2 + k ^ v1 + k) + added), max( (v2 ^ v1) + notAdded, (v2 ^ v1 + k) + added ) print(max(added, notAdded))
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
n = int(input()) for z in range(n): num, x = map(int, input().split()) arr = [int(i) for i in input().split()] ans = [0, 0] new1, new2 = 0, 0 for i in range(1, num): new1 = max((arr[i] ^ arr[i - 1]) + ans[0], (arr[i] ^ arr[i - 1] + x) + ans[1]) new2 = max( (arr[i] + x ^ arr[i - 1]) + ans[0], (arr[i] + x ^ arr[i - 1] + x) + ans[1] ) ans[0] = new1 ans[1] = new2 print(max(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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
testcase = int(input()) for _ in range(testcase): n, x = [int(num) for num in input().split()] arr = [int(num) for num in input().split()] ans = [[0, 0] for _ in range(n)] for i in range(1, n): for j in range(2): t = arr[i] + x * j p0 = ans[i - 1][0] + (arr[i - 1] ^ t) p1 = ans[i - 1][1] + (arr[i - 1] + x ^ t) ans[i][j] = max(p0, p1) print(max(ans[-1]))
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
from sys import stdin, stdout read = stdin.readline t = int(read()) for i in range(t): a, x = map(int, read().split()) arr = list(map(int, read().split())) a1 = [] a2 = [] for j in range(a): if j == 0: a1.append(0) a2.append(0) else: n1 = max(a1[-1] + (arr[j - 1] ^ arr[j]), a2[-1] + (arr[j - 1] + x ^ arr[j])) n2 = max( a1[-1] + (arr[j - 1] ^ arr[j] + x), a2[-1] + (arr[j - 1] + x ^ arr[j] + x), ) a1.append(n1) a2.append(n2) print(max(a1[-1], a2[-1]))
ASSIGN VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, x = map(int, input().split()) l = list(map(int, input().split())) if n > 1: a = {} for i in range(1, n + 1): a[i] = l[i - 1] d1 = {} d2 = {} for i in range(2, n + 1): if i - 1 not in d1: d1[i - 1] = 0 if i - 1 not in d2: d2[i - 1] = 0 d1[i] = max( d1[i - 1] + (a[i - 1] ^ a[i]), d2[i - 1] + (a[i - 1] + x ^ a[i]) ) d2[i] = max( d1[i - 1] + (a[i - 1] ^ a[i] + x), d2[i - 1] + (a[i - 1] + x ^ a[i] + x) ) print(max(d1[n], d2[n])) else: print(0)
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 IF VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
def solve(x, a): res = [0, 0] for i in range(len(a) - 1): oldres = res.copy() res[0] = max( (a[i] + x ^ a[i + 1] + x) + oldres[0], (a[i] ^ a[i + 1] + x) + oldres[1] ) res[1] = max((a[i] + x ^ a[i + 1]) + oldres[0], (a[i] ^ a[i + 1]) + oldres[1]) return max(res) t = int(input()) for i in range(t): n, x = [int(i) for i in input().split()] a = [int(i) for i in input().split()] print(solve(x, a))
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for i in range(int(input())): n, x = map(int, input().split()) a = list(map(int, input().split())) dp = [] for i in range(n): dp.append([0, 0]) dp[0][0] = 0 dp[0][1] = 0 for i in range(1, n): dp[i][0] = max( dp[i - 1][0] + (a[i - 1] ^ a[i]), dp[i - 1][1] + (a[i - 1] + x ^ a[i]) ) dp[i][1] = max( dp[i - 1][0] + (a[i - 1] ^ a[i] + x), dp[i - 1][1] + (a[i - 1] + x ^ a[i] + x), ) print(max(dp[n - 1][0], dp[n - 1][1]))
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
def adjacent_xors(arr, n, X): p, q = 0, 0 for i in range(1, n): prev_same = max(p + (arr[i - 1] ^ arr[i]), q + (arr[i] ^ arr[i - 1] + X)) prev_change = max( p + (arr[i - 1] ^ arr[i] + X), q + (arr[i - 1] + X ^ arr[i] + X) ) p, q = prev_same, prev_change return max(p, q) T = int(input()) for _ in range(T): N, X = tuple(map(int, input().split())) arr = list(map(int, input().split())) print(adjacent_xors(arr, N, X))
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
def miis(): return map(int, input().split()) for _ in range(int(input())): n, x = miis() a = list(miis()) dpgive = [0] dpdont = [0] for i in range(1, n): to_d = max(dpgive[-1] + (a[i - 1] + x ^ a[i]), dpdont[-1] + (a[i - 1] ^ a[i])) to_g = max( dpgive[-1] + (a[i - 1] + x ^ a[i] + x), dpdont[-1] + (a[i - 1] ^ a[i] + x) ) dpgive.append(to_g) dpdont.append(to_d) print(max(dpgive[-1], dpdont[-1]))
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
T = int(input()) for j in range(T): N, X = list(map(int, input().split())) A = list(map(int, input().split())) dp = [[(0) for i in range(N)] for i in range(2)] for i in range(1, N): dp[0][i] = max( (A[i] ^ A[i - 1]) + dp[0][i - 1], (A[i] ^ A[i - 1] + X) + dp[1][i - 1] ) dp[1][i] = max( (A[i] + X ^ A[i - 1]) + dp[0][i - 1], (A[i] + X ^ A[i - 1] + X) + dp[1][i - 1], ) print(max(dp[0][N - 1], dp[1][N - 1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
import sys sys.setrecursionlimit(10**6) def fun(i, n, f, arr, x, dp): if i == n: return 0 ans = 0 if dp[i - 1][f] != -1: return dp[i - 1][f] if f == 1: ans = max( ans, (arr[i - 1] + x ^ arr[i]) + fun(i + 1, n, 0, arr, x, dp), (arr[i - 1] + x ^ arr[i] + x) + fun(i + 1, n, 1, arr, x, dp), ) else: ans = max( ans, (arr[i - 1] ^ arr[i]) + fun(i + 1, n, 0, arr, x, dp), (arr[i - 1] ^ arr[i] + x) + fun(i + 1, n, 1, arr, x, dp), ) dp[i - 1][f] = ans return ans for _ in range(int(input())): n, x = map(int, input().split()) arr = list(map(int, input().split())) dp = [([-1] * 2) for i in range(n + 1)] if n == 1: print(0) else: dp = [[-1, -1] for i in range(n + 1)] ans1 = fun(1, n, 0, arr, x, dp) ans2 = fun(1, n, 1, arr, x, dp) print(max(ans1, ans2))
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR 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 FUNC_CALL 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, x = [int(i) for i in input().split()] A = [int(i) for i in input().split()] sum_orig = 0 sum_new = 0 current_sum = 0 for i in range(n - 1): orig = A[i] new = A[i] + x next_orig = A[i + 1] next_new = A[i + 1] + x a = max((orig ^ next_orig) + sum_orig, (new ^ next_orig) + sum_new) b = max((orig ^ next_new) + sum_orig, (new ^ next_new) + sum_new) sum_orig = a sum_new = b print(max(sum_orig, sum_new))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
from sys import * setrecursionlimit(1000000) def solve(i, n, x, arr, prev, dp): if i == n: return 0 if dp[prev][i] != -1: return dp[prev][i] if prev: c1 = (arr[i - 1] + x ^ arr[i]) + solve(i + 1, n, x, arr, 0, dp) c2 = (arr[i - 1] + x ^ arr[i] + x) + solve(i + 1, n, x, arr, 1, dp) else: c1 = (arr[i - 1] ^ arr[i]) + solve(i + 1, n, x, arr, 0, dp) c2 = (arr[i - 1] ^ arr[i] + x) + solve(i + 1, n, x, arr, 1, dp) dp[prev][i] = max(c1, c2) return dp[prev][i] for t in range(int(input())): n, x = map(int, input().split()) arr = list(map(int, input().split())) dp = [[(-1) for i in range(n + 1)] for j in range(2)] print(max(solve(1, n, x, arr, 0, dp), solve(1, n, x, arr, 1, dp)))
EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
t = int(input()) for t_1 in range(t): line = input().split(" ") n = int(line[0]) x = int(line[1]) numbers = [int(item) for item in input().split(" ")] max_by_added_i = [0] max_not_added_i = [0] for i in range(1, n): max_by_added_i.append( max( max_by_added_i[i - 1] + (numbers[i - 1] + x ^ numbers[i] + x), max_not_added_i[i - 1] + (numbers[i - 1] ^ numbers[i] + x), ) ) max_not_added_i.append( max( max_by_added_i[i - 1] + (numbers[i - 1] + x ^ numbers[i]), max_not_added_i[i - 1] + (numbers[i - 1] ^ numbers[i]), ) ) print(max(max_by_added_i[n - 1], max_not_added_i[n - 1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER
JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subsequence [2, 3, 5] and add X to all the elements. Now the array A becomes [2 + 7, 1, 6, 3 + 7, 5 + 7] = [9, 1, 6, 10, 12]. JJ wants to maximize the value of \displaystyle \sum_{i = 2}^{N} (A_{i - 1} \oplus A_{i}). Can you help him to do so? Here, \oplus denotes the [bitwise XOR operation]. & & kya & ------ Input Format ------ - The first line contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains two space-separated integers N and X β€” the size of the array A and the parameter X mentioned in the statement. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the maximum value of \displaystyle \sum_{i = 2}^{n} (A_{i - 1} \oplus A_{i}) which can be obtained after applying the given operation at most once. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $1 ≀ N ≀ 10^{5}$ $1 ≀X ≀10^{9}$ $1 ≀A_{i} ≀10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 1 1 2 4 1 2 2 3 3 5 2 5 3 6 2 8 ----- Sample Output 1 ------ 3 15 43 ----- explanation 1 ------ Test case $1$: It is optimal to not perform the given operation. So the answer will equal $1 \oplus 2 = 3$. Test case $2$: It is optimal to add $X = 1$ to the $2^{nd}$ and the $3^{rd}$ element. So $A$ will become $[2, 3, 4, 3]$ and the answer will be $(2 \oplus 3) + (3 \oplus 4) + (4 \oplus 3) = 15$.
for _ in range(int(input())): n, x = map(int, input().split()) a = list(map(int, input().split())) g = [([0] * (n + 1)) for _ in range(2)] for i in range(1, n): if i == 1: g[0][i] = max(a[i - 1] ^ a[i], a[i - 1] + x ^ a[i]) g[1][i] = max(a[i - 1] ^ a[i] + x, a[i - 1] + x ^ a[i] + x) else: g[0][i] = max( g[0][i - 1] + (a[i - 1] ^ a[i]), g[1][i - 1] + (a[i - 1] + x ^ a[i]) ) g[1][i] = max( g[0][i - 1] + (a[i - 1] ^ a[i] + x), g[1][i - 1] + (a[i - 1] + x ^ a[i] + x), ) print(max(g[0][n - 1], g[1][n - 1]))
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 ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer. Two ways are considered different if sets of indexes of elements chosen by these ways are different. Since the answer can be very large, you should find the answer modulo 10^9 + 7. -----Input----- First line contains one integer n (1 ≀ n ≀ 10^5)Β β€” the number of elements in the array. Second line contains n integers a_{i} (1 ≀ a_{i} ≀ 70)Β β€” the elements of the array. -----Output----- Print one integerΒ β€” the number of different ways to choose some elements so that their product is a square of a certain integer modulo 10^9 + 7. -----Examples----- Input 4 1 1 1 1 Output 15 Input 4 2 2 2 2 Output 7 Input 5 1 2 4 5 8 Output 7 -----Note----- In first sample product of elements chosen by any way is 1 and 1 = 1^2. So the answer is 2^4 - 1 = 15. In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.
from sys import stdin def find_prime(max_value): assert max_value >= 2 result = [2] for i in range(3, max_value): state = 1 for item in result: if item * item > i: break elif i % item == 0: state = -1 break if state == 1: result.append(i) return result module = int(1000000000.0) + 7 n = int(stdin.readline()) A = list(map(int, stdin.readline().split())) number = [(0) for i in range(70)] for item in A: number[item - 1] += 1 prime_list = find_prime(70) prime_map = {} for i in range(2, 70 + 1): result = 0 for item in prime_list: cur = i num = 0 while cur % item == 0: num += 1 cur = int(cur / item) result = result * 2 + num % 2 prime_map[i] = result number_dic = {(0): 1} sum_time = 0 for i in range(2, 70 + 1): if number[i - 1] >= 1: mask = prime_map[i] state = 1 new_number_dic = number_dic.copy() for key, value in list(new_number_dic.items()): new_key = key ^ mask if new_key in number_dic: number_dic[new_key] += value else: number_dic[new_key] = value number_dic[new_key] %= module sum_time += number[i - 1] - 1 result = number_dic[0] for j in range(number[0] + sum_time): result *= 2 result %= module print(result - 1)
FUNC_DEF VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER 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 VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer. Two ways are considered different if sets of indexes of elements chosen by these ways are different. Since the answer can be very large, you should find the answer modulo 10^9 + 7. -----Input----- First line contains one integer n (1 ≀ n ≀ 10^5)Β β€” the number of elements in the array. Second line contains n integers a_{i} (1 ≀ a_{i} ≀ 70)Β β€” the elements of the array. -----Output----- Print one integerΒ β€” the number of different ways to choose some elements so that their product is a square of a certain integer modulo 10^9 + 7. -----Examples----- Input 4 1 1 1 1 Output 15 Input 4 2 2 2 2 Output 7 Input 5 1 2 4 5 8 Output 7 -----Note----- In first sample product of elements chosen by any way is 1 and 1 = 1^2. So the answer is 2^4 - 1 = 15. In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.
n = int(input()) (*a,) = map(int, input().split()) mod = 1000000007 d = [] primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67] b = [ 0, 4, 8, 0, 32, 12, 128, 4, 0, 36, 2048, 8, 8192, 132, 40, 0, 131072, 4, 524288, 32, 136, 2052, 8388608, 12, 0, 8196, 8, 128, 536870912, 44, 2147483648, 4, 2056, 131076, 160, 0, 137438953472, 524292, 8200, 36, 2199023255552, 140, 8796093022208, 2048, 32, 8388612, 140737488355328, 8, 0, 4, 131080, 8192, 9007199254740992, 12, 2080, 132, 524296, 536870916, 576460752303423488, 40, 2305843009213693952, 2147483652, 128, 0, 8224, 2060, 147573952589676412928, 131072, 8388616, 164, ] for i in set(a): c = b[i - 1] for j in d: c = min(c, c ^ j) if c > 0: d.append(c) print(pow(2, n - len(d), mod) - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER
Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer. Two ways are considered different if sets of indexes of elements chosen by these ways are different. Since the answer can be very large, you should find the answer modulo 10^9 + 7. -----Input----- First line contains one integer n (1 ≀ n ≀ 10^5)Β β€” the number of elements in the array. Second line contains n integers a_{i} (1 ≀ a_{i} ≀ 70)Β β€” the elements of the array. -----Output----- Print one integerΒ β€” the number of different ways to choose some elements so that their product is a square of a certain integer modulo 10^9 + 7. -----Examples----- Input 4 1 1 1 1 Output 15 Input 4 2 2 2 2 Output 7 Input 5 1 2 4 5 8 Output 7 -----Note----- In first sample product of elements chosen by any way is 1 and 1 = 1^2. So the answer is 2^4 - 1 = 15. In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.
n = int(input()) s = [] p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67] for i in set(map(int, input().split())): b = 0 for j in p: while i % j == 0: i //= j b ^= 1 << j for j in s: b = min(b, b ^ j) if b > 0: s.append(b) print(pow(2, n - len(s), 10**9 + 7) - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER
Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer. Two ways are considered different if sets of indexes of elements chosen by these ways are different. Since the answer can be very large, you should find the answer modulo 10^9 + 7. -----Input----- First line contains one integer n (1 ≀ n ≀ 10^5)Β β€” the number of elements in the array. Second line contains n integers a_{i} (1 ≀ a_{i} ≀ 70)Β β€” the elements of the array. -----Output----- Print one integerΒ β€” the number of different ways to choose some elements so that their product is a square of a certain integer modulo 10^9 + 7. -----Examples----- Input 4 1 1 1 1 Output 15 Input 4 2 2 2 2 Output 7 Input 5 1 2 4 5 8 Output 7 -----Note----- In first sample product of elements chosen by any way is 1 and 1 = 1^2. So the answer is 2^4 - 1 = 15. In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.
n = int(input()) arr = [0] * 71 a = map(int, input().split()) for i in a: arr[i] += 1 dp = [0] * 2**11 dp[0] = 1 for i in range(71): if ( arr[i] == 0 or i == 37 or i == 41 or i == 43 or i == 47 or i == 53 or i == 59 or i == 61 or i == 67 ): continue cur = 0 primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67] for j in range(len(primes)): if i > 1 and i % primes[j] == 0: x = i cnt = 0 while x % primes[j] == 0: x /= primes[j] cnt += 1 if cnt % 2 == 1: cur += 2**j ndp = [0] * 2**11 for x in range(len(dp)): ndp[x ^ cur] += dp[x] * pow(2, arr[i] - 1, 10**9 + 7) ndp[x ^ cur] %= 10**9 + 7 ndp[x] += dp[x] * pow(2, arr[i] - 1, 10**9 + 7) ndp[x] %= 10**9 + 7 dp = ndp ans = dp[0] for i in [37, 41, 43, 47, 53, 59, 61, 67]: if arr[i] > 0: ans *= pow(2, arr[i] - 1, 10**9 + 7) ans %= 10**9 + 7 print((ans + 10**9 + 6) % (10**9 + 7))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER
Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer. Two ways are considered different if sets of indexes of elements chosen by these ways are different. Since the answer can be very large, you should find the answer modulo 10^9 + 7. -----Input----- First line contains one integer n (1 ≀ n ≀ 10^5)Β β€” the number of elements in the array. Second line contains n integers a_{i} (1 ≀ a_{i} ≀ 70)Β β€” the elements of the array. -----Output----- Print one integerΒ β€” the number of different ways to choose some elements so that their product is a square of a certain integer modulo 10^9 + 7. -----Examples----- Input 4 1 1 1 1 Output 15 Input 4 2 2 2 2 Output 7 Input 5 1 2 4 5 8 Output 7 -----Note----- In first sample product of elements chosen by any way is 1 and 1 = 1^2. So the answer is 2^4 - 1 = 15. In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.
def getmask(x): ans = 0 for i in range(2, x + 1): while x % (i * i) == 0: x //= i * i if x % i == 0: ans ^= 1 << i x //= i return ans def main(): maxn = 71 n = int(input()) a = [int(i) for i in input().split()] cnt = [0] * maxn for i in a: cnt[i] += 1 masks = {} for i in range(1, maxn): if cnt[i]: masks[getmask(i)] = masks.get(getmask(i), 0) + cnt[i] while len(masks) > 1 or 0 not in masks: if not masks: print(0) return fixed = max(masks.keys()) for i in list(masks.keys()): if i ^ fixed < i: masks[i ^ fixed] = masks.get(i ^ fixed, 0) + masks[i] masks[i] = 0 masks[0] = masks.get(0, 0) + masks[fixed] - 1 masks[fixed] = 0 masks = {i: j for i, j in masks.items() if j > 0} print(pow(2, masks[0], 10**9 + 7) - 1) main()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR WHILE FUNC_CALL VAR VAR NUMBER NUMBER VAR IF VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR
Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer. Two ways are considered different if sets of indexes of elements chosen by these ways are different. Since the answer can be very large, you should find the answer modulo 10^9 + 7. -----Input----- First line contains one integer n (1 ≀ n ≀ 10^5)Β β€” the number of elements in the array. Second line contains n integers a_{i} (1 ≀ a_{i} ≀ 70)Β β€” the elements of the array. -----Output----- Print one integerΒ β€” the number of different ways to choose some elements so that their product is a square of a certain integer modulo 10^9 + 7. -----Examples----- Input 4 1 1 1 1 Output 15 Input 4 2 2 2 2 Output 7 Input 5 1 2 4 5 8 Output 7 -----Note----- In first sample product of elements chosen by any way is 1 and 1 = 1^2. So the answer is 2^4 - 1 = 15. In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.
MOD = int(1000000000.0 + 7) def is_prime(x): for i in range(2, int(x**0.5) + 1): if x % i == 0: return False return True p = [i for i in range(2, 100) if is_prime(i)] n = int(input()) arr = list(map(int, input().split())) s = [] for i in set(arr): b = 0 for j in p: while i % j == 0: i //= j b ^= 1 << j for j in s: b = min(b, b ^ j) if b > 0: s.append(b) print(pow(2, n - len(s), MOD) - 1)
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER
You are given a board of size $2 \times n$ ($2$ rows, $n$ columns). Some cells of the board contain chips. The chip is represented as '*', and an empty space is represented as '.'. It is guaranteed that there is at least one chip on the board. In one move, you can choose any chip and move it to any adjacent (by side) cell of the board (if this cell is inside the board). It means that if the chip is in the first row, you can move it left, right or down (but it shouldn't leave the board). Same, if the chip is in the second row, you can move it left, right or up. If the chip moves to the cell with another chip, the chip in the destination cell disappears (i. e. our chip captures it). Your task is to calculate the minimum number of moves required to leave exactly one chip on the board. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the length of the board. The second line of the test case contains the string $s_1$ consisting of $n$ characters '*' (chip) and/or '.' (empty cell). The third line of the test case contains the string $s_2$ consisting of $n$ characters '*' (chip) and/or '.' (empty cell). Additional constraints on the input: in each test case, there is at least one chip on a board; the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print one integer β€” the minimum number of moves required to leave exactly one chip on the board. -----Examples----- Input 5 1 * . 2 .* ** 3 *.* .*. 4 **.* **.. 5 **... ...** Output 0 2 3 5 5 -----Note----- None
t = int(input()) for it in range(t): n = int(input()) a = [] for i in range(2): a.append(list(input())) for j in range(n): if a[0][j] == "*" or a[1][j] == "*": l = j break for j in range(n): if a[0][j] == "*" or a[1][j] == "*": r = j for i in range(l + 1, r + 1): if a[0][i - 1] == "*" and a[0][i] == "." and a[1][i - 1] == ".": a[0][i] = "*" if a[1][i - 1] == "*" and a[1][i] == "." and a[0][i - 1] == ".": a[1][i] = "*" for i in range(l + 1, r + 1): if a[0][i] == "." and a[0][i - 1] == "*" and a[1][i] == ".": a[0][i] = "*" ans = -1 for i in range(n): if a[0][i] == "*": ans += 1 if a[1][i] == "*": ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR STRING VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR STRING VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a board of size $2 \times n$ ($2$ rows, $n$ columns). Some cells of the board contain chips. The chip is represented as '*', and an empty space is represented as '.'. It is guaranteed that there is at least one chip on the board. In one move, you can choose any chip and move it to any adjacent (by side) cell of the board (if this cell is inside the board). It means that if the chip is in the first row, you can move it left, right or down (but it shouldn't leave the board). Same, if the chip is in the second row, you can move it left, right or up. If the chip moves to the cell with another chip, the chip in the destination cell disappears (i. e. our chip captures it). Your task is to calculate the minimum number of moves required to leave exactly one chip on the board. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the length of the board. The second line of the test case contains the string $s_1$ consisting of $n$ characters '*' (chip) and/or '.' (empty cell). The third line of the test case contains the string $s_2$ consisting of $n$ characters '*' (chip) and/or '.' (empty cell). Additional constraints on the input: in each test case, there is at least one chip on a board; the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print one integer β€” the minimum number of moves required to leave exactly one chip on the board. -----Examples----- Input 5 1 * . 2 .* ** 3 *.* .*. 4 **.* **.. 5 **... ...** Output 0 2 3 5 5 -----Note----- None
x = [] for _ in range(int(input())): z = int(input()) s1 = input() s2 = input() l = r = -1 for i in range(z): if s1[i] == "*" or s2[i] == "*": if l == -1: l = i r = i d1, d2 = int(s2[l] == "*"), int(s1[l] == "*") for i in range(l + 1, r + 1): d3 = min(d1 + 1 + int(s2[i] == "*"), d2 + 2) d4 = min(d2 + 1 + int(s1[i] == "*"), d1 + 2) d1, d2 = d3, d4 c = min(d1, d2) x.append(c) [print(i) for i in x]
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR STRING BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
You are given a board of size $2 \times n$ ($2$ rows, $n$ columns). Some cells of the board contain chips. The chip is represented as '*', and an empty space is represented as '.'. It is guaranteed that there is at least one chip on the board. In one move, you can choose any chip and move it to any adjacent (by side) cell of the board (if this cell is inside the board). It means that if the chip is in the first row, you can move it left, right or down (but it shouldn't leave the board). Same, if the chip is in the second row, you can move it left, right or up. If the chip moves to the cell with another chip, the chip in the destination cell disappears (i. e. our chip captures it). Your task is to calculate the minimum number of moves required to leave exactly one chip on the board. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the length of the board. The second line of the test case contains the string $s_1$ consisting of $n$ characters '*' (chip) and/or '.' (empty cell). The third line of the test case contains the string $s_2$ consisting of $n$ characters '*' (chip) and/or '.' (empty cell). Additional constraints on the input: in each test case, there is at least one chip on a board; the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print one integer β€” the minimum number of moves required to leave exactly one chip on the board. -----Examples----- Input 5 1 * . 2 .* ** 3 *.* .*. 4 **.* **.. 5 **... ...** Output 0 2 3 5 5 -----Note----- None
import sys input = sys.stdin.readline def solve(): n = int(input()) g = [list(input().rstrip()) for __ in range(2)] left, right = -1, 0 for i in range(n): if g[0][i] == "*" or g[1][i] == "*": if left == -1: left = i right = i ret = 0 f = [0] * (n + 1) mid = (left + right) // 2 for i in range(right): if f[i]: if g[0][i + 1] == "." and g[1][i + 1] == ".": f[i + 1] = 1 ret += 1 continue if ( g[0][i] == "*" and g[1][i] == "*" and g[0][i + 1] == "." and g[1][i + 1] == "." ): f[i + 1] = 1 ret += 2 continue if g[0][i] == "*": if g[0][i + 1] == "." and g[1][i] == ".": g[0][i + 1] = "*" ret += 1 if g[1][i] == "*": if g[1][i + 1] == "." and g[0][i] == ".": g[1][i + 1] = "*" ret += 1 cnt = 0 if g[0][right] == "*": cnt += 1 if g[1][right] == "*": cnt += 1 return ret + (1 if cnt == 2 else 0) for __ in range(int(input())): print(solve())
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER RETURN BIN_OP VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given a board of size $2 \times n$ ($2$ rows, $n$ columns). Some cells of the board contain chips. The chip is represented as '*', and an empty space is represented as '.'. It is guaranteed that there is at least one chip on the board. In one move, you can choose any chip and move it to any adjacent (by side) cell of the board (if this cell is inside the board). It means that if the chip is in the first row, you can move it left, right or down (but it shouldn't leave the board). Same, if the chip is in the second row, you can move it left, right or up. If the chip moves to the cell with another chip, the chip in the destination cell disappears (i. e. our chip captures it). Your task is to calculate the minimum number of moves required to leave exactly one chip on the board. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β€” the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the length of the board. The second line of the test case contains the string $s_1$ consisting of $n$ characters '*' (chip) and/or '.' (empty cell). The third line of the test case contains the string $s_2$ consisting of $n$ characters '*' (chip) and/or '.' (empty cell). Additional constraints on the input: in each test case, there is at least one chip on a board; the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print one integer β€” the minimum number of moves required to leave exactly one chip on the board. -----Examples----- Input 5 1 * . 2 .* ** 3 *.* .*. 4 **.* **.. 5 **... ...** Output 0 2 3 5 5 -----Note----- None
import sys input = sys.stdin.readline def solve(): n = int(input()) board = [input().strip() for _ in range(2)] f = 0 while f < n and board[0][f] == "." and board[1][f] == ".": f += 1 b = n - 1 while b >= 0 and board[0][b] == "." and board[1][b] == ".": b -= 1 dp = [0, 0] for i in range(f, b): if board[0][i] == "." and board[1][i] == ".": dp = [min(dp[0] + 1, dp[1] + 2), min(dp[0] + 2, dp[1] + 1)] elif board[0][i] == "*" and board[1][i] == ".": dp = [min(dp[0] + 1, dp[1] + 2), min(dp[0], dp[1]) + 2] elif board[0][i] == "." and board[1][i] == "*": dp = [min(dp[0], dp[1]) + 2, min(dp[0] + 2, dp[1] + 1)] else: dp = [min(dp[0], dp[1]) + 2, min(dp[0], dp[1]) + 2] if board[0][b] == "." and board[1][b] == ".": return min(dp) elif board[0][b] == "." and board[1][b] == "*": return min(dp[0] + 1, dp[1]) elif board[0][b] == "*" and board[1][b] == ".": return min(dp[0], dp[1] + 1) else: return min(dp) + 1 for _ in range(int(input())): print(solve())
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING ASSIGN VAR LIST BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING RETURN FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING RETURN FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of $7$ segments, which can be turned on or off to display different numbers. The picture shows how all $10$ decimal digits are displayed: After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly $k$ segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly $k$ sticks (which are off now)? It is allowed that the number includes leading zeros. -----Input----- The first line contains integer $n$ $(1 \leq n \leq 2000)$ β€” the number of digits on scoreboard and $k$ $(0 \leq k \leq 2000)$ β€” the number of segments that stopped working. The next $n$ lines contain one binary string of length $7$, the $i$-th of which encodes the $i$-th digit of the scoreboard. Each digit on the scoreboard consists of $7$ segments. We number them, as in the picture below, and let the $i$-th place of the binary string be $0$ if the $i$-th stick is not glowing and $1$ if it is glowing. Then a binary string of length $7$ will specify which segments are glowing now. Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from $0$ to $9$ inclusive. -----Output----- Output a single number consisting of $n$ digits β€” the maximum number that can be obtained if you turn on exactly $k$ sticks or $-1$, if it is impossible to turn on exactly $k$ sticks so that a correct number appears on the scoreboard digits. -----Examples----- Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 -----Note----- In the first test, we are obliged to include all $7$ sticks and get one $8$ digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For $5$ of additionally included sticks, you can get the numbers $07$, $18$, $34$, $43$, $70$, $79$, $81$ and $97$, of which we choose the maximum β€” $97$. In the third test, it is impossible to turn on exactly $5$ sticks so that a sequence of numbers appears on the scoreboard.
def binStringToInt(s): return int(s, base=2) def binIntToString(x): return bin(x)[2:] numToString = [ "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011", ] digits = [[(-1) for _ in range(10)] for __ in range(2**7)] for i in range(2**7): iS = binIntToString(i) for num in range(10): numS = numToString[num] num2 = binStringToInt(numS) if i | num2 == num2: digits[i][num] = numS.count("1") - iS.count("1") n, k = [int(x) for x in input().split()] board = [] for _ in range(n): board.append(binStringToInt(input())) possibleMoves = [set() for _ in range(n)] for i in range(n): binaryInt = board[i] for num in range(10): if digits[binaryInt][num] != -1: possibleMoves[i].add(digits[binaryInt][num]) dp = [[(False) for _ in range(k + 1)] for __ in range(n + 1)] dp[n][0] = True for i in range(n - 1, -1, -1): for kk in range(k + 1): for cost in possibleMoves[i]: if kk - cost >= 0 and dp[i + 1][kk - cost] == True: dp[i][kk] = True break if dp[0][k] == True: ans = "" currK = k for i in range(n): binaryInt = board[i] for num in range(9, -1, -1): cost = digits[binaryInt][num] if cost != -1 and currK - cost >= 0 and dp[i + 1][currK - cost] == True: ans = ans + str(num) currK -= cost break print(ans) else: print(-1)
FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of $7$ segments, which can be turned on or off to display different numbers. The picture shows how all $10$ decimal digits are displayed: After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly $k$ segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly $k$ sticks (which are off now)? It is allowed that the number includes leading zeros. -----Input----- The first line contains integer $n$ $(1 \leq n \leq 2000)$ β€” the number of digits on scoreboard and $k$ $(0 \leq k \leq 2000)$ β€” the number of segments that stopped working. The next $n$ lines contain one binary string of length $7$, the $i$-th of which encodes the $i$-th digit of the scoreboard. Each digit on the scoreboard consists of $7$ segments. We number them, as in the picture below, and let the $i$-th place of the binary string be $0$ if the $i$-th stick is not glowing and $1$ if it is glowing. Then a binary string of length $7$ will specify which segments are glowing now. Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from $0$ to $9$ inclusive. -----Output----- Output a single number consisting of $n$ digits β€” the maximum number that can be obtained if you turn on exactly $k$ sticks or $-1$, if it is impossible to turn on exactly $k$ sticks so that a correct number appears on the scoreboard digits. -----Examples----- Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 -----Note----- In the first test, we are obliged to include all $7$ sticks and get one $8$ digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For $5$ of additionally included sticks, you can get the numbers $07$, $18$, $34$, $43$, $70$, $79$, $81$ and $97$, of which we choose the maximum β€” $97$. In the third test, it is impossible to turn on exactly $5$ sticks so that a sequence of numbers appears on the scoreboard.
zero = "1110111" one = "0010010" two = "1011101" three = "1011011" four = "0111010" five = "1101011" six = "1101111" seven = "1010010" eight = "1111111" nine = "1111011" numbers = [nine, eight, seven, six, five, four, three, two, one, zero] n, k2 = map(int, input().split()) bank = 0 completefail = 0 listofusage = [] listofbestnums = [] lamps = [] def convert(s): new = "" for x in s: new += x return new for i in range(n): lamp = input() lamps.append(lamp) maxusage = 100 bestnum = "" for j in numbers: fail = 0 usage = 0 for k in range(7): if j[k] == "0" and lamp[k] == "1": fail = 1 if j[k] == "1" and lamp[k] == "0": usage += 1 if fail == 1: continue if usage < maxusage: bestnum = j maxusage = usage if maxusage == 100: completefail = 1 break listofusage.append(maxusage) listofbestnums.append(bestnum) if completefail == 1 or sum(listofusage) > k2: print(-1) else: ans = [] bank = k2 - sum(listofusage) for i in range(n - 1): lamp = lamps[i] change = 0 for j in numbers: fail = 0 usage = 0 for k in range(7): if j[k] == "0" and lamp[k] == "1": fail = 1 if j[k] == "1" and lamp[k] == "0": usage += 1 if fail == 1: continue if usage - listofusage[i] <= bank: change = 1 bank -= usage - listofusage[i] break if change == 0: ans.append(listofbestnums[i]) else: ans.append(j) totalfail = 0 if bank > 7 - listofusage[n - 1]: j = n - 2 const = bank - 7 + listofusage[n - 1] for i in range(const): if j == -1: totalfail = 1 break if ans[j] == eight: i -= 1 j -= 1 continue ans[j] = eight bank -= 1 j -= 1 lamp = lamps[n - 1] change = 0 for j in numbers: fail = 0 usage = 0 for k in range(7): if j[k] == "0" and lamp[k] == "1": fail = 1 if j[k] == "1" and lamp[k] == "0": usage += 1 if fail == 1: continue if usage - listofusage[n - 1] == bank: change = 1 bank -= usage - listofusage[n - 1] break if change == 0: ans.append(listofbestnums[n - 1]) else: ans.append(j) if totalfail == 1 or not bank == 0: print(-1) else: printans = [] for i in range(n): for j in range(10): if ans[i] == numbers[j]: printans.append(str(9 - j)) break print(convert(printans))
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't give any answer. The poor boy was very upset because of that. He was so sad that he punched some kind of scoreboard with numbers. The numbers are displayed in the same way as on an electronic clock: each digit position consists of $7$ segments, which can be turned on or off to display different numbers. The picture shows how all $10$ decimal digits are displayed: After the punch, some segments stopped working, that is, some segments might stop glowing if they glowed earlier. But Denis remembered how many sticks were glowing and how many are glowing now. Denis broke exactly $k$ segments and he knows which sticks are working now. Denis came up with the question: what is the maximum possible number that can appear on the board if you turn on exactly $k$ sticks (which are off now)? It is allowed that the number includes leading zeros. -----Input----- The first line contains integer $n$ $(1 \leq n \leq 2000)$ β€” the number of digits on scoreboard and $k$ $(0 \leq k \leq 2000)$ β€” the number of segments that stopped working. The next $n$ lines contain one binary string of length $7$, the $i$-th of which encodes the $i$-th digit of the scoreboard. Each digit on the scoreboard consists of $7$ segments. We number them, as in the picture below, and let the $i$-th place of the binary string be $0$ if the $i$-th stick is not glowing and $1$ if it is glowing. Then a binary string of length $7$ will specify which segments are glowing now. Thus, the sequences "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011" encode in sequence all digits from $0$ to $9$ inclusive. -----Output----- Output a single number consisting of $n$ digits β€” the maximum number that can be obtained if you turn on exactly $k$ sticks or $-1$, if it is impossible to turn on exactly $k$ sticks so that a correct number appears on the scoreboard digits. -----Examples----- Input 1 7 0000000 Output 8 Input 2 5 0010010 0010010 Output 97 Input 3 5 0100001 1001001 1010011 Output -1 -----Note----- In the first test, we are obliged to include all $7$ sticks and get one $8$ digit on the scoreboard. In the second test, we have sticks turned on so that units are formed. For $5$ of additionally included sticks, you can get the numbers $07$, $18$, $34$, $43$, $70$, $79$, $81$ and $97$, of which we choose the maximum β€” $97$. In the third test, it is impossible to turn on exactly $5$ sticks so that a sequence of numbers appears on the scoreboard.
import sys def compare(x, s): for i in range(len(x)): if x[i] == "1" and s[i] == "0": return False return True def compare2(x, s): count = 0 for i in range(len(x)): if x[i] == "0" and s[i] == "1": count += 1 return count li = [ "1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011", ] dummy = li + [] dict = {} num = 0 for i in li: dict[i] = num num += 1 n, k = [int(x) for x in input().split()] arr = [] for i in range(n): s = input() arr.append(s) ans = [] k_ans = [] for i in range(len(arr)): need = 0 if dict.get(arr[i]) is not None: ans.append(arr[i]) else: need = 7 todo = li[8] for j in li: if compare(arr[i], j): p = compare2(arr[i], j) if p < need: need = p todo = j k -= need ans.append(todo) k_ans.append(need) if k < 0: print(-1) sys.exit(0) to_print = "" li = li[::-1] for i in range(n): s = ans[i] for j in li: if dict[j] <= dict[s]: break if compare(arr[i], j): p = compare2(arr[i], j) if p - k_ans[i] <= k: ans[i] = j k -= p - k_ans[i] k_ans[i] = p break if k >= 2: for i in range(n - 1, -1, -1): if dict[ans[i]] == 7: if compare(arr[i], dummy[5]): ans[i] = dummy[5] k -= 2 else: ans[i] = dummy[3] k -= 2 break flag = 0 if k > 0: index = 0 for i in range(n - 1, -1, -1): for j in li: if dict[j] < dict[ans[i]] and compare(arr[i], j): p = compare2(arr[i], j) if p - k_ans[i] <= k: k -= p - k_ans[i] if p - k_ans[i] < 0: flag = 1 else: flag = 2 ans[i] = j index = i break if flag != 0: break if flag == 1: nn = 0 for i in range(index + 1, n): for j in li: if dict[j] > dict[ans[i]] and compare(arr[i], j): p = compare2(arr[i], j) if p - k_ans[i] > k: continue k -= p - k_ans[i] ans[i] = j nn = 1 break if nn == 1: break if nn == 0: for i in range(n - 1, -1, -1): if dict[ans[i]] == 7: if compare(arr[i], dummy[5]): ans[i] = dummy[5] k -= 2 else: ans[i] = dummy[3] k -= 2 break if k > 0: for i in range(n - 1, -1, -1): if k == 0: break if dict[ans[i]] == 9: ans[i] = dummy[8] k -= 1 if k > 0: print(-1) sys.exit(0) for i in range(n): print(dict[ans[i]], end="")
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NONE EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING