description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
query = int(input()) for q in range(query): num = bin(int(input()))[2:][::-1] length = len(num) ans = 0 for cnt, x in enumerate(num): if x == "0": ans += 2**cnt print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\textit{q}$ queries, and each query is in the form of a long integer denoting $\boldsymbol{x}$. For each query, print the total number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the conditions above on a new line. For example, you are given the value $x=5$. Condition $2$ requires that $\class{ML__boldsymbol}{\boldsymbol{a}}<x$. The following tests are run: $1\oplus5=4$ $2\oplus5=7$ $3\oplus5=6$ $4\oplus5=1$ We find that there are $2$ values meeting the first condition: $2$ and $3$. Function Description Complete the theGreatXor function in the editor below. It should return an integer that represents the number of values satisfying the constraints. theGreatXor has the following parameter(s): x: an integer Input Format The first line contains an integer $\textit{q}$, the number of queries. Each of the next $\textit{q}$ lines contains a long integer describing the value of $\boldsymbol{x}$ for a query. Constraints $1\leq q\leq10^5$ $1\leq x\leq10^{10}$ Subtasks For $50\%$ of the maximum score: $1\leq q\leq10^3$ $1\leq x\leq10^4$ Output Format For each query, print the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the given conditions on a new line. Sample Input 0 2 2 10 Sample Output 0 1 5 Explanation 0 We perform the following $q=2$ queries: For $x=2$ the only value of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying $0<a<x$ is $1$. This also satisfies our other condition, as $1\oplus2=3$ and $3>x$. Because we have one valid $\class{ML__boldsymbol}{\boldsymbol{a}}$ and there are no more values to check, we print $1$ on a new line. For $x=10$, the following values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfy our conditions: $1\oplus10=11$ $4\oplus10=14$ $5\oplus10=15$ $6\oplus10=12$ $7\oplus10=13$ There are five valid values of $\class{ML__boldsymbol}{\boldsymbol{a}}$. Sample Input 1 2 5 100 Sample Output 1 2 27 Explanation 1 In the first case: $2\oplus5=7$ $3\oplus5=6$ In the second case, the first 10 values are: $1\oplus100=101$ $2\oplus100=102$ $3\oplus100=103$ $8\oplus100=108$ $9\oplus100=109$ $10\oplus100=110$ $11\oplus100=111$ $\textbf{12}\oplus100=104$ $13\oplus100=105$ $14\oplus100=106$ $15\oplus100=107$
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) answer = 0 for i in range(0, 33): if 1 << i >= x: break if 0 == x & 1 << i: answer = answer + (1 << i) print(answer)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR IF NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c) Example 2: Input: a = 4, b = 2, c = 7 Output: 1 Example 3: Input: a = 1, b = 2, c = 3 Output: 0   Constraints: 1 <= a <= 10^9 1 <= b <= 10^9 1 <= c <= 10^9
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: flips = 0 print(bin(a)) print(bin(b)) print(bin(c)) while a or b or c: if c % 2: if not (a % 2 or b % 2): flips += 1 else: flips += a % 2 + b % 2 a //= 2 b //= 2 c //= 2 return flips
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c) Example 2: Input: a = 4, b = 2, c = 7 Output: 1 Example 3: Input: a = 1, b = 2, c = 3 Output: 0   Constraints: 1 <= a <= 10^9 1 <= b <= 10^9 1 <= c <= 10^9
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: res = 0 for i in range(32): mask = 1 << i ai = a & mask bi = b & mask ci = c & mask if ci == 0: if ai and bi: res += 2 elif ai or bi: res += 1 elif not ai and not bi: res += 1 return res
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c) Example 2: Input: a = 4, b = 2, c = 7 Output: 1 Example 3: Input: a = 1, b = 2, c = 3 Output: 0   Constraints: 1 <= a <= 10^9 1 <= b <= 10^9 1 <= c <= 10^9
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: a = bin(a)[2:].zfill(32) b = bin(b)[2:].zfill(32) c = bin(c)[2:].zfill(32) count = 0 for i in range(32): temp_a = int(a[i]) temp_b = int(b[i]) temp_c = int(c[i]) if temp_a | temp_b != temp_c: if temp_c == 1: count += 1 else: if temp_a == 1: count += 1 if temp_b == 1: count += 1 return count
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c) Example 2: Input: a = 4, b = 2, c = 7 Output: 1 Example 3: Input: a = 1, b = 2, c = 3 Output: 0   Constraints: 1 <= a <= 10^9 1 <= b <= 10^9 1 <= c <= 10^9
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: flips = 0 while a or b or c: if c & 1 == 0: if a & 1: flips += 1 if b & 1: flips += 1 elif a & 1 == 0 and b & 1 == 0: flips += 1 a >>= 1 b >>= 1 c >>= 1 return flips
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c) Example 2: Input: a = 4, b = 2, c = 7 Output: 1 Example 3: Input: a = 1, b = 2, c = 3 Output: 0   Constraints: 1 <= a <= 10^9 1 <= b <= 10^9 1 <= c <= 10^9
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: i, j, k = bin(a)[2:], bin(b)[2:], bin(c)[2:] maxL = max(len(i), len(j), len(k)) i, j, k = ( "0" * (maxL - len(i)) + i, "0" * (maxL - len(j)) + j, "0" * (maxL - len(k)) + k, ) cnt = 0 for x, y, z in zip(i, j, k): if z == "1" and x == "0" and y == "0": cnt += 1 if z == "0": if x == "1": cnt += 1 if y == "1": cnt += 1 return cnt
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR NUMBER IF VAR STRING IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER RETURN VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c) Example 2: Input: a = 4, b = 2, c = 7 Output: 1 Example 3: Input: a = 1, b = 2, c = 3 Output: 0   Constraints: 1 <= a <= 10^9 1 <= b <= 10^9 1 <= c <= 10^9
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: stra = "{0:b}".format(a) strb = "{0:b}".format(b) strc = "{0:b}".format(c) n = max(len(stra), len(strb), len(strc)) stra = "0" * (n - len(stra)) + stra strb = "0" * (n - len(strb)) + strb strc = "0" * (n - len(strc)) + strc boolA = [(s == "1") for s in stra] boolB = [(s == "1") for s in strb] boolC = [(s == "1") for s in strc] x = 0 for i in range(n): A, B, C = boolA[i], boolB[i], boolC[i] if not (A or B) == C: if A and B: x += 2 else: x += 1 return x
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING VAR VAR ASSIGN VAR VAR STRING VAR VAR ASSIGN VAR VAR STRING VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c) Example 2: Input: a = 4, b = 2, c = 7 Output: 1 Example 3: Input: a = 1, b = 2, c = 3 Output: 0   Constraints: 1 <= a <= 10^9 1 <= b <= 10^9 1 <= c <= 10^9
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: count = 0 while a or b or c: temp = a & 1 | b & 1 if temp != c & 1: if c & 1: count += 1 else: if a & 1: count += 1 if b & 1: count += 1 a = a >> 1 b = b >> 1 c = c >> 1 return count
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) i = 0 while i < t: l1, l2, l3, N = input().strip().split(" ") N = int(N) if (l1.count("0") == 0 and l2.count("0") == 0) and l3.count("0") == 0: print("1") elif l3.count("0") == 0 and l2.count("0") == 0: s1 = bin(int(l1, 2) + 1) s1 = s1[2 : len(s1)] print(s1.count("1")) elif l3.count("0") == 0: s1 = bin(int(l2, 2) + 1) s1 = s1[2 : len(s1)] print(l1.count("1") + l2.count("1") * (N - 1) + s1.count("1")) else: s1 = bin(int(l3, 2) + 1) l3 = s1[2 : len(s1)] print(l1.count("1") + l2.count("1") * N + l3.count("1")) i += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
import sys def ones(x): return sum(1 for c in list(x) if c == "1") def trailones(x): ret = 0 for c in reversed(list(x)): if c == "0": break ret += 1 return ret def solve(a, b, c, d): oc = ones(c) tc = trailones(c) if tc < len(c): return ones(a) + ones(b) * d + oc - tc + 1 tb = trailones(b) if tb < len(b): return ones(a) + ones(b) * d - tb + 1 return ones(a) - trailones(a) + 1 f = sys.stdin t = int(f.readline()) for i in range(t): a, b, c, d = f.readline().split() d = int(d) print(solve(a, b, c, d))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
def inc(b): for i, c in reversed(list(enumerate(b))): if c == "0": b[i] = "1" break b[i] = "0" else: return 1 return 0 for _ in range(int(input())): a, b, c, n = input().split() a, b, c = (list(x) for x in (a, b, c)) n = int(n) r = 0 if inc(c): t = b.count("1") if inc(b): r += inc(a) r += a.count("1") else: r += a.count("1") r += b.count("1") r += t * (n - 1) else: r += a.count("1") r += b.count("1") * n r += c.count("1") print(r)
FUNC_DEF FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
import sys sys.setrecursionlimit(10**9) def pad(s): if s == "": return s if s[0] == "0": return pad(s[1:]) return s def pad1(s): if s == "": return s if s[0] == "1": return pad1(s[1:]) return s t = int(input()) while t > 0: t -= 1 s1, s2, s3, n = map(str, input().split()) n = int(n) if n <= 10: s = s1 + n * s2 + s3 s = pad(s)[::-1] s = pad1(s) print(s.count("1") + 1) else: n -= 2 if pad(s1 + s2) == "": s3 = pad1(pad(s3)[::-1]) print(s3.count("1") + 1) elif pad1((s2 + s3)[::-1]) == "": s1 = pad1(pad(s1)[::-1]) print(s1.count("1") + 1) else: s1 += s2 s1 = pad(s1) s3 = s2 + s3 s3 = s3[::-1] s3 = pad1(s3) print(s1.count("1") + n * s2.count("1") + s3.count("1") + 1)
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR STRING RETURN VAR IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR STRING RETURN VAR IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for t in range(int(input())): l = list(input().strip().split()) l[3] = int(l[3]) str2 = l[2] str2 = str2[::-1] flag = [False] * 3 count = 1 i = 0 while i < len(str2) and str2[i] == "1": i += 1 if i == len(str2): flag[2] = True if not flag[2]: count = count + str2[i:].count("1") + l[1].count("1") * l[3] + l[0].count("1") elif flag[2]: str1 = l[1] str1 = str1[::-1] j = 0 while j < len(str1) and str1[j] == "1": j += 1 if j == len(str1): flag[1] = True if not flag[1]: count = ( count + str1[j:].count("1") + l[1].count("1") * (l[3] - 1) + l[0].count("1") ) elif flag[1]: str0 = l[0] str0 = str0[::-1] k = 0 while k < len(str0) and str0[k] == "1": k += 1 if k == len(str0): flag[0] = True if not flag[0]: count = count + str0[k:].count("1") elif flag[0]: count = count print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING BIN_OP FUNC_CALL VAR NUMBER STRING VAR NUMBER FUNC_CALL VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING BIN_OP FUNC_CALL VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) for i in range(0, t): count = 0 l1, l2, l3, n = map(str, input().split()) N = int(n) L = int(l3, 2) if len(l3) == l3.count("1"): if len(l2) == l2.count("1"): l = int(l1, 2) + 1 l1 = bin(l) L1 = l1.count("1") else: l4 = l2 l = int(l4, 2) + 1 l4 = bin(l) n1 = l4.count("1") n2 = (N - 1) * l2.count("1") n3 = l1.count("1") L1 = n1 + n2 + n3 else: L = L + 1 l3 = bin(L) L1 = l1.count("1") + N * l2.count("1") + l3.count("1") print(L1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for _ in range(int(input())): a, b, c, n = map(str, input().split()) n = int(n) s = a + b + c c1 = a.count("1") + n * b.count("1") + c.count("1") l = len(s) i = l - 1 while i >= 0: if s[i] == "0": break i -= 1 if i == l - 1: print(c1 + 1) elif i == -1: print(1) elif i <= len(a) - 1: print(c1 - (len(a) - i - 1) + 1 - (n * b.count("1") + c.count("1"))) else: print(c1 - (l - i - 1) + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for i in range(0, int(input())): lst = [i for i in input().split()] s1, s2, s3, n = lst[0], lst[1], lst[2], int(lst[3]) o = 0 for i in s1: if i == "1": o += 1 for i in s2: if i == "1": o += n for i in s3: if i == "1": o += 1 o += 1 l = len(s3) - 1 if s3[l] == "1": while l >= 0 and s3[l] == "1": l -= 1 o -= 1 if l == -1: l = len(s2) - 1 k = 0 while l >= 0 and s2[l] == "1": l -= 1 k += 1 if k == len(s2): o -= n * len(s2) else: o -= k if l == -1: l = len(s1) - 1 while l >= 0 and s1[l] == "1": l -= 1 o -= 1 print(o)
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for _ in range(int(input())): l = input().split() cnt = 0 for c in l[1]: cnt += c == "1" cnt *= int(l[3]) for c in l[0]: cnt += c == "1" for c in l[2]: cnt += c == "1" i = len(l[2]) - 1 while i >= 0 and l[2][i] == "1": cnt -= 1 i -= 1 if l[2] == "1" * len(l[2]): if l[1] != "1" * len(l[1]): i = len(l[1]) - 1 while i >= 0 and l[1][i] == "1": cnt -= 1 i -= 1 else: if l[0] != len(l[0]) * "1": i = len(l[0]) - 1 while i >= 0 and l[0][i] == "1": cnt -= 1 i -= 1 else: cnt -= len(l[0]) cnt -= int(l[3]) * len(l[1]) cnt += 1 print(cnt)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR VAR STRING VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER VAR VAR STRING FOR VAR VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP STRING FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for z in range(int(input())): li = [i for i in input().split()] ans, temp = 0, 0 if li[2][-1] == "0": ans = 1 for i in li[0]: if i == "1": ans += 1 for i in li[1]: if i == "1": temp += 1 temp *= int(li[3]) ans += temp for i in li[2]: if i == "1": ans += 1 else: zc, dex = -1, 0 for i in li[2][::-1]: if zc == 0: if i == "1": ans += 1 if i == "0": zc = 0 if zc == 0: for i in li[1]: if i == "1": temp += 1 temp *= int(li[3]) ans += temp for i in li[0]: if i == "1": ans += 1 else: for i in li[1][::-1]: if zc == 0: if i == "1": ans += 1 if i == "0": zc = 0 if zc == 0: for i in li[1]: if i == "1": temp += 1 temp *= int(li[3]) - 1 ans += temp for i in li[0]: if i == "1": ans += 1 else: for i in li[0][::-1]: if zc == 0: if i == "1": ans += 1 if i == "0": zc = 0 ans += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER FOR VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER FOR VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) for i in range(t): l1, l2, l3, n = input().split() n = int(n) c = l1.count("1") + l2.count("1") * n + l3.count("1") len1, len2, len3 = len(l1), len(l2), len(l3) if l3[-1] == "0": print(c + 1) elif l3[-1] == "1": r = l3.rindex("0") if "0" in l3 else -1 if r != -1: print(c - (len3 - (r + 1)) + 1) continue r = l2.rindex("0") if "0" in l2 else -1 if r != -1: print(c - (len3 + len2 - (r + 1)) + 1) continue r = l1.rindex("0") if "0" in l1 else -1 if r != -1: print(c - (len1 + len3 + len2 * n - (r + 1)) + 1) continue print(1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR STRING VAR FUNC_CALL VAR STRING NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR STRING NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR STRING NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) for i in range(t): l1, l2, l3, n = map(lambda x: x.strip(), list(input().split())) n = int(n) x = l3.rfind("0") if x == -1: y = l2.rfind("0") if y == -1: z = l1.rfind("0") if z == -1: print(1) else: print(1 + l1.count("1", 0, z)) else: count = l2.count("1") * n + l1.count("1") - l2.count("1", y) print(1 + count) elif x == len(l3) - 1: count = l3.count("1") + l2.count("1") * n + l1.count("1") print(1 + count) else: count = l3.count("1") - l3.count("1", x) + l2.count("1") * n + l1.count("1") print(1 + count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR STRING NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) for i in range(t): l1, l2, l3, n = map(str, input().split()) len1 = l1.count("1") len2 = l2.count("1") len3 = l3.count("1") if len3 == len(l3): if len2 == len(l2): if len1 == len(l1): print(1) else: ind = -1 while l1[ind] != "0": ind = ind - 1 print(max(0, len1 + ind + 1) + 1) else: ind = -1 while l2[ind] != "0": ind = ind - 1 print(len2 * (int(n) - 1) + len1 + max(0, len2 + ind + 1) + 1) elif l3[-1] == "1": ind = -1 while l3[ind] != "0": ind = ind - 1 print(len1 + len2 * int(n) + max(0, len3 + ind + 1) + 1) else: print(len1 + len2 * int(n) + len3 + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) for t0 in range(t): l1, l2, l3, n = [i for i in input().strip().split()] n = int(n) s = 0 s1 = 0 if "0" in l3: r1 = l3.rindex("0") s = l1.count("1") + l2.count("1") * n + l3[0:r1].count("1") + 1 elif "0" in l2: r1 = l2.rindex("0") ct = l2[r1:].count("1") s = l1.count("1") + l2.count("1") * n + 1 - ct elif "0" in l1: r1 = l1.rindex("0") ct = l1[r1:].count("1") s = l1.count("1") + 1 - ct else: s = 1 print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR STRING NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR NUMBER VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for t in range(eval(input())): lis = input().split() c3 = 0 flag = False for i in reversed(lis[2]): if flag and i == "1": c3 += 1 elif i == "0": flag = True c2 = 0 c21 = 0 for i in reversed(lis[1]): if i == "1": c21 += 1 if flag: c2 += 1 elif i == "0": flag = True if flag: c2 += (eval(lis[3]) - 1) * c21 c1 = 0 for i in reversed(lis[0]): if flag and i == "1": c1 += 1 elif i == "0": flag = True print(c1 + c2 + c3 + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR NUMBER IF VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
def fdown(i): return i & i + 1 def actual_answer(value): count = 0 while value > 0: value = fdown(value) - 1 count += 1 return count t = int(input()) while t > 0: t -= 1 l1, l2, l3, n = input().split() n = int(n) case1 = int(l1 + l2 + l3, base=2) case2 = int(l1 + l2 * 2 + l3, base=2) count_case1 = actual_answer(case1) count_case2 = actual_answer(case2) diff = count_case2 - count_case1 answer = count_case1 + (n - 1) * diff print(answer)
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
def check(s): size = len(s) end, total, found = 0, 0, True for i in range(len(s) - 1, -1, -1): if s[i] == "0": found = False if found: end += 1 if s[i] == "1": total += 1 return total, end, size for i in range(int(input())): l = list(map(str, input().split())) s1 = check(l[0]) s2 = check(l[1]) s3 = check(l[2]) if s3[2] != s3[1]: ans = s1[0] + int(l[3]) * s2[0] + s3[0] - s3[1] + 1 elif s2[2] != s2[1]: ans = s1[0] + (int(l[3]) - 1) * s2[0] + s2[0] - s2[1] + 1 elif s1[2] != s1[1]: ans = s1[0] - s1[1] + 1 else: ans = 1 print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) while t: t -= 1 inp = input().split() n = int(inp[3]) inp_1 = inp[0] inp_2 = inp[1] inp_3 = inp[2] len1 = len(inp_1) len2 = len(inp_2) len3 = len(inp_3) count = 1 c = len3 - 1 found_zero = 0 while c >= 0: if inp_3[c] == "0": found_zero = 1 c -= 1 continue elif found_zero: count += 1 c -= 1 else: c -= 1 c = len2 - 1 cnt = 0 while c >= 0: if inp_2[c] == "0": found_zero = 1 c -= 1 continue elif found_zero: count += n c -= 1 else: cnt += 1 c -= 1 if found_zero: count += (n - 1) * cnt c = len1 - 1 while c >= 0: if inp_1[c] == "0": found_zero = 1 c -= 1 continue elif found_zero: count += 1 c -= 1 else: c -= 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
tes = int(input()) for _ in range(tes): a, b, c, n = [x for x in input().split()] n = int(n) ans = switch = 0 for i in range(len(c) - 1, -1, -1): if switch == 0: if c[i] == "0": switch = 1 ans += 1 if switch == 1: if c[i] == "1": ans += 1 for i in range(len(b) - 1, -1, -1): if switch == 0: if b[i] == "0": switch = 1 ans += 1 if switch == 1: if b[i] == "1": ans += 1 for i in range(len(b) - 1, -1, -1): if switch == 0: if b[i] == "0": switch = 1 ans += n - 1 if switch == 1: if b[i] == "1": ans += n - 1 for i in range(len(a) - 1, -1, -1): if switch == 0: if a[i] == "0": switch = 1 ans += 1 if switch == 1: if a[i] == "1": ans += 1 if switch == 0: ans = 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) ans = [] for i in range(t): ip = list(input().split(" ")) l1 = ip[0] l2 = ip[1] l3 = ip[2] n = int(ip[3]) zero_flag = 0 count = 0 rep_count = 0 for j in range(len(l3) - 1, -1, -1): if l3[j] == "1": count += 1 if zero_flag == 0: rep_count += 1 else: zero_flag = 1 l2_count = 0 l2_rep_count = 0 zero_flag = 0 for j in range(len(l2) - 1, -1, -1): if l2[j] == "1": l2_count += 1 if zero_flag == 0: l2_rep_count += 1 else: zero_flag = 1 l1_count = 0 l1_rep_count = 0 zero_flag = 0 for j in range(len(l1) - 1, -1, -1): if l1[j] == "1": l1_count += 1 if zero_flag == 0: l1_rep_count += 1 else: zero_flag = 1 if rep_count == len(l3): if l2_rep_count == len(l2): rep_count += l2_rep_count * n + l1_rep_count else: rep_count += l2_rep_count count += l2_count * n + l1_count count -= rep_count ans.append(count + 1) for x in ans: print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
def add_one(n, add_carry=False): n = list(n) l = len(n) carry = 1 for i in range(l - 1, -1, -1): if carry == 1: if n[i] == "1": n[i] = "0" else: n[i] = "1" carry = 0 if add_carry and carry == 1: n.insert(0, "1") return "".join(n), carry def complex_add_one(l1, l2, l3, n): l3, l3_c = add_one(l3) if l3_c == 0: return l1, l2, l3, n l2_old = l2 l2, l2_c = add_one(l2) if l2_c == 0: return l1, l2_old, l2 + l3, n - 1 l1, l1_c = add_one(l1) if l1_c == 1: l1 = "1" + l1 return l1, l2, l3, n def count_ones(n): return sum([(1) for c in n if c == "1"]) def complex_count_ones(l1, l2, l3, n): return count_ones(l1) + n * count_ones(l2) + count_ones(l3) def expand(l1, l2, l3, n): return l1 + n * l2 + l3 def compute(): z = input().split() z[3] = int(z[3]) z = complex_add_one(*z) print(complex_count_ones(*z)) t = int(input()) for _ in range(t): compute()
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING RETURN FUNC_CALL STRING VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR RETURN VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR VAR VAR STRING FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) for i in range(t): l1, l2, l3, n = input().strip().split(" ") n = int(n) cnt = 0 if l3.count("0") == 0: if l2.count("0") == 0: ll1 = bin(int(l1, 2) + 1) ll1 = ll1[2 : len(ll1)] cnt = ll1.count("1") else: ll2 = bin(int(l2, 2) + 1) ll2 = ll2[2 : len(ll2)] cnt += l2.count("1") * (n - 1) + ll2.count("1") cnt += l1.count("1") else: ll3 = bin(int(l3, 2) + 1) ll3 = ll3[2 : len(ll3)] cnt += ll3.count("1") + l2.count("1") * n + l1.count("1") print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
T = int(input()) for _t in range(T): a, b, c, n = input().strip().split(" ") n = int(n) ans = 0 if "0" not in a + b + c: ans = 1 elif "1" not in a + b + c: ans = 0 else: if "0" in c: ans = 0 elif "0" in b: c = b n -= 1 elif "0" in a: c = a n = 0 a = "" c = list(c) for i in range(len(c) - 1, -1, -1): if c[i] == "1": c[i] = "0" else: c[i] = "1" break ans = a.count("1") + n * b.count("1") + c.count("1") print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF STRING BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF STRING BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR VAR VAR NUMBER IF STRING VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
def plusone(s): for i in range(len(s) - 1, -1, -1): if s[i] == "0": s[i] = "1" return i else: s[i] = "0" return -1 def countones(s): cnt = 0 for c in s: if c == "1": cnt += 1 return cnt T = int(input()) for t in range(T): S = input().split() L1, L2, L3, N = list(S[0]), list(S[1]), list(S[2]), int(S[3]) L2x = list(L2) N -= 1 cnt = 0 y = 100 x = plusone(L3) if x == -1: y = plusone(L2x) if y == -1: z = plusone(L1) if z == -1: L1 = ["1"] cnt = countones(L3) if y >= 0: cnt += countones(L2x) + N * countones(L2) cnt += countones(L1) print(cnt)
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING RETURN VAR ASSIGN VAR VAR STRING RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = input() t = int(t) while t: l1, l2, l3, n = input().split() n = int(n) counter = 0 t = t - 1 if l3.count("1") == len(l3): if l2.count("1") == len(l2): if l1.count("1") == len(l1): counter = 1 print(counter) continue else: temp = int(l1, 2) temp += 1 counter += bin(temp).count("1") print(counter) continue else: temp = int(l2, 2) temp += 1 counter += bin(temp).count("1") counter += l1.count("1") counter += (n - 1) * l2.count("1") print(counter) continue else: temp = int(l3, 2) temp += 1 counter += bin(temp).count("1") counter += l1.count("1") counter += n * l2.count("1") print(counter) continue
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR STRING VAR BIN_OP VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
import sys t = int(input()) for i in range(t): s = input().strip().split() n = int(s[3]) l1 = "" l2 = "" l3 = "" if s[2][-1] == "0": print(1 + s[0].count("1") + n * s[1].count("1") + s[2].count("1")) else: l3 = bin(int(s[2], 2) + 1)[2:] if len(l3) <= len(s[2]): print(s[0].count("1") + n * s[1].count("1") + l3.count("1")) elif s[1][-1] == "0": print(1 + s[0].count("1") + n * s[1].count("1") + (l3.count("1") - 1)) else: l2 = bin(int(s[1], 2) + 1)[2:] if len(l2) <= len(s[1]): print( s[0].count("1") + (n - 1) * s[1].count("1") + l2.count("1") + (l3.count("1") - 1) ) elif s[0][-1] == "0": print(1 + s[0].count("1") + n * l2[1:].count("1") + l3[1:].count("1")) else: l1 = bin(int(s[0], 2) + 1)[2:] print(l1.count("1") + n * l2[1:].count("1") + l3[1:].count("1"))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER STRING BIN_OP VAR FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING BIN_OP VAR FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR STRING IF VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER STRING BIN_OP VAR FUNC_CALL VAR NUMBER STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER IF VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER STRING BIN_OP VAR FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP VAR FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER STRING
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for _ in range(int(input())): l1, l2, l3, n = [i for i in input().split()] n = int(n) if l3.find("0") == -1: if l2.find("0") == -1: if l1.find("0") == -1: print(1) else: s = l1[::-1] for i in range(len(s)): if s[i] == "0": s = s[i:] break print(s.count("1") + 1) else: s = l2[::-1] cnt = 0 for i in range(len(s)): if s[i] == "0": s = s[i:] break else: cnt += 1 print(l2.count("1") * n + l1.count("1") - cnt + 1) else: s = l3[::-1] for i in range(len(s)): if s[i] == "0": s = s[i:] break print(s.count("1") + l1.count("1") + l2.count("1") * n + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for _ in range(int(input())): l1, l2, l3, n = [x for x in input().split()] allOne = 0 count = 0 last = len(l3) - 1 countl3 = l3.count("1") countl2 = l2.count("1") countl1 = l1.count("1") totalOne = countl1 + countl2 * int(n) + countl3 if len(l3) == countl3: count += countl3 allOne = 1 else: while l3[last] == "1" and last >= 0: count += 1 last -= 1 if allOne == 1: if len(l2) == countl2: count += countl2 * int(n) else: allOne = 0 last = len(l2) - 1 while l2[last] == "1" and last >= 0: count += 1 last -= 1 if allOne == 1: if len(l1) == countl1: count += countl1 else: allOne = 0 last = len(l1) - 1 while l1[last] == "1" and last >= 0: count += 1 last -= 1 print(totalOne + 1 - count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
for t in range(int(input())): s, s1, s2, n = [i for i in input().split()] sf = s co = 0 l = len(s) l1 = len(s1) l2 = len(s2) ns = s.count("1") ns1 = s1.count("1") ns2 = s2.count("1") co = ns + ns1 * int(n) + ns2 if s2[l2 - 1] == "0": co += 1 elif co == l + l1 * int(n) + l2: co = 1 else: f = 1 if ns2 > 0: if ns2 == l2: co -= ns2 else: for i in s2[::-1]: if i == "0": f = 0 co += 1 break co -= 1 else: co += 1 f = 0 if f == 1: if ns1 > 0: if ns1 == l1: co -= ns1 * int(n) else: for i in s1[::-1]: if i == "0": f = 0 co += 1 break co -= 1 else: co += 1 f = 0 if f == 1: if ns > 0: if ns == l: co -= ns else: for i in s[::-1]: if i == "0": f = 0 co += 1 break co -= 1 else: co += 1 f = 0 print(co)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR FOR VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR FOR VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) while t > 0: l = ["", "", ""] c = 1 l1, l2, l3, n = input().split(" ") n = int(n) a1, b1, c1 = l1.count("1"), l2.count("1"), l3.count("1") a0, b0, c0 = l1.count("0"), l2.count("0"), l3.count("0") if c0 == 0: if b0 == 0: if a0 == 0: print(1) else: i = len(l1) - 1 while i >= 0 and l1[i] == "1": i = i - 1 while i >= 0: if l1[i] == "1": c = c + 1 i = i - 1 print(c) else: i = len(l2) - 1 while i >= 0 and l2[i] == "1": i = i - 1 while i >= 0: if l2[i] == "1": c = c + 1 i = i - 1 print(c + a1 + b1 * (n - 1)) else: i = len(l3) - 1 while i >= 0 and l3[i] == "1": i = i - 1 while i >= 0: if l3[i] == "1": c = c + 1 i = i - 1 print(c + a1 + b1 * n) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) count = [] for i in range(t): s = input() a, b, c, n = s.split() n = int(n) d = int(a + b * n + c, 2) count.append(0) while d > 0: d = (d & d + 1) - 1 count[i] += 1 for i in range(t): print(count[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
def returnIndexAfterContinuousOnes(s): l = len(s) i = l - 1 while i >= 0 and s[i] == "1": i -= 1 return i def returnCountOfOnes(s, j): i = j sum = 0 while i >= 0: if s[i] == "1": sum += 1 i -= 1 return sum t = int(input()) for xyz in range(t): inp = str(input()).split() l1 = inp[0] l2 = inp[1] l3 = inp[2] n = int(inp[3]) len3 = len(l3) i = len3 - 1 ans = 1 chk = returnIndexAfterContinuousOnes(l3) if chk == -1: chk = returnIndexAfterContinuousOnes(l2) if chk == -1: chk = returnIndexAfterContinuousOnes(l1) if chk == -1: ans += 0 else: ans += returnCountOfOnes(l1, chk) else: ans += ( returnCountOfOnes(l2, chk) + returnCountOfOnes(l2, len(l2) - 1) * (n - 1) + returnCountOfOnes(l1, len(l1) - 1) ) else: ans += ( returnCountOfOnes(l3, chk) + returnCountOfOnes(l2, len(l2) - 1) * n + returnCountOfOnes(l1, len(l1) - 1) ) print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) while t: a, b, c, d = input().split() d = int(d) an = a.count("1") + b.count("1") * d + c.count("1") lc = len(c) lb = len(b) la = len(a) cc = 0 cb = 0 ca = 0 for i in range(lc - 1, -1, -1): if c[i] == "0": break else: cc += 1 if cc == lc: for i in range(lb - 1, -1, -1): if b[i] == "0": break else: cb += 1 if cb == lb: for i in range(la - 1, -1, -1): if a[i] == "0": break else: ca += 1 if ca == la: print(1) else: print(an - cc - cb * d - (ca - 1)) else: print(an - cc - (cb - 1)) else: print(an - (cc - 1)) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data structure is also well known for its low memory usage. To be more precise, it needs exactly the same amount of memory as that of array. Given some array A, first we build data structure in some other array T. Ti stores the sum of the elements Astart, Astart + 1, ..., Ai. Index start is calculated with formula start = Fdown(i) = (i & (i + 1)). Here "&" denotes bitwise AND operation. So, in order to find a sum of elements A0, A1, ..., AL you start with index L and calculate sum of TL + TFdown(L)-1 + TFdown(Fdown(L)-1)-1 + ... + TFdown(Fdown(...(Fdown(L)-1)-1)-1. Usually it is performed with cycle that goes from L down to 0 with function Fdown and sums some elements from T. Chef wants to verify that the time complexity to calculate sum of A0, A1, A2, ..., AL is O(log L). In order to do so, he wonders how many times he has to access array T to calculate this sum. Help him to find this out. Since Chef works with really big indices. The value of L can be very large and is provided to you in binary representation as concatenation of strings L1, L2 repeated N times and string L3. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three non-empty strings L1, L2, L3 and an integer N. Strings will contain only characters 0 and 1. To obtain binary representation of index L concatenate L1 with L2 repeated N times and with L3. You are guaranteed that the index will be positive. -----Output----- For each test case, output a single line containing number of times Fenwick tree data structure will access array T in order to compute sum of A0, A1, A2, ..., AL. -----Constraints----- - 1 ≤ T ≤ 300 - 1 ≤ Length(Li) ≤ 1000 - 1 ≤ N ≤ 106 -----Subtasks----- - Subtask #1 (20 points): |L1| + |L2| * N + |L3| ≤ 60 - Subtask #2 (30 points): 1 ≤ T ≤ 30, 1 ≤ N ≤ 100 - Subtask #3 (50 points): No additional constraints -----Example----- Input: 4 001 100 011 4 1000 1101 100 3 1010 001 101 4 010 101 000 4 Output: 6 12 8 10
t = int(input()) while t > 0: l1, l2, l3, n = map(str, input().split()) n = int(n) a = bin(int(l3, 2) + 1) if len(a) > len(l3) + 2: a = bin(int(l2, 2) + 1) if len(a) > len(l2) + 2: a = bin(int(l1, 2) + 1) if len(a) > len(l1) + 2: print(1) else: print(a.count("1")) else: print(l2.count("1") * (n - 1) + a.count("1") + l1.count("1")) else: print(a.count("1") + l2.count("1") * n + l1.count("1")) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR NUMBER
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
t = int(input()) for _ in range(t): n, A = map(int, input().split()) if n == 1: if A & 1: print("Odd") else: print("Even") continue if A & 1 == 0: print("Impossible") continue if n & 1: print("Odd") else: print("Even")
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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
for _ in range(int(input())): n, a = map(int, input().split()) if a % 2: if n % 2: print("Odd") else: print("Even") elif n == 1: print("Even") else: print("Impossible")
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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
for a0 in range(int(input())): n, k = list(map(int, input().split())) if n == 1: if k % 2 == 0: print("Even") else: print("Odd") elif k % 2 == 1: if n % 2 == 0: print("Even") else: print("Odd") else: print("Impossible")
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 IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
num = int(input()) def answer(integer): if integer % 2 == 0: print("Even") else: print("Odd") while num: num -= 1 a1 = input().split() n, a = int(a1[0]), int(a1[1]) if n == 1: answer(a) continue if a % 2 == 0: print("Impossible") else: answer(n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
T = int(input()) for i in range(T): N, A = input().split() N = eval(N) A = eval(A) if A % 2 != 0: if N % 2 == 0: print("Even") else: print("Odd") elif N == 1: print("Even") else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
t = input() for c in range(0, int(t)): n, a = map(int, input().split()) if n == 1: if a % 2 == 1: print("Odd") elif a % 2 == 0: print("Even") elif n % 2 == 0: if a % 2 == 1: print("Even") else: print("Impossible") elif a % 2 == 1: print("Odd") else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
t = int(input()) for _ in range(t): n, a = list(map(int, input().split())) if n == 1: print("Odd" if a % 2 else "Even") else: x = a % 10 if x == 0 or x % 2 == 0: print("Impossible") else: print("Odd" if n % 2 else "Even")
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 IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
for _ in range(int(input())): n, a = [int(i) for i in input().split()] if n % 2 == 0 and a & 1 == 1 or n == 1 and a & 1 == 0: print("Even") elif n % 2 != 0 and a & 1 == 1: print("Odd") else: print("Impossible")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
for i in range(int(input())): N, A = map(int, input().split()) BinS = bin(A)[2:] if BinS[len(BinS) - 1] == "1": if N % 2 == 0: print("Even") else: print("Odd") elif N == 1: if A % 2 == 0: print("Even") else: print("Odd") else: print("Impossible")
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 NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
for _ in range(int(input())): d = {(1): "Odd", (0): "Even"} n, a = map(int, input().split()) if a % 2 != 0 or n <= 2: if n <= 2: print(d[a % 2]) else: print(d[n % 2]) else: print("Impossible")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER STRING STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
t = int(input()) for i in range(t): n, a = [int(x) for x in input().split()] if a & 1 == 1: if n & 1 == 1: result = "Odd" else: result = "Even" elif n == 1: result = "Even" else: result = "Impossible" print(result)
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 NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
t = int(input()) while t: n, a = map(int, input().split()) if a % 2 == 1: if n % 2 == 0: print("Even") else: print("Odd") elif a % 2 == 0: if n == 1: print("Even ") else: print("Impossible") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only line of each test case contains two space-separated integers N and A - the number of elements in the hidden array and the bitwise AND of all the elements in the hidden array. ------ Output Format ------ For each test case, output Even if the sum of all elements in the hidden array is even, Odd if the sum of all elements in the hidden array is odd, or Impossible if the parity cannot be determined. Note: You may print each character of the string in uppercase or lowercase (for example, the strings eVen, EvEn, even and EVEN will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 10000$ $1 ≤ N ≤ 10^{9}$ $0 ≤ A ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 11 1 2 74120341 829182732 ----- Sample Output 1 ------ Odd Even Impossible
def solve(n, a): if n == 1: if a & 1: return "Odd" else: return "Even" val = a & 1 if val == 1: return "Even" if n % 2 == 0 else "Odd" else: return "Impossible" for _ in range(int(input())): n, a = map(int, input().split()) print(solve(n, a))
FUNC_DEF IF VAR NUMBER IF BIN_OP VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER STRING STRING RETURN STRING 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
Consider an array, $\mbox{A}$, of $n$ integers ($A=a_0,a_1,...,a_{n-1}$). We take all consecutive subsequences of integers from the array that satisfy the following: $\{a_i,a_{i+1},\ldots,a_{j-1},aj\},\text{where}\ 0\leq i\leq j<n$ For example, if $n=3$ our subsequences will be: $\boldsymbol{a_0}$ $a_1$ $a_2$ $a_{0},a_{1}$ $a_{1},a_{2}$ $a_{0},a_{1},a_{2}$ For each subsequence, we apply the bitwise XOR ($\oplus$) operation on all the integers and record the resultant value. Since there are $n\times\frac{(n+1)}{2}$ subsequences, this will result in $n\times\frac{(n+1)}{2}$ numbers. Given array $\mbox{A}$, find the XOR sum of every subsequence of $\mbox{A}$ and determine the frequency at which each number occurs. Then print the number and its respective frequency as two space-separated values on a single line. Input Format The first line contains an integer, $n$, denoting the size of the array. Each line $\boldsymbol{i}$ of the $n$ subsequent lines contains a single integer describing element $a_i$. Constraints $1\leq n\leq10^5$ $1\leq a_i<2^{16}$ Output Format Print $2$ space-separated integers on a single line. The first integer should be the number having the highest frequency, and the second integer should be the number's frequency (i.e., the number of times it appeared). If there are multiple numbers having maximal frequency, choose the smallest one. Sample Input 0 4 2 1 1 3 Sample Output 0 1 3 Explanation 0 Let's find the XOR sum for all consecutive subsequences. We'll refer to the frequency of some number $\boldsymbol{x}$ as $f(x)$, and keep a running sum for each frequency: $2=2$, frequencies: $f(2)=1$ $1=1$, frequencies: $f(1)=1$ and $f(2)=1$ $1=1$, frequencies: $f(1)=2$ and $f(2)=1$ $3=3$, frequencies: $f(1)=2$, $f(2)=1$, and $f(3)=1$ $2\oplus1=3$, frequencies: $f(1)=2$, $f(2)=1$, and $f(3)=2$ $1\oplus1=0$, frequencies: $f(0)=1$, $f(1)=2$, $f(2)=1$, and $f(3)=2$ $1\oplus3=2$, frequencies: $f(0)=1$, $f(1)=2$, $f(2)=2$, and $f(3)=2$ $2\oplus1\oplus1=2$, frequencies: $f(0)=1$, $f(1)=2$, $f(2)=3$, and $f(3)=2$ $1\oplus1\oplus3=3$, frequencies: $f(0)=1$, $f(1)=2$, $f(2)=3$, and $f(3)=3$ $2\oplus1\oplus1\oplus3=1$, frequencies: $f(0)=1$, $f(1)=3$, $f(2)=3$, and $f(3)=3$ Our maximal frequency is $3$, and the integers $1$, $2$, and $3$ all have this frequency. Because more than one integer has this frequency, we choose the smallest one, which is $1$. We then print the respective smallest number having the maximal frequency and the maximal frequency as a single line of space-separated values.
def fwht(a): h = 1 while h < len(a): for i in range(0, len(a), h << 1): for j in range(i, i + h): k = j + h x = a[j] y = a[k] a[j] = x + y a[k] = x - y h <<= 1 n = int(input()) bits = 16 a = [0] * (1 << bits) a[0] = 1 xor = 0 for i in range(n): xor ^= int(input()) a[xor] += 1 fwht(a) for i in range(len(a)): a[i] *= a[i] fwht(a) bits += 1 best = 1 high = a[1] >> bits for i in range(2, len(a)): x = a[i] >> bits if x > high: high = x best = i print(best, high)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR
Consider an array, $\mbox{A}$, of $n$ integers ($A=a_0,a_1,...,a_{n-1}$). We take all consecutive subsequences of integers from the array that satisfy the following: $\{a_i,a_{i+1},\ldots,a_{j-1},aj\},\text{where}\ 0\leq i\leq j<n$ For example, if $n=3$ our subsequences will be: $\boldsymbol{a_0}$ $a_1$ $a_2$ $a_{0},a_{1}$ $a_{1},a_{2}$ $a_{0},a_{1},a_{2}$ For each subsequence, we apply the bitwise XOR ($\oplus$) operation on all the integers and record the resultant value. Since there are $n\times\frac{(n+1)}{2}$ subsequences, this will result in $n\times\frac{(n+1)}{2}$ numbers. Given array $\mbox{A}$, find the XOR sum of every subsequence of $\mbox{A}$ and determine the frequency at which each number occurs. Then print the number and its respective frequency as two space-separated values on a single line. Input Format The first line contains an integer, $n$, denoting the size of the array. Each line $\boldsymbol{i}$ of the $n$ subsequent lines contains a single integer describing element $a_i$. Constraints $1\leq n\leq10^5$ $1\leq a_i<2^{16}$ Output Format Print $2$ space-separated integers on a single line. The first integer should be the number having the highest frequency, and the second integer should be the number's frequency (i.e., the number of times it appeared). If there are multiple numbers having maximal frequency, choose the smallest one. Sample Input 0 4 2 1 1 3 Sample Output 0 1 3 Explanation 0 Let's find the XOR sum for all consecutive subsequences. We'll refer to the frequency of some number $\boldsymbol{x}$ as $f(x)$, and keep a running sum for each frequency: $2=2$, frequencies: $f(2)=1$ $1=1$, frequencies: $f(1)=1$ and $f(2)=1$ $1=1$, frequencies: $f(1)=2$ and $f(2)=1$ $3=3$, frequencies: $f(1)=2$, $f(2)=1$, and $f(3)=1$ $2\oplus1=3$, frequencies: $f(1)=2$, $f(2)=1$, and $f(3)=2$ $1\oplus1=0$, frequencies: $f(0)=1$, $f(1)=2$, $f(2)=1$, and $f(3)=2$ $1\oplus3=2$, frequencies: $f(0)=1$, $f(1)=2$, $f(2)=2$, and $f(3)=2$ $2\oplus1\oplus1=2$, frequencies: $f(0)=1$, $f(1)=2$, $f(2)=3$, and $f(3)=2$ $1\oplus1\oplus3=3$, frequencies: $f(0)=1$, $f(1)=2$, $f(2)=3$, and $f(3)=3$ $2\oplus1\oplus1\oplus3=1$, frequencies: $f(0)=1$, $f(1)=3$, $f(2)=3$, and $f(3)=3$ Our maximal frequency is $3$, and the integers $1$, $2$, and $3$ all have this frequency. Because more than one integer has this frequency, we choose the smallest one, which is $1$. We then print the respective smallest number having the maximal frequency and the maximal frequency as a single line of space-separated values.
M = 1 << 16 def FWHT(V, inv=False): H = 1 while H < M: for L in range(0, M, 2 * H): for I in range(H): X = V[L + I] Y = V[L + H + I] V[L + H + I] = X - Y V[L + I] = X + Y if inv: V[L + H + I] >>= 1 V[L + I] >>= 1 H <<= 1 N = int(input()) A = [] for _ in range(N): A.append(int(input())) B = [0] for E in A: B.append(B[-1] ^ E) CNT = [0] * (1 << 16) for E in B: CNT[E] += 1 FWHT(CNT) for i in range(len(CNT)): CNT[i] *= CNT[i] FWHT(CNT, True) Y = 0 X = -1 for i in range(1, len(CNT)): if CNT[i] > Y: X = i Y = CNT[i] print(X, Y // 2)
ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
T = int(input()) for _ in range(T): A, B = map(int, input().split()) i = 0 while 2**i < B - A: i += 1 ans = A & B & (4294967295 ^ 2**i - 1) 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 NUMBER WHILE BIN_OP NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
import sys __author__ = "mtadmk" def pr(a): if db: print(a) def process(a, b): act = a & b num = 1 while a + num < b: act &= a + num num *= 2 return act db = False if not db: n = int(input()) for i in range(0, n): a, b = list(map(int, input().split())) print(process(a, b)) else: print(process(12, 15)) print(process(2, 3)) print(process(8, 13))
IMPORT ASSIGN VAR STRING FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def and_product(fst, secnd): fst = list(bin(fst))[2:] secnd = list(bin(secnd))[2:] if len(fst) != len(secnd): return 0 num = 0 same = True for ind in range(len(fst)): num *= 2 same &= fst[ind] == secnd[ind] if same: num += int(fst[ind]) return num numtests = int(input()) for _ in range(numtests): print(and_product(*[int(s) for s in input().split()]))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def main(): for _ in range(int(input())): A, B = map(int, input().split()) A = bin(A)[2:] B = bin(B)[2:] answer = "" A = "0" * (32 - len(A)) + A B = "0" * (32 - len(B)) + B for i in range(32): if A[i] != B[i]: break answer += A[i] answer = answer + "0" * (32 - i) temp = 0 for x in answer: if x == "1": break print(int(answer, base=2)) main()
FUNC_DEF 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
for _ in range(int(input())): a, b = (int(f) for f in input().split()) result = 0 bit = 1 while bit <= b: if bit & a & b: result |= bit elif bit & a != bit & b: result = 0 bit <<= 1 print(result)
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 NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
t = int(input()) for i in range(t): a, b = [int(x) for x in input().split()] x = a ^ b s = x >> 1 while s != 0: x = x | s s >>= 1 print(a & b & ~x)
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 BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
a = 0 b = 0 c = 0 result = 0 current = 0 for i in range(0, int(input())): a, b = input().split() c = 0 while int(a) | c < int(b): c = c << 1 | 1 result = int(a) & ~c print(result)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def calc_and(a, b): result = 0 distance = b - a + 1 for i in range(0, 32): if distance <= 1 << i: mask = 1 << i if a & mask == b & mask: result = result | a & mask return result def main(): T = int(input()) for t in range(0, T): var = input().split() a = int(var[0]) b = int(var[1]) print(calc_and(a, b)) main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def bitLen(int_type): length = 0 while int_type: int_type >>= 1 length += 1 return length T = int(input()) for j in range(T): A, B = input().split(" ") A = int(A) B = int(B) result = 0 lengthA = bitLen(A) lengthB = bitLen(B) while lengthA == lengthB: temp = 1 for i in range(lengthA - 1): temp <<= 1 result |= temp A = A & ~temp B = B & ~temp lengthA = bitLen(A) lengthB = bitLen(B) print(result)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
T = int(input()) for _ in range(T): A, B = (bin(int(i))[2:] for i in input().split()) max_length = max(len(A), len(B)) A, B = (x.zfill(max_length) for x in (A, B)) i = 0 result = "" while i < max_length and A[i] == B[i]: result += A[i] i += 1 result += "0" * (max_length - i) print(int(result, 2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
for _ in range(int(input())): A, B = [int(i) for i in input().split()] v = A ^ B v |= v >> 1 v |= v >> 2 v |= v >> 4 v |= v >> 8 v |= v >> 16 print(A & ~v)
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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def run(a, b): if len(bin(b)) > len(bin(a)): return 0 d = len(bin(b - a)) - 2 a_, b_ = int(bin(a)[:-d], 2), int(bin(b)[:-d], 2) s = a_ for x in range(a_ + 1, b_ + 1): s &= x return s * 2**d for _ in range(int(input())): a, b = [int(x) for x in input().split()] print(run(a, b))
FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR BIN_OP NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
t = int(input()) for uuhhhj in range(t): a = [int(i) for i in input().split()] p = bin(a[0]) q = bin(a[1]) m = min(len(p), len(q)) - 2 p = p[-m:] q = q[-m:] s = "0b" t = 0 for i in range(m): if p[i] != q[i] or t == 1: t = 1 s += "0" else: s += p[i] print(int(s, 2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
t = int(input().strip()) while t > 0: a, b = [int(i) for i in input().strip().split(" ")] count = 1 while a != b: a = int(a / 2) b = int(b / 2) count *= 2 t -= 1 print(int(count * a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def reduce_and(a, b): bits_to_ignore = (a - b).bit_length() - 1 mask = 2**bits_to_ignore - 1 a |= mask a ^= mask interval = 2**bits_to_ignore result = a for val in range(a, b + 1, interval): result &= val return result count = int(input()) for i in range(count): a, b = [int(x) for x in input().split(" ")] print(reduce_and(a, b))
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def my_bin(n, length=32): t = str(bin(n))[2:] ans = "0" * (length - len(t)) + t return ans for t in range(int(input())): a, b = [int(i) for i in input().split()] a = my_bin(a) b = my_bin(b) ans = [0] * 32 for i in range(32): if a[i] == b[i]: ans[i] = a[i] else: break s = "" for i in ans: s += str(i) print(int(s, 2))
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def solve(A, B): if A == B: return A a, b, i, j = A, B, 0, 0 while a > 0 or b > 0: if (a ^ b) & 1: j = i a >>= 1 b >>= 1 i += 1 return A & -(2**j) T = int(input()) for _ in range(T): A, B = (int(_) for _ in input().split()) print(solve(A, B))
FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR BIN_OP 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
for T in range(int(input())): A, B = map(int, input().split()) ans = 0 for i in range(32): k = A + (1 << i) >> i if k << i >= B + 1 and k & 1 == 0: ans |= 1 << i print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def min_and(a, b): for i in range(a.bit_length(), -1, -1): mask = 2**i if a & mask != b & mask: return sum(a & 2**j for j in range(i + 1, a.bit_length())) return a & a + 1 test_cases = int(input().strip()) for _ in range(test_cases): a, b = [int(n) for n in input().strip().split()] if a.bit_length() != b.bit_length(): result = 0 else: result = min_and(a, b) print(result)
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
import sys n = int(sys.stdin.readline().strip()) for i in range(n): cl = [int(num) for num in sys.stdin.readline().strip().split(" ")] x = 0 while cl[0] | x < cl[1]: x = x << 1 | 1 print(cl[0] & ~x)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
t = int(input()) for w in range(t): start, end = list(int(i) for i in input().split()) testLow = int.bit_length(start) testHigh = int.bit_length(end) if testHigh > testLow: print(0) else: result = start shift = 0 while start <= end: while start & 1 == 0: start >>= 1 end >>= 1 result >>= 1 shift += 1 result &= start start += 1 print(result << shift)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
for _ in range(int(input())): a, b = [int(i) for i in input().strip().split()] diff = b - a n = 0 while diff: diff >>= 1 n += 1 res = (a & b) >> n << n print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def and_product(a, b): l1 = len(a) l2 = len(b) b = b[l2 - l1 :] i = 0 res = "" while a[i] == b[i]: res += a[i] i += 1 res += "0" * (l1 - i) return btd(res) def dtb(n): ans = "" while n != 0: ans += str(n % 2) n = n // 2 return ans[::-1] def btd(S): num = 0 l = len(S) for i in range(l - 1, -1, -1): if S[i] == "1": num += int(pow(2, l - 1 - i)) return num t = int(input()) for i in range(t): a, b = [int(j) for j in input().split()] if a * b == 0: print("0") else: print(and_product(dtb(a), dtb(b)))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP STRING BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
T = int(input()) for _ in range(T): A, B = map(lambda x: bin(int(x)), input().split()) ans = "" for ind, digit in enumerate(A): if ind < 2: continue if digit == B[ind]: ans += digit else: ans += "0" * (len(B) - ind) break print(int(ans, 2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
author = "Ashu" tc = int(input()) for _ in range(tc): x = input().split() a = int(x[0]) b = int(x[1]) r = 0 while a | r < b: r = r << 1 | 1 print(a & ~r)
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def and_product(start, end): result = start steps = end - start i = 0 while start >> i > 0: if lmask(start, i + 1) + steps > lmask(-1, i + 1): result = bitmask(result, i) i += 1 return result def lmask(n, k): return n & (1 << k) - 1 def bitmask(n, k): return n & (-1 << k + 1 | lmask(-1, k)) def main(): k = int(input()) for _ in range(k): start, end = input().split() print(and_product(int(start), int(end))) main()
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
T = int(input()) for _ in range(T): l, r = [int(i) for i in input().split()] x1 = x2 = l ^ r while x1: x1 >>= 1 l >>= 1 while x2: x2 >>= 1 l <<= 1 print(l)
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 VAR BIN_OP VAR VAR WHILE VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def calc(a, b): if a == 0 and b == 0: return 0 if a == 1 and b == 1: return 1 res = "0" for i in range(1, 32): if 2**i & a > 0: if b >= a + 2**i: res = "0" + res else: res = "1" + res else: res = "0" + res return int(res, 2) t = int(input()) for _ in range(t): a, b = [int(x) for x in input().split()] print(calc(a, b))
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR RETURN FUNC_CALL VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
t = int(input()) for _ in range(t): a, b = map(int, input().split()) result = 1 aBinary, bBinary = bin(a)[2:], bin(b)[2:] aBinary = "0" * (len(bBinary) - len(aBinary)) + aBinary result = "" for i in range(len(aBinary)): if aBinary[i] == bBinary[i]: result += aBinary[i] else: result += "0" break i += 1 result = result + "0" * (len(bBinary) - i) print(int(result, 2))
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 VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
t = int(input()) for i in range(0, t): s = input() ss = s.split(" ") a = int(ss[0]) b = int(ss[1]) pow = 0 while 1: if 2**pow > a: break else: pow = pow + 1 if 2**pow > b and 2 ** (pow - 1) < b: aa = "{0:b}".format(a) bb = "{0:b}".format(b) if len(aa) < len(bb): str_add = "" for ii in range(0, len(bb) - len(aa)): str_add = str_add + "0" aa = aa + str_add if len(aa) > len(bb): str_add = "" for ii in range(0, len(aa) - len(bb)): str_add = str_add + "0" bb = bb + str_add fin_ans = "" for ii in range(0, len(aa)): if aa[ii] == bb[ii]: fin_ans = fin_ans + aa[ii] else: break for ii in range(0, len(aa) - len(fin_ans)): fin_ans = fin_ans + "0" print(int(fin_ans, 2)) else: print("0")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
T = int(input()) for _ in range(T): A, B = [int(x) for x in input().split()] a = bin(A)[2:] b = bin(B)[2:] if len(a) != len(b): print(0) else: i = 0 while i < len(a): if a[i] != b[i]: break i += 1 c = a[:i] while len(c) != len(a): c += "0" print(int(c, 2))
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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
T = int(input()) for _ in range(T): A, B = (int(_) for _ in input().split()) i, C = -1, A ^ B while C > 0: C >>= 1 i += 1 print(A & 2**32 - 2**i)
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 VAR NUMBER BIN_OP VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
for _ in range(int(input())): a, b = list(map(int, input().split())) a, b = bin(a)[2:], bin(b)[2:] if len(a) != len(b): print(0) else: res = 0 for i in range(len(a)): if a[i] == b[i] == "1": res |= 1 << len(a) - i - 1 elif a[i] == "0" and b[i] == "1": break print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
for t in range(int(input())): a, b = map(int, input().split()) answer = a for i in range(32): d = 1 << i if a & d and (not b & d or b - a >= d): answer ^= d print(answer)
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 FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
n = int(input()) while n > 0: n -= 1 numbers = input().split() numbers = [int(x) for x in numbers] a = numbers[0] b = numbers[1] ans = 0 i = 31 while i >= 0: temp = 1 temp = temp << i i -= 1 if a & temp != 0 and b & temp == 0: break elif a & temp == 0 and b & temp != 0: break elif a & temp != 0 and b & temp != 0: ans = ans | 1 << i + 1 else: continue print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
T = int(input()) for _ in range(T): A, B = tuple([int(token) for token in input().split()]) diff = A ^ B diff = diff | diff >> 1 diff = diff | diff >> 2 diff = diff | diff >> 4 diff = diff | diff >> 8 diff = diff | diff >> 16 R = A & B & ~diff print(R)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
for _ in range(int(input())): l, h = [bin(int(x))[2:] for x in input().split()] if len(l) != len(h): print(0) elif l == h: print(int(l, 2)) else: for i in range(1, len(l)): if l[i] != h[i]: print(int(l[:i] + "0" * (len(l) - i), 2)) break
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR VAR NUMBER
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
t = int(input()) for k in range(t): a, b = map(int, input().split(" ")) x = 0 while a | x < b: x <<= 1 x |= 1 print(a & ~x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def and_product(a, b): b_str = bin(b)[2:] a_str = bin(a)[2:].zfill(len(b_str)) result = [] for i in range(len(b_str)): if a_str[i] == b_str[i]: result.append(b_str[i]) else: break while len(result) != len(b_str): result.append("0") return int("".join(result), 2) t = int(input()) for _ in range(t): a, b = tuple(map(int, input().split())) print(and_product(a, b))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def andpro(A, B): lenA = len("{0:b}".format(A)) lenB = len("{0:b}".format(B)) if lenA == lenB: i = 0 strA = "{0:b}".format(A) strB = "{0:b}".format(B) curr = "" for i in range(lenA): if strA[i] == strB[i]: curr += strA[i] else: break curr = curr + "0" * (lenA - len(curr)) print(int(curr, 2)) return else: print("0") return t = int(input()) for _ in range(t): A, B = [int(x) for x in input().strip().split(" ")] andpro(A, B)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR STRING RETURN 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 FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
def andProduct(A, B): shift_amount = 0 while A != B: A = A >> 1 B = B >> 1 shift_amount += 1 return A << shift_amount T = int(input()) for _ in range(T): A, B = map(int, input().split(" ")) print(andProduct(A, B))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER 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
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given $n$ pairs of long integers, $a[i]$ and $b[i]$, compute and print the bitwise AND of all natural numbers in the inclusive range between $a[i]$ and $b[i]$. For example, if $\boldsymbol{a=10}$ and $b=14$, the calculation is $10\:\text{&}\:11\:\text{&}\:12\:\text{&}\:13\:\text{&}\:14=8$. Function Description Complete the andProduct in the editor below. It should return the computed value as an integer. andProduct has the following parameter(s): a: an integer b: an integer Input Format The first line contains a single integer $n$, the number of intervals to test. Each of the next $n$ lines contains two space-separated integers $a[i]$ and $b[i]$. Constraints $1\leq n\leq200$ $0\leq a[i]\leq b[i]<2^{32}$ Output Format For each pair of long integers, print the bitwise AND of all numbers in the inclusive range between $a[i]$ and $b[i]$ on a new line. Sample Input 0 3 12 15 2 3 8 13 Sample Output 0 12 2 8 Explanation 0 There are three pairs to compute results for: $\boldsymbol{a=12}$ and $\boldsymbol{b=15}$ $12~\text{&}~13~\text{&}~14~\text{&}~15~=12$, so we print $12$ on a new line. $\boldsymbol{a}=2$ and $b=3$ $2\&3=2$ $\boldsymbol{a}=8$ and $b=13$ $8\:\text{&}\:9\:\text{&}\:10\:\text{&}\:11\:\text{&}\:12\&\:13\:=8$ Sample Input 1 2 17 23 11 15 Sample Output 1 16 8
T = int(input()) while T: A, B = map(int, input().split()) if A == B: print(A) T -= 1 continue a, b = map(bin, (A, B)) dif = len(bin(B - A)[2:]) a, b = a[2:], b[2:] x, y = len(a), len(b) if y > x: print(0) T -= 1 continue ret = "0" * dif for z in range(dif + 1, x + 1): if a[-z] == "1" and b[-z] == "1": ret = "1" + ret else: ret = "0" + ret print(int(ret, 2)) T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER