description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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(0, T): S, L = map(int, input().split()) if S == 0 or L == 0: print(0) continue S = "{0:032b}".format(S) L = "{0:032b}".format(L) S = list(S) L = list(L) S.reverse() L.reverse() s = S.pop() l = L.pop() while s != "1" and l != "1" and S: s = S.pop() l = L.pop() ans = [] if len(S) > 0: ans.append("1") s = S.pop() l = L.pop() while s == l and S: ans.append(s) s = S.pop() l = L.pop() ans.append("0") for i in S: ans.append("0") print(int("".join(ans), 2)) else: print(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL 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 = map(int, input().split()) N = A.bit_length() if N == B.bit_length(): A, B = str(bin(A))[2:], str(bin(B))[2:] for i in range(N): if not A[i] == B[i]: print(int(A[:i] + "0" * (N - i), 2)) break else: print(0)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR 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 VAR VAR NUMBER EXPR FUNC_CALL 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 = map(int, input().split()) x = 0 while a | x < b: x = x + x | 1 print(a & ~x)
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 WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP 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
import sys t = int(sys.stdin.readline().strip()) for tests in range(t): a, b = [int(x) for x in sys.stdin.readline().split()] msb_a = 0 msb_b = 0 mask = 1 << 31 a_test = True b_test = True if a == 0: msb_a = 0 a_test = False if b == 0: msb_b = 0 b_test = False while a_test or b_test: if mask & a != 0: msb_a = mask a_test = False if mask & b != 0: msb_b = mask b_test = False mask = mask >> 1 if msb_b > msb_a: print(0) elif a % 2 == 0: print(a) else: print(msb_a)
IMPORT 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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR 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()) while t != 0: t -= 1 l, u = map(int, input().split()) s1 = "{0:032b}".format(l) s2 = "{0:032b}".format(u) s = [0] * 32 i = 0 flag = False ans = 0 while i < 32: if s2[i] == "1" and s1[i] == "1": s[i] = 1 flag = True if flag == True and ( s1[i] == "1" and s2[i] == "0" or s1[i] == "0" and s2[i] == "1" ): break i += 1 i = 0 s.reverse() while i != 32: ans += s[i] * pow(2, i) i += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR 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().strip()) for t in range(0, T): a, b = list(map(int, input().strip().split(" "))) A, B = [bin(a)[2:], bin(b)[2:]] alen, blen = len(A), len(B) if alen < blen: print(0) else: s = "" found = False for i in range(0, alen): if found: s += "0" elif A[i] == "0": if B[i] == "1": found = True s += "0" else: s += "1" bwAND = int(s, 2) print(bwAND)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR 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
for t in range(int(input())): a, b = sorted(map(int, input().split())) bits = ["0"] * (a.bit_length() + 1) for k in range(a.bit_length()): twoP = 1 << k if a & twoP and b < (a // twoP + 1) * twoP: bits[~k] = "1" ans = "".join(bits) print(int(ans, 2))
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 BIN_OP LIST STRING BIN_OP FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING 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
import sys T = int(input().strip()) def ANDproduct(A, B): s = (B ^ A).bit_length() B = B >> s B = B << s return B for t in range(T): arr = [int(arr_temp) for arr_temp in input().strip().split(" ")] print(ANDproduct(arr[0], arr[1]))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER 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
numcases = int(input()) for _ in range(numcases): min, max = [int(x) for x in input().split()] reverseDigits = [] for i in range(32): place = pow(2, i) if place > max: break if min // place == max // place and min // place % 2 == 1: reverseDigits.append("1") else: reverseDigits.append("0") print(int("".join(reversed(reverseDigits)), 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 LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING 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 longest_common_prefix(seq1, seq2): start = 0 while start < min(len(seq1), len(seq2)): if seq1[start] != seq2[start]: break start += 1 return seq1[:start] t = int(input()) while t: s = input().split() a, b = int(s[0]), int(s[1]) x = bin(a)[2:] y = bin(b)[2:] if len(x) < len(y): c = len(y) - len(x) while c: x = "0" + x c -= 1 if len(y) < len(x): c = len(x) - len(y) while c: y = "0" + y c -= 1 z = longest_common_prefix(x, y) if z == "": print("0") else: c = len(x) - len(z) while c: z = z + "0" c -= 1 print(int(z, 2)) t -= 1
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR BIN_OP STRING VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR BIN_OP VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER 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 next_all_ones(n): n -= 1 for k in (1, 2, 4, 8, 16, 32, 64): n |= n >> k return n for _ in range(int(input())): a, b = list(map(int, input().split())) print(a & b & ~next_all_ones(a ^ b))
FUNC_DEF VAR NUMBER FOR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR 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
numOfCase = int(input()) for noc in range(numOfCase): l = list(map(lambda s: int(s), input().split(" "))) m = l[0] n = l[1] res = n while res > m: res = res & res - 1 print(res)
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 VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR 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
def ANDprod(s): n1, n2 = s.split() n1 = int(n1) n2 = int(n2) c1 = 0 c2 = 0 x = 1 y = 1 while x <= n1: x = x << 1 | 0 c1 = c1 + 1 while y <= n2: y = y << 1 | 0 c2 = c2 + 1 if x == y: y = 0 while c1: c1 = c1 - 1 x = x >> 1 if x == x & n1 and x == x & n2: y = y ^ x elif 0 == x & n1 and 0 == x & n2: pass else: break return y else: return 0 t = int(input()) while t: s = input() res = ANDprod(s) print(res) t = t - 1
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN 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
def hibit(n): n = n | n >> 1 n = n | n >> 2 n = n | n >> 4 n = n | n >> 8 n = n | n >> 16 return n - (n >> 1) T = int(input()) for _ in range(T): A, B = [int(i) for i in input().split()] diff = A ^ B diff = hibit(diff) diff = (diff << 1) - 1 print(A & ~diff)
FUNC_DEF 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 RETURN BIN_OP VAR BIN_OP 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 ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL 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_A2B(A, B): if not A: return 0 last1 = A & -A a = A - last1 while a and a + (last1 << 1) <= B: last1 = a & -a a -= last1 return 0 if not A and last1 << 1 <= B else a + last1 def bt4c(A, B): ans = A for i in range(A + 1, B + 1): ans &= i return ans for _ in range(int(input())): A, B = map(int, input().split()) print(AND_A2B(A, B))
FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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().strip()) for _ in range(T): a, b = [int(s) for s in input().strip().split(" ")] et = a & b for i in range(et.bit_length()): bit = 1 << i if et & bit: if a <= b - bit: et -= bit print(et)
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 STRING ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR IF VAR 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 bin_repr(n): return "{:b}".format(n) def smart(low, high): return int(_smart_r(bin_repr(low), bin_repr(high)), base=2) def _smart_r(low_bin_str, high_bin_str): low_bin_str_stripped = low_bin_str.lstrip("0") high_bin_str_stripped = high_bin_str.lstrip("0") if len(low_bin_str) == 0: return "" if len(low_bin_str_stripped) != len(high_bin_str_stripped): return "0" * len(high_bin_str) else: return low_bin_str[0] + _smart_r(low_bin_str[1:], high_bin_str[1:]) def main(): test_count = int(input()) for __ in range(test_count): low, high = [int(x) for x in input().split(" ")] print(smart(low, high)) main()
FUNC_DEF RETURN FUNC_CALL STRING VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER RETURN STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP STRING FUNC_CALL VAR VAR RETURN BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_DEF 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 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 t in range(int(input())): a, b = map(int, input().split()) s = a if b - a >= a: print(0) else: while a <= b: k = 1 t = a while t % 2 == 0: t //= 2 k *= 2 a += k if a <= b: s &= a print(s)
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 IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR IF 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 has_zero(a, b, n): if a & 2**n == 0: return True x = a // 2**n * 2**n x += 2**n return x <= b for _ in range(int(input())): a, b = [int(s) for s in input().split()] res = 0 for i in range(32): if not has_zero(a, b, i): res += 2**i print(res)
FUNC_DEF IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR 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
all_ones = pow(2, 33) - 1 n = int(input()) for i in range(n): s, e = [int(p) for p in input().split()] r = s twopow = 0 v = pow(2, twopow) while twopow < 33: _next = (all_ones ^ v - 1) & s + v if v > e: break if _next <= e and r & v > 0: r ^= v twopow += 1 v = pow(2, twopow) print(r)
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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
T = int(input()) for T_i in range(T): p, r = [int(x) for x in input().split()] if len(bin(p)) != len(bin(r)): print(0) continue low = bin(p)[2:] high = bin(r)[2:] ans = 0 for c in range(len(low)): if low[c] == high[c] == "1": ans += 2 ** (len(low) - c - 1) elif low[c] != high[c]: break print(ans)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 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 ii in range(t): a, b = input().split() a, b = int(a), int(b) ax = str(bin(a)) bs = str(bin(b)) ca = len(ax) cb = len(bs) if ca == cb: c = ca aa = ax bb = bs elif ca > cb: c = ca aa = ax bb = "0" for i in range(1, ca - cb): bb += "0" bb += bs else: c = cb bb = bs aa = "0" for i in range(1, cb - ca): aa += "0" aa += ax ac = list(aa) bc = list(bb) xx = [0] * c i = 0 while i < c: if ac[i] == bc[i]: xx[i] = ac[i] i += 1 else: break for j in range(i, c): xx[j] = "0" ss = "" for i in range(c): ss += str(xx[i]) print(int(ss, 2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR STRING VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR 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()) while t: a, b = [int(i) for i in input().split()] ans = b k = 0 i = a while i < b: ans &= i i += 2**k k += 1 print(ans) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR 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 tt in range(t): a, b = list(map(int, input().split())) a_b = list(bin(a)[2:]) b_b = list(bin(b)[2:]) if len(a_b) > len(b_b): b_b = [0] * (len(a_b) - len(b_b)) + b_b else: a_b = [0] * (len(b_b) - len(a_b)) + a_b res = [] for i, (bit_a, bit_b) in enumerate(zip(a_b, b_b)): if bit_a == bit_b: res.append(bit_a) else: res += [0] * (len(a_b) - i) break print(int("".join(str(x) for x in res), 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 FUNC_CALL FUNC_CALL VAR 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 ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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 i in range(t): a, b = input().split(" ") a = int(a) b = int(b) r = 0 for j in range(32): if a == b and a & 1 == 1: r += 1 << j a >>= 1 b >>= 1 print(r)
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 FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER 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
for t in range(int(input())): a, b = [int(x) for x in input().split()] a = bin(a)[2:] b = bin(b)[2:] sol = 0 if len(a) != len(b): print(0) else: i = 0 while a[i] == b[i]: if a[i] == "1": sol += 2 ** (len(a) - i - 1) i += 1 if i == len(a): break print(sol)
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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF 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
def test_case(): m, n = [int(x) for x in input().split()] k = 0 while True: if n > m: k += 1 else: return m << k m = m >> 1 n = n >> 1 def main(): T = int(input()) while T > 0: print(test_case()) T -= 1 main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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
def function(start, end): blbs = bin(int(start))[2:] blbe = bin(int(end))[2:] if len(blbs) - len(blbe) == 0: k = 0 while int(start) >> k != int(end) >> k: k += 1 shift = int(start) >> k result = shift << k return result else: return 0 cases = int(input()) for case in range(cases): a, b = input().split() print(function(a, b))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR RETURN NUMBER 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 VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for i in range(int(input())): n = int(input()) li = list(map(int, input().split())) print(li[0] & li[1], end=" ") for i in range(1, len(li) - 1): print(max(li[i] & li[i + 1], li[i] & li[i - 1]), end=" ") print(li[n - 1] & li[n - 2])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
def solve(A, N): ans = [0] * N ans[0] = A[0] & A[1] ans[N - 1] = A[N - 1] & A[N - 2] for i in range(1, N - 1): ans[i] = max(A[i] & A[i + 1], A[i] & A[i - 1]) for i in ans: print(i, end=" ") print() T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) solve(A, N)
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for q in range(int(input())): n = int(input()) li = [int(x) for x in input().split()] for i in range(n): if i == 0: print(li[i] & li[i + 1], end=" ") elif i == n - 1: print(li[i - 1] & li[i], end=" ") else: print(max(li[i] & li[i + 1], li[i - 1] & li[i]), end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for p in range(t): q = int(input()) b = list(map(int, input().split())) n = len(b) for i in range(n): val = 0 if i > 0: val = max(val, b[i] & b[i - 1]) if i < n - 1: val = max(val, b[i] & b[i + 1]) print(val, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
import sys def solve(n, values): for i in range(n): val = 0 if i > 0: val = max(val, values[i] & values[i - 1]) if i < n - 1: val = max(val, values[i] & values[i + 1]) print(val, end=" ") print() def main(): test_case = int(sys.stdin.readline()) for tc in range(test_case): n = int(sys.stdin.readline()) values = [int(a) for a in sys.stdin.readline().split()] solve(n, values) main()
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for _ in range(int(input())): l = int(input()) arr = list(map(int, input().strip().split())) for i in range(len(arr)): ans1, ans2 = 0, 0 if i - 1 >= 0: ans1 = arr[i] & arr[i - 1] if i + 1 < len(arr): ans2 = arr[i] & arr[i + 1] print(max(ans1, ans2), end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
try: for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) res = [] res = [a[0] & a[1]] for i in range(1, n - 1, 1): ans = max(a[i] & a[i - 1], a[i] & a[i + 1]) res.append(ans) res.append(a[-1] & a[-2]) print(*res) except: pass
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for _ in range(t): n = int(input()) lst = list(map(int, input().split())) for i in range(0, n): if i == 0: print(lst[i] & lst[i + 1], end=" ") continue elif i == n - 1: print(lst[i] & lst[i - 1]) continue print(max(lst[i] & lst[i + 1], lst[i] & lst[i - 1]), end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
try: times = int(input()) for i in range(times): x = int(input()) arr = list(map(int, input().split(" "))) maximum = 1 n = len(arr) print(arr[0] & arr[1], end=" ") for i in range(1, n - 1): maxi = max(arr[i] & arr[i - 1], arr[i] & arr[i + 1]) print(maxi, end=" ") print(arr[n - 2] & arr[n - 1]) except: pass
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
def func(arr, N): ans = [(0) for i in range(N)] ans[0] = arr[0] & arr[1] for i in range(1, N - 1): ans[i] = max(arr[i] & arr[i + 1], arr[i] & arr[i - 1]) ans[-1] = arr[N - 1] & arr[N - 2] return ans T = int(input()) for i in range(T): N = int(input()) arr = list(map(int, input().split())) print(*func(arr, N))
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
n = int(input()) for i in range(n): k = int(input()) l = list(map(int, input().strip().split(" "))) if k == 2: print(l[0] & l[1]) continue print(l[0] & l[1], end=" ") for i in range(1, len(l) - 1): print(max(l[i] & l[i - 1], l[i] & l[i + 1]), end=" ") print(l[len(l) - 1] & l[len(l) - 2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for p in range(t): q = int(input()) b = list(map(int, input().split())) b.insert(0, 0) b.append(0) n = len(b) a = b[1] & b[2] for i in range(1, len(b) - 1): d = a a = b[i] & b[i + 1] if d > a: print(d, end=" ") else: print(a, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for i in range(t): n = int(input()) a = input().split(" ") b = [] x = int(a[0]) & int(a[1]) y = int(a[n - 2]) & int(a[n - 1]) b.insert(0, x) b.insert(n - 1, y) for j in range(1, n - 1): c = int(a[j - 1]) & int(a[j]) d = int(a[j]) & int(a[j + 1]) e = max(c, d) b.insert(j, e) g = " ".join(str(element) for element in b) print(g)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) ans = [a[0] & a[1]] for i in range(1, n - 1): ans.append(max(a[i] & a[i - 1], a[i] & a[i + 1])) ans.append(a[-1] & a[-2]) for i in ans: print(i, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
try: t = int(input()) while t != 0: n = int(input()) arr = [int(i) for i in input().split()] s = [] s.append(arr[0] & arr[1]) for i in range(1, len(arr) - 1): s.append(max(arr[i] & arr[i - 1], arr[i] & arr[i + 1])) s.append(arr[-1] & arr[-2]) print(*s) t -= 1 except EOFError: pass
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
T = int(input()) for m in range(T): n = [int(X) for X in input().split()] arr = [int(X) for X in input().split()] left = 0 right = 0 for i in range(n[0]): if i - 1 >= 0: left = arr[i] & arr[i - 1] if i + 1 < n[0]: right = arr[i] & arr[i + 1] print(max(left, right), end=" ") print()
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) ans = [] for i in range(n): l = 0 g = 0 if i > 0: l = arr[i] & arr[i - 1] if i < n - 1: g = arr[i] & arr[i + 1] ans.append(max(l, g)) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
def DhuaDhua(c, n): if n == 0: return c[0] & c[1] elif n == len(c) - 1: return c[n] & c[n - 1] else: return max(c[n] & c[n - 1], c[n] & c[n + 1]) for _ in range(int(input())): n = int(input()) c = list(map(int, input().split())) ans = [] for i in range(n): ans.append(DhuaDhua(c, i)) print(*ans)
FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for _ in range(0, t): n = int(input()) l = list(map(int, input().split())) ans = [] for i in range(0, n): if i == 0: ans.append(l[i] & l[i + 1]) elif i == n - 1: ans.append(l[i] & l[i - 1]) else: p = 0 p = max(l[i] & l[i + 1], l[i] & l[i - 1]) ans.append(p) print(*ans[0:])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for _ in range(int(input())): n = int(input()) A = [int(i) for i in input().strip().split(" ")] ans = [] for i in range(n): if i == 0: ans.append(A[i] & A[i + 1]) elif i == n - 1: ans.append(A[i] & A[i - 1]) else: ans.append(max(A[i] & A[i + 1], A[i] & A[i - 1])) for ele in ans: print(ele, end=" ") print("")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, list(input().split()))) b = len(l) for i in range(b): if i == 0: print(l[i] & l[i + 1], end=" ") elif i != b - 1: v = l[i] & l[i + 1] k = l[i] & l[i - 1] if v > k: print(v, end=" ") else: print(k, end=" ") else: print(l[i] & l[i - 1], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) arr.insert(0, 0) arr.append(0) for i in range(1, n + 1): print(max(arr[i] & arr[i - 1], arr[i] & arr[i + 1]), end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for _ in range(int(input())): _, l, res, ps = int(input()), [int(x) for x in input().split()], [], 0 for x in range(_ - 1): sol, ps = res.append(max(ps, l[x] & l[x + 1])), l[x] & l[x + 1] print(*(res + [l[x] & l[x + 1]]))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR LIST BIN_OP VAR VAR VAR BIN_OP VAR NUMBER
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) ans = [0] * n ans[0] = arr[0] & arr[1] ans[n - 1] = arr[n - 1] & arr[n - 2] for i in range(1, n - 1): ans[i] = max(arr[i] & arr[i + 1], arr[i] & arr[i - 1]) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) arr = [0] * N for i in range(N - 1): v = A[i] & A[i + 1] v1 = v vi = i + 1 for j in range(i, N): v1 = arr[j] & v1 arr[j] = max(arr[j], v1) if v1 > v: v = v1 vi = j else: break for j in range(i, vi + 1): arr[j] = max(arr[j], v) print(*arr)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
case = int(input()) for r in range(case): n = int(input()) arr = [int(x) for x in input().split()] for i in range(n): res = 1 if i == 0: res = arr[0] & arr[1] print(res, end=" ") continue elif i == n - 1: res = arr[n - 1] & arr[n - 2] print(res, end=" ") continue else: a = arr[i] & arr[i - 1] b = arr[i] & arr[i + 1] print(max(a, b), end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
for _ in range(int(input())): n = int(input()) lst = list(map(int, input().split())) ans = list() nm = 0 for i in range(n): if i == 0: nm = lst[0] & lst[1] elif i == n - 1: nm = lst[i] & lst[i - 1] else: nm = max(lst[i] & lst[i - 1], lst[i] & lst[i + 1]) ans.append(nm) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for i in range(t): n = int(input()) c = [] a = list(map(int, input().split())) c.append(a[0] & a[1]) for i in range(1, n - 1): b = a[i] & a[i + 1] e = a[i] & a[i - 1] c.append(max(b, e)) c.append(a[n - 1] & a[n - 2]) print(*c, sep=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
t = int(input()) for _ in range(t): input() xs = [int(w) for w in input().strip().split(" ")] ans = [] for i, x in enumerate(xs): if i == 0: ans.append(x & xs[1]) elif i == len(xs) - 1: ans.append(x & xs[i - 1]) else: ans.append(max(x & xs[i - 1], x & xs[i + 1])) print(" ".join([str(v) for v in ans]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Nasir and two of his henchmen are planning to attack N shops of the Qureshi clan. The shops are conveniently lined up, and numbered from 1 to N. The i-th shop contains A_{i} kg of coal. For a given subarray of shops [A_{L}, A_{L+1}, \dots, A_{R}], the *bitwise and* of this subarray is defined to be the [bitwise AND] of the coal contained in each of the shops, i.e, A_{L} \& A_{L+1} \& \dots \& A_{R}. The damage caused when bombing the i-th shop is computed to be the maximum *bitwise and* over all subarrays containing shop i, and whose size is strictly larger than 1. For each shop (1≤ i≤ N), find the damage caused when Nasir bombs it. ------ Input Format ------ - The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N, denoting the number of shops. - The second line of each test case contains N space-separated integers, the i-th of which is A_{i}, representing the amount of coal in the i-th shop. ------ Output Format ------ For each test case, print a single line containing N integers d_{1},d_{2},\ldots,d_{n} where d_{i} represents the maximum damage that can be caused if the i-th shop is to be bombed. ------ Constraints ------ $1 ≤ T ≤ 10000$ $2 ≤ N ≤ 2 \cdot 10^{5}$ $0 ≤ A_{i} ≤ 10^{9}$ - The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 2 5 29 412 671 255 912 6 166 94 184 114 1124 298 ----- Sample Output 1 ------ 28 156 159 159 144 6 24 48 96 96 32 ----- explanation 1 ------ Test case 1: There are several choices of subarray which give the maximum for each index. One such choice is given below: For shop $1$, choose subarray $[29, 412, 671, 255]$ For shop $2$, choose subarray $[412, 671, 255]$ For shop $3$, choose subarray $[671, 255]$ For shop $4$. choose subarray $[671, 255]$ For shop $5$, choose subarray $[412, 671, 255, 912]$
def ans(arr): new_arr = [] i = 0 while i < len(arr): if i == 0: new_arr.append(arr[i] & arr[i + 1]) elif i == len(arr) - 1: new_arr.append(arr[i] & arr[i - 1]) else: new_arr.append(max(arr[i] & arr[i - 1], arr[i] & arr[i + 1])) i += 1 return new_arr test_cases = int(input()) while test_cases != 0: d = input() d2 = list(map(int, input().split())) print(*ans(d2)) test_cases -= 1
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): a = [int(x) for x in input().split()] a.sort() b = [] for i in a: if i: b.append(i) ans = len(b) if len(b) == 2: if b[0] > 1: ans += 1 elif len(b) == 3: if b[0] > 1 and b[2] > 1: b[0] -= 1 b[2] -= 1 ans += 1 if b[1] > 1 and b[2] > 1: b[1] -= 1 b[2] -= 1 ans += 1 if b[1] > 1 and b[0] > 1: ans += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
def count_colors(colors): zeros, ones, twos = colors.count(0), colors.count(1), colors.count(2) primary_color = 3 - zeros if zeros + ones > 1: secondary_color = 0 elif zeros + ones == 1: secondary_color = 1 elif twos == 1 or twos == 2: secondary_color = 2 elif twos == 3: secondary_color = 1 else: secondary_color = 3 return primary_color + secondary_color for _ in range(int(input())): print(count_colors(list(map(int, input().split()))))
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
def find_max(r, g, b): sorted_array = [r, g, b] sorted_array.sort(reverse=True) max_colours = 0 for position in (0, 1): next_po = position + 1 if sorted_array[next_po] > 1 and sorted_array[position] > 1: max_colours += 1 sorted_array[next_po] -= 1 sorted_array[position] -= 1 second_next_pos = next_po + 1 if second_next_pos < 3: if sorted_array[second_next_pos] > 1 and sorted_array[position] > 1: max_colours += 1 sorted_array[position] -= 1 sorted_array[second_next_pos] -= 1 for colour in sorted_array: max_colours += min(1, colour) colours_possible_with_just_individual_colours = min(1, r) + min(1, g) + min(1, b) return max(max_colours, colours_possible_with_just_individual_colours) t = int(input()) for _ in range(t): r, g, b = map(int, input().split()) print(find_max(r, g, b))
FUNC_DEF ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): a = list(map(int, input().split())) count = 0 a.sort(reverse=True) for i in range(3): if a[i] > 0: a[i] -= 1 count += 1 for i in range(3): for j in range(i + 1, 3): if a[i] > 0 and a[j] > 0: a[i] -= 1 a[j] -= 1 count += 1 print(count)
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 NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
case = int(input()) for _ in range(case): arr = list(map(int, input().split(" "))) count = 0 n = 3 arr.sort() if arr[n - 1] > 1 and arr[n - 2] > 1: count += 1 arr[n - 1] -= 1 arr[n - 2] -= 1 if arr[n - 1] > 1 and arr[n - 3] > 1: count += 1 arr[n - 1] -= 1 arr[n - 3] -= 1 if arr[n - 2] > 1 and arr[n - 3] > 1: count += 1 arr[n - 2] -= 1 arr[n - 3] -= 1 if arr[n - 1] > 0: count += 1 if arr[n - 2] > 0: count += 1 if arr[n - 3] > 0: count += 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
T = int(input()) for i in range(T): a = list(map(int, input().split())) a.sort(reverse=True) ans = 0 if a[0] > 0: ans += 1 if a[1] > 0: ans += 1 if a[2] > 0: ans += 1 if a[0] > 1 and a[1] > 1: ans += 1 a[0] -= 1 a[1] -= 1 if a[0] > 1 and a[2] > 1: ans += 1 a[0] -= 1 a[2] -= 1 if a[1] > 1 and a[2] > 1: ans += 1 a[1] -= 1 a[2] -= 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): x, y, z = map(int, input().split()) n = 0 if x > 0: n += 1 x -= 1 if y > 0: n += 1 y -= 1 if z > 0: n += 1 z -= 1 x, y, z = sorted([x, y, z], reverse=True) if x > 0 and y > 0: n += 1 x -= 1 y -= 1 if z > 0 and y > 0: n += 1 z -= 1 y -= 1 if x > 0 and z > 0: n += 1 x -= 1 z -= 1 print(n)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR LIST VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
test = int(input()) while test > 0: test = test - 1 X, Y, Z = map(int, input().split()) list1 = [X, Y, Z] ans = 0 if list1[0] > 0: ans += 1 list1[0] -= 1 if list1[1] > 0: ans += 1 list1[1] -= 1 if list1[2] > 0: ans += 1 list1[2] -= 1 list1.sort() list1.reverse() if list1[0] > 0 and list1[1] > 0: ans += 1 list1[0] -= 1 list1[1] -= 1 if list1[0] > 0 and list1[2] > 0: ans += 1 list1[0] -= 1 list1[2] -= 1 if list1[1] > 0 and list1[2] > 0: ans += 1 list1[1] -= 1 list1[2] -= 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
T = int(input()) for _ in range(T): list1 = list(map(int, input().split(" "))) list1.sort(reverse=True) X, Y, Z = list1[0], list1[1], list1[2] x = X - 1 if X > 1 else 0 y = Y - 1 if Y > 1 else 0 z = Z - 1 if Z > 1 else 0 total = min(X, 1) + min(Y, 1) + min(Z, 1) if x and y: total += 1 x -= 1 y -= 1 if x and z: total += 1 x -= 1 z -= 1 if z and y: total += 1 print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
t = int(input()) for _ in range(t): x, y, z = map(int, input().split()) if x > 2 and y > 2 and z > 2: print(6) elif ( x > 2 and y > 1 and z > 1 or y > 2 and x > 1 and z > 1 or z > 2 and x > 1 and y > 1 ): print(5) elif x == 2 and y == 2 and z == 2: print(4) elif x > 1 and y > 1 and z <= 1: print(3 + z) elif x > 1 and z > 1 and y <= 1: print(3 + y) elif y > 1 and z > 1 and x <= 1: print(3 + x) else: print(int(x >= 1) + int(y >= 1) + int(z >= 1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): x, y, z = map(int, input().split()) temp = [x, y, z] res = 0 for col in range(3): if temp[col] >= 1: temp[col] -= 1 res += 1 temp.sort() if temp[0] >= 2: res += 3 elif temp[0] == 1: if temp[2] >= 2: res += 2 else: res += 1 elif temp[1] != 0: res += 1 print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
t = int(input()) while t: a, b, c = map(int, input().split()) s = 0 l = [] if a > 0: s += 1 a -= 1 if b > 0: s += 1 b -= 1 if c > 0: s += 1 c -= 1 x, p = a, a y, q = b, b z, r = c, c l, m, n = 0, 0, 0 if x > 0 and y > 0: l += 1 x -= 1 y -= 1 if y > 0 and z > 0: l += 1 y -= 1 z -= 1 if z > 0 and x > 0: l += 1 z -= 1 x -= 1 if b > 0 and c > 0: m += 1 b -= 1 c -= 1 if c > 0 and a > 0: m += 1 c -= 1 a -= 1 if a > 0 and b > 0: m += 1 b -= 1 a -= 1 if r > 0 and p > 0: r -= 1 p -= 1 n += 1 if p > 0 and q > 0: q -= 1 p -= 1 n += 1 if q > 0 and r > 0: q -= 1 r -= 1 n += 1 print(max(l, m, n) + s) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
def check(a, b, output): if a > 0 and b > 0: return a - 1, b - 1, output + 1 return a, b, output n = int(input()) for i in range(n): colors = list(map(int, input().split())) output = len([i for i in colors if i > 0]) r, g, b = sorted([(i - 1) for i in colors], reverse=True) r, g, output = check(r, g, output) r, b, output = check(r, b, output) g, b, output = check(g, b, output) print(output)
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): a = sorted(list(map(int, input().split()))) add = 0 for i in a: if i != 0: add += 1 if a[0] >= 3: print(add + 3) elif a[0] == 2: if a[2] >= 3: print(add + 2) else: print(add + 1) elif a[1] <= 1: print(add) else: print(add + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
t = int(input()) for i in range(t): x, y, z = map(int, input().split()) x, y, z = sorted([x, y, z]) count = 0 if x >= 1: count = count + 1 if y >= 1: count = count + 1 if z >= 1: count = count + 1 if y > 1 and z > 1: count = count + 1 if x > 1 and z > 2: count = count + 1 if x > 2 and y > 2: count = count + 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): li = list(map(int, input().split())) zero = 0 one = 0 two = 0 for i in li: if i == 0: zero += 1 elif i == 1: one += 1 elif i == 2: two += 1 if zero == 3: res = 0 elif zero == 2: res = 1 elif zero == 1: if li[0] == 1 or li[1] == 1 or li[2] == 1: res = 2 else: res = 3 elif one == 1 or two == 3: res = 4 elif one == 2 or one == 3: res = 3 elif two == 1 or two == 2: res = 5 else: res = 6 print(res)
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for i in range(0, int(input())): l = list(map(int, input().split())) a = 0 for j in range(0, 3): if l[j] > 0: a = a + 1 l[j] = l[j] - 1 else: continue n = 0 x = l[0] y = l[1] z = l[2] x, y, z = sorted([x, y, z], reverse=True) if x > 0 and y > 0: n += 1 x -= 1 y -= 1 if y > 0 and z > 0: n += 1 z -= 1 y -= 1 if x > 0 and z > 0: n += 1 x -= 1 z -= 1 print(int(a + n))
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR LIST VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
t = int(input()) for i in range(t): x, y, z = map(int, input().split(" ")) c = 0 if x > 0: c += 1 x -= 1 if y > 0: c += 1 y -= 1 if z > 0: c += 1 z -= 1 if x * y * z == 0 and (x, y, z).count(0) == 1: c += 1 elif (x, y, z).count(0) == 2: c += 0 elif (x, y, z).count(0) == 0: if (x, y, z).count(1) == 0: c += 3 elif (x, y, z).count(1) in (1, 2): c += 2 elif (x, y, z).count(1) == 3: c += 1 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
n = int(input()) d = [] for i in range(n): l = [int(x) for x in input().split()] ans = 3 - l.count(0) l.sort() if l[0] >= 3: print(6) elif l[0] == 2: if l[2] >= 3: ans = 5 else: ans = 4 print(ans) elif l[1] <= 1: print(ans) else: print(ans + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
t = int(input()) for _ in range(t): a = list(map(int, input().split())) a.sort() v = 0 for i in range(3): a[i] = min(3, a[i]) v = 16 * a[0] + 4 * a[1] + a[2] if v == 0: ans = 0 elif v <= 3: ans = 1 elif v <= 0 * 16 + 1 * 4 + 3: ans = 2 elif v <= 1 * 16 + 1 * 4 + 3: ans = 3 elif v <= 2 * 16 + 2 * 4 + 2: ans = 4 elif v <= 2 * 16 + 3 * 4 + 3: ans = 5 else: ans = 6 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
T = int(input()) for _ in range(T): x = list(map(int, input().split())) x.sort(reverse=True) r = x[0] g = x[1] b = x[2] n = 0 if r > 1 and g > 1: r = r - 1 g = g - 1 n = n + 1 if r > 1 and b > 1: r = r - 1 b = b - 1 n = n + 1 if r > 0: n = n + 1 if g > 1 and b > 1: g = g - 1 b = b - 1 n = n + 1 if g > 0: n = n + 1 if b > 0: n = n + 1 print(n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): A = list(map(int, input().split())) A.sort(reverse=True) X, Y, Z = A colors = 0 if X > 1 and Y > 1: colors += 1 X -= 1 Y -= 1 if Y > 1 and Z > 1: colors += 1 Y -= 1 Z -= 1 if Z > 1 and X > 1: colors += 1 Z -= 1 X -= 1 colors += X > 0 colors += Y > 0 colors += Z > 0 print(colors)
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
t = int(input()) for i in range(t): l = list(map(int, input().split())) t = 0 for j in range(len(l)): if l[j] - 1 >= 0: l[j] = l[j] - 1 t += 1 l.sort() if l >= [2, 2, 2]: t += 3 elif l >= [1, 1, 2]: t += 2 elif l >= [0, 1, 1]: t += 1 print(t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR LIST NUMBER NUMBER NUMBER VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for i in range(int(input())): a = list(map(int, input().split())) r = a[0] g = a[1] b = a[2] if r > 1 and g > 1 and b > 1: if r > 2 and g > 2 and b > 2: print("6") elif r > 2 or g > 2 or b > 2: print("5") else: print("4") elif ( r > 1 and g <= 1 and b > 1 or r > 1 and g > 1 and b <= 1 or r <= 1 and g > 1 and b > 1 ): if g == 0 or r == 0 or b == 0: print("3") else: print("4") elif ( r <= 1 and g <= 1 and b > 1 or r > 1 and g <= 1 and b <= 1 or r <= 1 and g > 1 and b <= 1 ): if r == 0 and g == 0 or b == 0 and g == 0 or r == 0 and b == 0: print("1") elif g == 0 or r == 0 or b == 0: print("2") else: print("3") elif r == 0 and b == 0 and g == 0: print("0") elif r <= 1 and g <= 1 and b <= 1: if r == 1 and g == 1 and b == 1: print("3") elif ( r == 0 and b == 1 and g == 1 or r == 1 and b == 1 and g == 0 or r == 1 and b == 0 and g == 1 ): print("2") else: print("1")
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 VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for i in range(int(input())): c = list(map(int, input().split())) ans = 0 for i in range(len(c)): if c[i] > 0: ans += 1 c[i] -= 1 c.sort() c.reverse() for j in [(0, 1), (1, 2), (0, 2)]: if c[j[0]] > 0 and c[j[1]] > 0: c[j[0]] -= 1 c[j[1]] -= 1 ans += 1 print(ans)
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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
def check_positions(sorted_array, first_pos, second_pos): try: if sorted_array[first_pos] > 1 and sorted_array[second_pos] > 1: sorted_array[first_pos] -= 1 sorted_array[second_pos] -= 1 return 1 except IndexError: pass return 0 def find_max(r, g, b): sorted_array = [r, g, b] sorted_array.sort(reverse=True) max_colours = 0 for position in (0, 1): next_po = position + 1 max_colours += check_positions(sorted_array, position, next_po) second_next_pos = next_po + 1 max_colours += check_positions(sorted_array, position, second_next_pos) for colour in sorted_array: max_colours += min(1, colour) return max_colours t = int(input()) for _ in range(t): r, g, b = map(int, input().split()) print(find_max(r, g, b))
FUNC_DEF IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER VAR RETURN NUMBER FUNC_DEF ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR FUNC_CALL VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): a = list(map(int, input().split())) a.sort() if a[2] == 0: print(0) elif a[1] == 0: print(1) elif a[0] == 0: if a[1] >= 2: print(3) else: print(2) else: if a[0] >= 3: print(6) if a[0] == 2 and a[1] >= 3: print(5) if a[0] == 1 and a[1] >= 3: print(4) if a[0] == 2 and a[1] == 2 and a[2] >= 3: print(5) if a[0] == 1 and a[1] == 2 and a[2] >= 3: print(4) if (a[0] == 2 or a[0] == 1) and a[1] == 2 and a[2] == 2: print(4) if a[0] == 1 and a[1] == 1 and a[2] == 2: print(3) if a[0] == 1 and a[1] == 1 and a[2] >= 3: print(3) if a[0] == 1 and a[1] == 1 and a[2] == 1: print(3)
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 EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for i in range(0, int(input())): li = list(map(int, input().strip().split())) li.sort(reverse=True) cnt = 0 for i in range(0, len(li)): if li[i] > 0: li[i] -= 1 cnt += 1 for i in range(0, len(li)): for j in range(i + 1, len(li)): if li[i] > 0 and li[j] > 0: li[i] -= 1 li[j] -= 1 cnt += 1 print(cnt)
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
t = int(input()) while t: colors = list(map(int, input().split())) ans = 0 for i in range(3): if colors[i] != 0: ans += 1 colors[i] -= 1 colors.sort() if colors[0] >= 2: print(ans + 3) t -= 1 continue if colors[0] == 1: if colors[2] >= 2: print(ans + 2) else: print(ans + 1) t -= 1 continue if colors[1] == 0: print(ans) else: print(ans + 1) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
x = int(input()) g = [] for iir in range(0, x): op = str(input()) kkr = op.split(" ") uure = [] for bbv in kkr: uure.append(int(bbv)) g.append(uure) for nnx in g: if nnx[0] == 0 and nnx[1] == 0 and nnx[2] == 0: print(0) else: nnx.sort(reverse=True) a = nnx[0] b = nnx[1] c = nnx[2] ansd = 0 if a > 1 and b > 1: ansd += 1 a -= 1 b -= 1 if b > 1 and c > 1: ansd += 1 b -= 1 c -= 1 if c > 1 and a > 1: ansd += 1 c -= 1 a -= 1 prt = [a, b, c] for iinc in prt: if iinc != 0: ansd += 1 print(ansd)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for i in range(int(input())): lst = [int(a) for a in input().split()] lst.sort(reverse=True) answer = 0 if lst == [0, 0, 0]: print(0) else: x = 0 for i in range(3): if lst[i - x] == 0: lst.remove(0) x += 1 else: lst[i] -= 1 answer += 1 for i in range(len(lst)): for j in range(i + 1, min(len(lst), i + lst[i] + 1)): if lst[i] == 0: break elif lst[j] > 0: lst[j] -= 1 lst[i] -= 1 answer += 1 print(answer)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
get_int = lambda: int(input()) get_mint = lambda: list(map(int, input().split())) for _ in range(get_int()): X, Y, Z = sorted(get_mint(), reverse=True) color = 0 if X > 0: X -= 1 color += 1 if Y > 0: color += 1 Y -= 1 if Z > 0: color += 1 Z -= 1 if X > 0 and Y > 0: X -= 1 Y -= 1 color += 1 if X > 0 and Z > 0: X -= 1 Z -= 1 color += 1 if Y > 0 and Z > 0: Y -= 1 Z -= 1 color += 1 print(color)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): x, y, z = [int(x) for x in input().split()] ans = 0 if x > 0: ans += 1 x -= 1 if y > 0: ans += 1 y -= 1 if z > 0: ans += 1 z -= 1 l1 = [x, y, z] l1.sort() l1.reverse() if l1[0] > 0 and l1[1] > 0: ans += 1 l1[0] -= 1 l1[1] -= 1 if l1[0] > 0 and l1[2] > 0: ans += 1 l1[0] -= 1 l1[2] -= 1 if l1[1] > 0 and l1[2] > 0: ans += 1 l1[1] -= 1 l1[2] -= 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
reply = [] for _ in range(int(input())): arr = [] for i in input().split(): arr.append(int(i)) arr.sort() arr.reverse() r = arr[0] g = arr[1] b = arr[2] count = 0 if r >= 1: count += 1 r -= 1 if g >= 1: count += 1 g -= 1 if b >= 1: count += 1 b -= 1 if r >= 1 and b >= 1: count += 1 r -= 1 b -= 1 if b >= 1 and g >= 1: count += 1 g -= 1 b -= 1 if r >= 1 and g >= 1: count += 1 r -= 1 g -= 1 reply.append(count) for i in reply: print(i)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
vojj = int(input()) for vishnesh in range(vojj): r, g, b = map(int, input().split()) c = 0 if r > 0: r = r - 1 c = c + 1 if g > 0: g = g - 1 c = c + 1 if b > 0: b = b - 1 c = c + 1 a = [r, g, b] a.sort() a = a[::-1] r, g, b = a if r > 0 and g > 0: r = r - 1 g = g - 1 c = c + 1 if b > 0 and g > 0: g = g - 1 b = b - 1 c = c + 1 if r > 0 and b > 0: r = r - 1 b = b - 1 c = c + 1 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for _ in range(int(input())): x, y, z = map(int, input().split()) ans = 0 for mask in range(8): nx = ny = nz = 0 if mask & 1: nx += 1 ny += 1 if mask & 2: nx += 1 nz += 1 if mask & 4: nz += 1 ny += 1 if nx > x or ny > y or nz > z: continue have = bin(mask)[2:].count("1") have += (nx < x) + (ny < y) + (nz < z) ans = max(ans, have) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
for i in range(int(input())): c = list(map(int, input().split())) c = [x for x in c if x != 0] s = len(c) for i in range(len(c)): if c[i] >= 3: c = c[:i] + [3] + c[i + 1 :] c = [(x - 1) for x in c] c = [x for x in c if x != 0] if sum(c) == 6: s += 3 elif sum(c) == 5: s += 2 elif sum(c) == 4 and 1 in c: s += 2 elif sum(c) <= 4 and sum(c) != 0: if len(c) != 1: s += 1 else: s += 0 print(s)
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 VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR LIST NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
n = int(input()) for p in range(0, n): arr = [int(i) for i in input().split()] arr.sort() x = arr[0] y = arr[1] z = arr[2] ans = 0 for i in range(3): if arr[i] >= 1: ans += 1 if x == 2: if z >= 3: print(ans + 2) else: print(ans + 1) elif x >= 3: print(ans + 3) elif y <= 1: print(ans) else: print(ans + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
T = int(input()) for i in range(T): l = [] s = 0 x, y, z = map(int, input().split()) l.append(x) l.append(y) l.append(z) for i in range(3): if l[i] != 0: l[i] -= 1 s += 1 l.sort() if l[0] >= 2: print(s + 3) elif l[0] == 1: if l[2] >= 2: s += 2 else: s += 1 print(s) else: if l[1] == 0: s else: s += 1 print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
from sys import stdin input = stdin.readline for _ in range(int(input())): b, g, r = sorted(map(int, input().split())) if b == 0: print(3 if g > 1 else 2 if g > 0 else 1 if r > 0 else 0) elif b == 1: print(4 if g > 1 else 3) elif b == 2: print(5 if r > 2 else 4) else: print(6)
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three space separated integers X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available.
t = int(input()) while t > 0: r, g, b = map(int, input().split()) res = 0 l = [r, g, b] l.sort() r = l[2] g = l[1] b = l[0] if r > 0: res += 1 r -= 1 if g > 0: res += 1 g -= 1 if b > 0: res += 1 b -= 1 if r > 0 and g > 0: res += 1 r -= 1 g -= 1 if g > 0 and b > 0: res += 1 g -= 1 b -= 1 if b > 0 and r > 0: res += 1 print(res) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Bob is playing a game named "Walk on Matrix". In this game, player is given an n × m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}. To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix. However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to. Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. <image> However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n × m matrix A=(a_{i,j}) such that * 1 ≤ n,m ≤ 500 (as Bob hates large matrix); * 0 ≤ a_{i,j} ≤ 3 ⋅ 10^5 for all 1 ≤ i≤ n,1 ≤ j≤ m (as Bob hates large numbers); * the difference between the maximum score he can get and the output of his algorithm is exactly k. It can be shown that for any given integer k such that 0 ≤ k ≤ 10^5, there exists a matrix satisfying the above constraints. Please help him with it! Input The only line of the input contains one single integer k (0 ≤ k ≤ 10^5). Output Output two integers n, m (1 ≤ n,m ≤ 500) in the first line, representing the size of the matrix. Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column. Examples Input 0 Output 1 1 300000 Input 1 Output 3 4 7 3 3 1 4 8 3 6 7 7 7 3 Note In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000. In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
k = int(input()) y = 1 while y <= k: y <<= 1 X = k + y m = [[X, y, y], [k, y, y], [k, X, k]] print(3, 3) for arr in m: print(" ".join([str(x) for x in arr]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST LIST VAR VAR VAR LIST VAR VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR