description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, N): def findTwoPower(N): x = 0 while 1 << x <= N: x += 1 return x - 1 if N <= 1: return N x = findTwoPower(N) return x * int(2 ** (x - 1)) + (N - (1 << x) + 1) + self.countBits(N - ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP NUM...
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
def power(n): x = 0 while 2**x <= n: x += 1 return x - 1 class Solution: def countBits(self, n): if n == 0: return 0 if n == 3: return 4 x = power(n) ans = x * 2 ** (x - 1) + (n - 2**x + 1) + self.countBits(n - 2**x) ans1 = int(a...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR ...
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def powerof2(self, n): x = 1 c = 0 while x <= n: p = x x = x << 1 c += 1 return [p, c - 1] def countBits(self, n): if n == 0: return 0 l = self.powerof2(n) ans = (l[0] >> 1) * l[1] + (n - l[...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN LIST VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER...
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, N): ans = 0 tot_sets = 0 N1 = N while N1: tot_sets += 1 N1 &= N1 - 1 ans += tot_sets for i in range(32): if i == 0 and N & 1 << i: tot_sets -= 1 ans += tot_sets ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_...
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, n): if n == 0: return 0 if n == 1: return 1 m, k = 1, 0 while n >= m: m = m << 1 k = k + 1 m = m >> 1 k = k - 1 return k * (m >> 1) + (n - m + 1) + self.countBits(n - m)
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CA...
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, N): if N <= 0: return 0 elif N == 1: return 1 x = 0 while 1 << x <= N: x += 1 x -= 1 return (1 << x - 1) * x + (N - (1 << x) + 1) + self.countBits(N - (1 << x))
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, N): if N == 0: return 0 p = 0 ans = 0 while pow(2, p) <= N: p += 1 p -= 1 ans += p * pow(2, p) // 2 + N - pow(2, p) + 1 + self.countBits(N - pow(2, p)) return ans
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR RETURN VAR
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def largestPowerOfTwoInRange(self, N): power = 0 while pow(2, power) <= N: power = power + 1 return power - 1 def countSetBits(self, num): setBitsCount = 0 while num != 0: bit = num & 1 if bit == 1: set...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER A...
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, n): ans = 0 for i in range(32): part1 = n + 1 >> i + 1 << i part2 = n + 1 - (1 << i) - (n + 1 >> i + 1 << i + 1) if part2 > 0: ans += part1 + part2 else: ans += part1 return a...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR VAR VAR RETURN VAR
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, N): def findpow(n): x = 0 while 1 << x <= n: x = x + 1 return x - 1 def ans(n): if n <= 1: return n x = findpow(n) return x * pow(2, x - 1) + (n - pow(2, x) ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER FUNC_CAL...
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, N): return self.count1(N) def count1(self, A): if A == 0 or A == 1: return A x = self.po(A) ans = x * (1 << x - 1) + (A - (1 << x) + 1) + self.count1(A - (1 << x)) return ans def po(self, n): c = 1 whi...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_...
You are given a number N. Find the total number of setbits in the numbers from 1 to N. Example 1: Input: N = 3 Output: 4 Explaination: 1 -> 01, 2 -> 10 and 3 -> 11. So total 4 setbits. Example 2: Input: N = 4 Output: 5 Explaination: 1 -> 01, 2 -> 10, 3 -> 11 and 4 -> 100. So total 5 setbits. Your Task: You do n...
class Solution: def countBits(self, n): if n == 0: return 0 def find_x(n): x = 0 while 2**x <= n: x += 1 return x - 1 x = find_x(n) remaining = self.countBits(n - 2**x) ans = 2 ** (x - 1) * x + (n - 2**x + 1) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER...
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): a = 0 for j in range(32): c = 0 for i in arr: if i >> j & 1 == 1: c += 1 a += 2 * c * (len(arr) - c) return a
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): ans = 0 for i in range(32): c1, c2 = 0, 0 for j in range(n): if arr[j] & 1 << i > 0: c1 += 1 else: c2 += 1 ans += c1 * c2 return a...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): res = [0] * 32 for i in arr: k = 0 while i: if i & 1: res[k] += 1 k += 1 i >>= 1 s = 0 n = len(arr) for i in res: if i...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): n = len(arr) sum_bit_diff = 0 for i in range(32): count_set_bits = 0 count_clear_bits = 0 for j in range(n): if arr[j] & 1 << i: count_set_bits += 1 e...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): res = 0 for i in range(32): count1s = 0 for x in arr: if x & 1 << i != 0: count1s += 1 count0s = len(arr) - count1s bitDiff = count1s * 2 * count0s re...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, A, N): cnt = 0 maxi = max(A) z = len(bin(maxi)[2:]) li = [bin(x)[2:].zfill(z) for x in A] l = [(0) for i in range(z)] for x in li: i = 0 for ch in x: if ch == "0": ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR NUMBER VAR NUMBER FOR VAR VAR VAR BIN_OP B...
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): arr = list(arr) m = r = 0 for i in range(max(arr).bit_length()): m = 0 for j in arr: if j >> i & 1 == 1: m += 1 r += 2 * m * (len(arr) - m) return r
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
def diff(a, b): x = a ^ b c = 0 while x: c += 1 x = x & x - 1 return c class Solution: def sumBitDifferences(self, arr, n): m = len(bin(max(arr))) - 2 l0 = [0] * m l1 = [0] * m for x in arr: for i in range(m): if x & 1: ...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR...
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): d = [] ans = 0 for i in range(0, 31): c = 0 for j in arr: if j & 1 << i: c += 1 d.append(c) for i in d: ans += 2 * (i * (n - i)) return an...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR VAR RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): main_count = 0 c = 0 zero = 0 count = 0 for k in range(32): count = 0 for i in range(n): if arr[i] >> k & 1 == 1: count += 1 zero = n - count ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): sum = 0 v = max(arr) for i in range(v.bit_length()): setbits = 0 for j in arr: if j >> i & 1: setbits += 1 sum += 2 * setbits * (n - setbits) return sum
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): sum = 0 for i in range(32): setbits = 0 for j in arr: k = j >> i if k & 1: setbits += 1 sum += 2 * setbits * (n - setbits) return sum
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): l = len(arr) mx = max(arr) bitlen = mx.bit_length() k = 0 for i in range(bitlen): c = 0 for j in arr: if j >> i & 1: c += 1 k += 2 * c * (l - c) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
NOOFBITS = 17 class Solution: def sumBitDifferences(self, arr, siz): bitsum = [0] * NOOFBITS for n in arr: j = 0 while n > 0: bitsum[j] += n & 1 n >>= 1 j += 1 total = 0 for noofones in bitsum: noo...
ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y. For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 ...
class Solution: def sumBitDifferences(self, arr, n): res = 0 for i in range(32): count = 0 for j in range(n): if arr[j] & 1 << i: count += 1 res += count * (n - count) * 2 return res
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN VAR
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: def have_keys(status, key_id): return status & 2**key_id sx, sy = -1, -1 key_number = 0 key_idx = "abcdef" lock_idx = "ABCDEF" n, m = len(grid), len(grid[0]) for i in range(n...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF VAR VAR...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: res, dire, all_keys = 0, [[0, 1], [1, 0], [0, -1], [-1, 0]], 0 for i in range(len(grid)): for j in range(len(grid[0])): if grid[i][j] == "@": loc = i, j if grid[i][...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUN...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: m, n = len(grid), len(grid[0]) q = collections.deque() seen = set() tot_keys = 0 for i, row in enumerate(grid): for j, val in enumerate(row): if val == "@": ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING VAR NUMBER ...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid) -> int: row, col = len(grid), len(grid[0]) key_num, key = 0, {} for i in range(row): for j in range(col): if grid[i][j] == "@": start_i, start_j = i, j if grid[i][j] in "abcde...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR NUMBER NUMBER ASSIG...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: m, n = len(grid), len(grid[0]) k = 0 stx, sty = 0, 0 for i in range(m): for j in range(n): if grid[i][j] in "abcdef": k += 1 if grid[i][j] == "@": ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR LIST NUMBER NUMB...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: m = len(grid) n = len(grid[0]) q = collections.deque() keys = 0 visited = set() for i in range(m): for j in range(n): if grid[i][j] == "@": q.append...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR STR...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: m, n = len(grid), len(grid[0]) q, seen, keys = deque(), set(), set() for i in range(m): for j in range(n): if grid[i][j] == "@": q.append((i, j, "")) se...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING IF STRING VAR VAR VAR STRING EXP...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: n, m = len(grid), len(grid[0]) queue = collections.deque() seen = set() nKeys = 0 moves = 0 for i in range(n): for j in range(m): if grid[i][j] == "@": ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR NUMBER NUMBER STRING IF VAR VAR VAR STRING ...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: n, m = len(grid), len(grid[0]) startx, starty = -1, -1 nkeys = 0 for i in range(n): for j in range(m): if grid[i][j] == "@": startx, starty = i, j i...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR NUMBER STRING NUMBER...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: row, col = len(grid), len(grid[0]) x, y = None, None num_keys = 0 for r in range(row): for c in range(col): if grid[r][c] == "@": x, y = r, c elif g...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NONE NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR NUMBER NUMBER STRING ASS...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: sr, sc = 0, 0 k, m, n = 0, len(grid), len(grid[0]) key_id = collections.defaultdict(int) for i, x in enumerate("abcdef"): key_id[x] = i + 1 for r in range(m): for c in range(n): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR ASS...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: def bfs(r, c): start = grid[r][c] dist[start] = {} queue = collections.deque([(r, c, 0)]) visited = {(r, c): True} while queue: i, j, d = queue.pop() ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR FUNC_CALL VAR LIST VAR VAR NUMBER ASSIGN VAR DICT VAR VAR NUMBER WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR VAR VAR LIST STRING STRING VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR VAR LIST LIST BIN_OP VAR NUMBER VAR LIST BIN_...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: m = len(grid) n = len(grid[0]) def neighbor(i, j, keys): keys_list = list(keys) if grid[i][j] in [".", "@"]: return i, j, keys elif grid[i][j].islower(): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR LIST STRING STRING RETURN VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR ...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: if not grid or not grid[0]: return -1 m, n = len(grid), len(grid[0]) sx = sy = target = -1 for i in range(m): for j in range(n): c = grid[i][j] if c == "@":...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: keylock = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "A": "a", "B": "b", "C": "c", "D": "d", "E":...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: init_x, init_y = -1, -1 m = len(grid) n = len(grid[0]) keycnt = 0 for i in range(m): for j in range(n): c = grid[i][j] if c == "@": init_x, ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR VAR VAR VAR IF VAR STRING VAR STRING VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN ...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: mx_key = max( grid[i][j] for i in range(len(grid)) for j in range(len(grid[0])) if grid[i][j].isalpha() and grid[i][j].islower() ) for i in range(len(grid)): fo...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR A...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: if not grid: return -1 keys = [0] * 6 m, n = len(grid), len(grid[0]) si, sj = 0, 0 for i in range(m): for j in range(n): if grid[i][j] == "@": s...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CAL...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def __init__(self): self.DIR = [(1, 0), (-1, 0), (0, 1), (0, -1)] def shortestPathAllKeys(self, grid: List[str]) -> int: init_x = init_y = -1 target_keys = 0 for i in range(len(grid)): for j in range(len(grid[0])): if grid[i][j] == "@...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP NUMB...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid): m, n, k, keys, d = len(grid), len(grid[0]), 0, "", set() grid.append("#" * n) for i in range(m): grid[i] += "#" for i in range(m): for j in range(n): if grid[i][j] == "@": ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER STRING FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING VAR VA...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: if not grid: return -1 m, n = len(grid), len(grid[0]) numKeys = 0 for i in range(m): for j in range(n): if grid[i][j] == "@": start = i, j, 0 ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR LIS...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: target = 0 queue, visited = [], set() for i in range(len(grid)): for j in range(len(grid[0])): if "a" <= grid[i][j] <= "f": target += 1 elif grid[i][j] == "...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF STRING VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR LIST N...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: def contains(k, v): return k // v % 2 == 1 adjs = [[-1, 0], [0, 1], [0, -1], [1, 0]] keys = ["a", "b", "c", "d", "e", "f"] locks = [c.upper() for c in keys] key_to_val = {k: (2**i) for i, k ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR...
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wal...
class Solution: def shortestPathAllKeys(self, grid: List[str]) -> int: keys = "abcdef" locks = "ABCDEF" n, m = len(grid), len(grid[0]) x, y = -1, -1 target = 0 for i in range(n): for j in range(m): ch = grid[i][j] if ch == ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = input().split(" ") n = int(n) q = int(q) a = [] pre = 0 b = [] arr = input() a = list(map(int, arr.split(" "))) for i in range(0, int(n)): pre = pre ^ a[i] b.append(pre) b.append(0) for i in range(0, int(q)): k = int(input()) k = k - 1 k = k % (n + 1) print(b[k])
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = list(map(int, input().split())) a = list(map(int, input().split())) s = [0] * (n + 1) for i in range(n): if i == 0: s[i] = a[i] else: s[i] = s[i - 1] ^ a[i] s[n] = 0 for _ in range(q): k = int(input()) k -= 1 k = k % (n + 1) print(s[k])
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMB...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = list(map(int, input().split())) arr = [f[0]] for i in range(1, n): arr.append(f[i] ^ arr[i - 1]) arr.append(0) n = n + 1 for i in range(q): k = int(input()) print(arr[(k - 1) % n])
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
l = list(map(int, input().split())) n = l[0] q = l[1] l = list(map(int, input().split())) num = 0 for i in range(len(l)): num = num ^ l[i] l.append(num) s = [] num = 0 for i in range(len(l)): num = num ^ l[i] s.append(num) for i in range(q): k = int(input()) k = k % (n + 1) k = k - 1 if k < ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMB...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f1 = list(map(int, input().split())) f = [] size = n + 1 ans = 0 for i in range(n): ans ^= f1[i] f.append(ans) while q: k = int(input()) if k % size == 0: print(0) else: print(f[k % size - 1]) q -= 1
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBE...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
from sys import stdin def main(): n, q = map(int, stdin.readline().split()) arr = list(map(int, stdin.readline().split())) f = [0, arr[0]] xor = arr[0] ^ arr[1] f.append(xor) for index in range(2, n): xor ^= arr[index] f.append(xor) for query in range(q): k = int(st...
FUNC_DEF 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 NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
N, Q = map(int, input().split()) a = list(map(int, input().split())) s = [] c = 0 for i in a: c ^= i s.append(c) s.append(0) for i in range(Q): print(s[(int(input()) - 1) % len(s)])
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 NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NU...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = list(map(int, input().split())) l = list(map(int, input().split())) v = [(0) for x in range(n)] v[0] = l[0] for j in range(1, n): v[j] = v[j - 1] ^ l[j] for i in range(q): k = int(input()) if k <= n: print(v[k - 1]) else: ans = (k - n) % (n + 1) - 1 if ans == 0: ...
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 ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR AS...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) arr = [int(n) for n in input().split()] x = arr[0] arr1 = [] arr1.append(x) for i in range(1, n): x = x ^ arr[i] arr1.append(x) arr1.append(0) while q: q = q - 1 x = int(input()) r = x % (n + 1) print(arr1[r - 1])
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 VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR N...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
l = input().split() n = int(l[0]) q = int(l[1]) l = input().split() li = [int(i) for i in l] xori = 0 si = [(0) for i in range(n)] for i in range(n): si[i] = xori xori = xori ^ li[i] si.append(xori) fi = list(li) fi.append(xori) for you in range(q): q1 = int(input()) print(si[q1 % (n + 1)])
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUN...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) F = [] S = [] line1 = input().split() last = 0 for i in range(n): F.append(int(line1[i])) last = last ^ int(line1[i]) S.append(last) S.append(0) for i in range(q): query = int(input()) pos = (query - 1) % len(S) final = S[pos] print(final)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) lst = list(map(int, input().split())) ans = [lst[0]] for i in range(1, n): ans.append(ans[i - 1] ^ lst[i]) ans.append(0) for _ in range(q): idx = int(input()) % (n + 1) - 1 print(ans[idx])
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUN...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = [*map(int, input().split())] w = 0 for i in f: w ^= i f += [w] for i in range(1, len(f)): f[i] ^= f[i - 1] for i in range(q): k = int(input()) - 1 print(f[k % (n + 1)])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBE...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = list(map(int, input().split())) c = f[0] s = [f[0]] for i in range(1, n): c = c ^ f[i] s.append(c) s.append(0) for _ in range(q): k = int(input()) print(s[k % (n + 1) - 1])
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 ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VA...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) nli = [0] + list(map(int, input().split())) d = [0] for i in range(1, n + 1): d.append(d[i - 1] ^ nli[i]) for j in range(q): qi = int(input()) print(d[qi % (n + 1)])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) l = list(map(int, input().split())) t = [] for i in range(q): t.append(int(input())) k = 0 l1 = [] for i in l: k ^= i l1.append(k) l1 += [0] lenl = len(l1) for i in t: print(l1[(i - 1) % lenl])
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR LIST NUMBER ASSIGN VAR FUN...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, k = map(int, input().split()) arr = list(map(int, input().split())) sol_arr = [0] var = 0 for i in range(n): var ^= arr[i] sol_arr.append(var) while k > 0: x = int(input()) print(sol_arr[x % (n + 1)]) k -= 1
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = [int(i) for i in input().split()] a = [int(i) for i in input().split()] xor = a[0] for i in range(1, len(a)): xor = xor ^ a[i] a.append(xor) s = [a[0]] for i in range(1, len(a)): s.append(s[-1] ^ a[i]) for I in range(q): k = int(input()) k -= 1 print(s[k % (n + 1)])
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR F...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = list(map(int, input().split())) for j in range(1, n): f[j] ^= f[j - 1] for g in range(q): k = int(input()) tyagibagi = k % (n + 1) if tyagibagi == 0: print(0) else: print(f[tyagibagi - 1])
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 VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = list(map(int, input().split())) record = [] r = 0 for i in range(n): record.append(f[i]) r = r ^ f[i] record.append(r) s = [record[0]] for i in range(1, n + 1): s.append(s[i - 1] ^ record[i]) for i in range(q): k = int(input()) temp = k % (n + 1) print(s[temp...
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 NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = list(map(int, input().split())) d = {} ans = f[0] for i in range(1, n): ans = f[i] ^ ans f.append(ans) d[1] = f[0] for i in range(2, n + 2): d[i % (n + 1)] = d[i - 1] ^ f[i - 1] for _ in range(q): k = int(input()) print(d[k % (n + 1)])
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 DICT ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = list(map(int, input().split())) a = 0 na = [(0) for x in range(n + 1)] na[0] = f[0] na[n] = 0 for i in range(1, n): na[i] = na[i - 1] ^ f[i] for i in range(q): que = int(input()) print(na[que % (n + 1) - 1])
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUM...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
nq = [x for x in list(map(int, input().split(" ")))] tab = [x for x in list(map(int, input().split(" ")))] xs = tab[0] sol = [] sol.append(tab[0]) for i in range(1, nq[0]): xs ^= tab[i] sol.append(xs) sol.append(sol[-1] ^ xs) for i in range(nq[1]): q = int(input()) print(sol[(q - 1) % (nq[0] + 1)])
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) a = list(map(int, input().split())) f = [0] * n for i in range(n): if i == 0: f[i] = a[i] else: f[i] = f[i - 1] ^ a[i] for i in range(q): k = int(input()) x = k % (n + 1) if x == 0: print(0) else: print(f[x - 1])
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 VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) a = list(map(int, input().split())) xor = 0 sl = [] for i in a: xor = xor ^ i sl.append(xor) for i in range(q): qval = int(input()) if qval % (n + 1) == 0: print(0) else: print(sl[qval % (n + 1) - 1])
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 ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMB...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
N, Q = map(int, input().split()) l = list(map(int, input().split())) ans = [0] sk = 0 def tobinary(a): s = "" while a > 0: s = str(a % 2) + s a = a // 2 return s def XOR(a, b): s1 = tobinary(a) s2 = tobinary(b) if len(s1) > len(s2): s2 = "0" * (len(s1) - len(s2)) + s2...
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 NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN V...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
a, b = map(int, input().split()) A = list(map(int, input().split())) B = [] xor = 0 for i in range(a): xor ^= A[i] B.append(xor) for _ in range(b): t = int(input()) if t % (a + 1) == 0: print(0) else: hade = t % (a + 1) hade -= 1 print(B[hade])
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 NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMB...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split(" ")) ar, xor = list(map(int, input().split(" "))), 0 for x in ar: xor ^= x ar.append(xor) prefix = [0] * (n + 1) prefix[0] = ar[0] for i in range(1, len(prefix)): prefix[i] = ar[i] ^ prefix[i - 1] for i in range(q): print(prefix[(int(input()) - 1) % (n + 1)])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSI...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split(" ")) F = list(map(int, input().split(" "))) S = [0] for i in range(n): x = S[i] ^ F[i] S.append(x) S.append(0) for i in range(q): k = int(input()) indx = k % (n + 1) print(S[indx])
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = list(map(int, input().split())) s = [0] * (n + 1) f_seq = list(map(int, input().split())) for i in range(1, n + 1): s[i] = s[i - 1] ^ f_seq[i - 1] for _ in range(q): k = int(input()) print(s[k % (n + 1)])
ASSIGN VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
N, Q = map(int, input().split()) arr = list(map(int, input().split())) temp = arr[0] f = [arr[0]] for num in arr[1:]: temp ^= num f.append(temp) for i in range(Q): q = int(input()) s = q % (N + 1) ans = 0 if s >= 1: ans = f[s - 1] print(ans)
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 ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
a = [int(s) for s in input().split()] b = [int(s) for s in input().split()] c = [0] d = 0 for e in range(a[0]): d = d ^ b[e] c.append(d) for j in range(a[1]): e = int(input()) if e <= a[0]: print(c[e]) else: print(c[(e - (a[0] + 1)) % (a[0] + 1)])
ASSIGN 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = input().split() n = int(n) q = int(q) f = [int(fi) for fi in input().split()] cur = 0 s = [0] for fi in f: cur = cur ^ fi s.append(cur) for i in range(q): k = int(input()) print(s[k % (n + 1)])
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
N, Q = map(int, input().split()) F = [0] + list(map(int, input().split())) x = F[1] for i in range(2, N + 1): x = x ^ F[i] F.append(x) S = [0] S.append(F[1]) for i in range(2, N + 2): S.append(F[i] ^ S[i - 1]) for _ in range(Q): i = int(input()) if i % (N + 1) == 0: print(0) else: pr...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR NUMBER FO...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = list(map(lambda x: int(x), input().split())) a = list(map(lambda x: int(x), input().split())) xor_a = 0 for i in a: xor_a = xor_a ^ i a.append(xor_a) prefix = [a[0]] for i in range(1, len(a)): prefix.append(a[i] ^ prefix[i - 1]) for i in range(0, q): x = int(input()) print(prefix[(x - 1) % (n + 1...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR E...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, m = map(int, input().split()) l = [int(i) for i in input().split()] pr = [0] * (n + 1) pr = 0 for i in l: pr ^= i l.append(pr) pre = [0] * (n + 1) pre[0] = l[0] for i in range(1, n + 1): pre[i] = pre[i - 1] ^ l[i] for i in range(m): x = int(input()) x -= 1 print(pre[x % (n + 1)])
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 LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VA...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
N, Q = [int(x) for x in input().split()] F = [int(x) for x in input().split()] S = [F[0]] for i in range(1, len(F)): S.append(S[-1] ^ F[i]) for _ in range(Q): val = int(input()) % (N + 1) if not val: print(0) else: print(S[val - 1])
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR ...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = [int(a) for a in input().strip().split()] F = [int(a) for a in input().strip().split()] S = [0] for i in range(n): S.append(S[i] ^ F[i]) for _ in range(q): k = int(input()) print(S[k % (n + 1)])
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) arr = [int(x) for x in input().split()] x = arr[0] for i in range(1, len(arr)): x = x ^ arr[i] arr.append(x) xor = [] xor.append(arr[0]) for i in range(1, len(arr)): xor.append(xor[i - 1] ^ arr[i]) xor.insert(0, xor[n]) n += 1 while q != 0: q -= 1 t = int(input()) pr...
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, Q = map(int, input().split()) a = [int(x) for x in input().split()] b = [a[0]] for i in range(1, n): b.append(b[len(b) - 1] ^ a[i]) b.append(0) n += 1 for q in range(Q): k = int(input()) if k <= n: k -= 1 print(b[k]) else: if k % n == 0: k = n else: ...
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FU...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
N, Q = input().split() N = int(N) Farray = list(map(int, input().split())) requiredarray = [Farray[0]] for i in range(1, N): requiredarray.append(requiredarray[-1] ^ Farray[i]) requiredarray.append(0) for j in range(int(Q)): q = int(input()) print(requiredarray[q % (N + 1) - 1])
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUN...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().strip().split()) flist = list(map(int, input().strip().split())) num = 0 for ele in flist: num = num ^ ele flist.append(num) slist = [] num = 0 for ele in flist: num = num ^ ele slist.append(num) for _ in range(q): ind = int(input()) ind -= 1 rem = ind % (n + 1) print...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FO...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) a = list(map(int, input().split())) fin = [a[0]] for i in range(1, n): fin.append(fin[i - 1] ^ a[i]) while q: q1 = int(input()) rem = q1 % (n + 1) if rem == 0: print(0) else: print(fin[rem - 1]) q -= 1
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VA...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = [int(w) for w in input().split()] ft = [] ft.append(f[0]) for i in range(1, n): temp = ft[i - 1] temp = temp ^ f[i] ft.append(temp) ft.append(0) while q: k = int(input()) index = k % (n + 1) - 1 print(ft[index]) q = q - 1
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 EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR ASSIG...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = [int(fi) for fi in input().split()] s = [] sk = 0 for k in range(n): sk = sk ^ f[k] s.append(sk) s.append(0) for _ in range(q): k = int(input()) if k < n: print(s[k - 1]) else: print(s[k % (n + 1) - 1])
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split(" ")) f = list(map(int, input().split(" "))) c = [0] d = 0 for i in range(n): d = d ^ f[i] c.append(d) while q: e = int(input()) if e <= n: print(c[e]) else: print(c[(e - (n + 1)) % (n + 1)]) q = q - 1
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EX...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = input().strip().split(" ") n, q = int(n), int(q) l = list(map(int, input().strip().split(" "))) temp = l[0] for i in l[1:]: temp ^= i l.append(temp) ans = {} temp = 0 for i in range(n, -1, -1): ans[i] = temp ^ l[i] temp ^= l[i] for i in range(q): k = int(input()) print(ans[k % (n + 1)])
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR V...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
import sys sys.setrecursionlimit(10**5 + 1) inf = int(10**20) max_val = inf min_val = -inf RW = lambda: sys.stdin.readline().strip() RI = lambda: int(RW()) RMI = lambda: [int(x) for x in sys.stdin.readline().strip().split()] RWI = lambda: [x for x in sys.stdin.readline().strip().split()] nb_elem, nb_query = RMI() elem...
IMPORT EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUN...
Vietnamese and Bengali as well. An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \ldots, F...
n, q = map(int, input().split()) f = [int(x) for x in input().split()] xortab = [] xor, xor1 = 0, 0 for i in f: xor ^= i xortab.append(xor) xortab.append(0) for i in range(q): k = int(input()) rem = k % (n + 1) print(xortab[rem - 1])
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 ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_O...