description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
xor, summ = map(int, input().split()) if xor > summ or xor & 1 != summ & 1: print(-1) else: temp = (summ - xor) // 2 if temp != 0: if xor & temp: print(3) print(xor, temp, temp) else: print(2) print(temp + xor, temp) elif xor == 0 and summ == 0: print(0) else: print(1) print(xor)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
def solve(): u, v = map(int, input().split()) if abs(u - v) % 2 != 0 or u > v: return -1 elif u == v: return f"{1}\n{u}" if u != 0 else "0" else: x = (v - u) // 2 if u & x: return f"3\n{u} {x} {x}" else: return f"2\n{u ^ x} {x}" print(solve())
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR NUMBER NUMBER STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR RETURN STRING VAR STRING VAR STRING VAR RETURN STRING BIN_OP VAR VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
u, v = list(map(int, input().split())) ind = 0 if u > v or (v - u) % 2 == 1: print(-1) elif v == 0: print(0) elif u == v: print("1") print(u) else: v = (v - u) // 2 bit_u = [0] * 100 bit_v = [0] * 100 ind = 0 while v > 0: if v % 2 == 1: bit_v[ind] = 1 v = v // 2 ind += 1 ind = 0 while u > 0: if u % 2 == 1: bit_u[ind] = 1 u = u // 2 ind += 1 b = 1 for i in range(0, 100): if bit_u[i] + bit_v[i] == 2: b = 0 if b == 1: print(2) a1 = 0 a2 = 0 for i in range(0, 100): if bit_v[i] == 1: a1 += 1 << i a2 += 1 << i if bit_u[i] == 1: a2 += 1 << i print(str(a1) + " " + str(a2)) else: print(3) a1 = 0 a2 = 0 a3 = 0 for i in range(0, 100): if bit_u[i] + bit_v[i] == 2: a1 += 1 << i a2 += 1 << i a3 += 1 << i elif bit_v[i] == 1: a1 += 1 << i a2 += 1 << i elif bit_u[i] == 1: a2 += 1 << i print(str(a1) + " " + str(a2) + " " + str(a3))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
u, v = [int(x) for x in input().split()] if u == 0 and v == 0: print(0) exit(0) if u == v: print(1) print(u) exit(0) if u > v or (u - v) % 2 == 1: print(-1) exit(0) result = 0 tmp_u = u tmp_and = v - u >> 1 x = tmp_and i = 0 j = 0 while tmp_u > 0 or tmp_and > 0: a = tmp_and % 2 b = tmp_u % 2 if a == 1: if b == 1: print(3) print(u, x, x) exit(0) if b == 0: result = result + (1 << i) if b == 1: j = i tmp_u = tmp_u >> 1 tmp_and = tmp_and >> 1 i += 1 print(2) print(result, v - result)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
u, v = [int(x) for x in input().split()] v1 = (v - u) // 2 v2 = (v + u) // 2 if u > v or (v - u) % 2 == 1: print(-1) elif u == v and v == 0: print(0) elif u == v: print(1) print(u) elif v1 ^ v2 == u: print(2) print(v1, v2) else: print(3) print(v1, v1, u)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
import sys def toBinary(n): arr = [] k = n i = 0 while k > 0: next = k % (2 * 2**i) // 2**i arr.append(next) k -= next * 2**i i += 1 return arr fptr = sys.stdout uv = input().split() u = int(uv[0]) v = int(uv[1]) def f(u, v): if u > v: fptr.write(str(-1)) return if u == v and u == 0: fptr.write(str(0)) return if u == v: fptr.write(str(1) + "\n") fptr.write(str(u)) return if (v - u) % 2 == 1: fptr.write(str(-1)) return diff = (v - u) // 2 binV = toBinary(v) if u + diff ^ diff != u: fptr.write(str(3) + "\n") fptr.write(str(u) + " " + str(diff) + " " + str(diff)) return fptr.write(str(2) + "\n") fptr.write(str(u + diff) + " " + str(diff)) f(u, v) fptr.close()
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
def ii(): return int(input()) def mi(): return map(int, input().split()) def ai(): return list(map(int, input().split())) u, v = mi() if u > v or u & 1 != v & 1: print(-1) elif u == 0 and v == 0: print(0) else: x = (v - u) // 2 if x: if u & x != 0: print(3) print(u, x, x) else: print(2) print(u + x, x) else: print(1) print(u)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
u, v = list(map(int, input().split())) if (v - u) % 2 == 1: print(-1) elif v == 0 and u == 0: print(0) elif v < u: print(-1) elif v == u: print(1) print(u) else: bu = bin(u) bv = bin(v) k = (v - u) // 2 bk = bin(k) if u ^ k == u + k: print(2) print(k, k + u) else: print(3) print(u, k, k)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
def main(): u, v = map(int, input().split()) dif = v - u if dif < 0 or dif % 2: print(-1) return elif dif == 0 and u == 0: print(0) return elif dif == 0: ans = [u] else: half = dif >> 1 rest = v - 2 * half if rest & half: ans = [half, half, rest] else: ans = [half, half + rest] print(len(ans)) print(*ans) return main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR LIST VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
def run(): xo, s = list(map(int, input().split())) if s < xo: print(-1) return if s == xo: if s != 0: print(1) print(xo) return if (s - xo) % 2 != 0: print(-1) return an = (s - xo) // 2 an_binary = "{0:b}".format(an) xo_binary = "{0:b}".format(xo) xo_binary = xo_binary.rjust(len(an_binary), "0") an_binary = an_binary.rjust(len(xo_binary), "0") include_c = False for i in range(len(xo_binary)): if an_binary[i] == "1" and xo_binary[i] == "1": include_c = True break if not include_c: a = xo + an b = an print(2) print(str(a) + " " + str(b)) else: a = xo b = an print(3) print(str(a) + " " + str(b) + " " + str(b)) run()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
from sys import gettrace, stdin if not gettrace(): def input(): return next(stdin)[:-1] def main(): u, v = map(int, input().split()) if u > v: print(-1) return if u % 2 != v % 2: print(-1) return if v == 0: print(0) return if u == v: print(1) print(u) return x = (v - u) // 2 if x & u == 0: print(2) print(x | u, x) else: print(3) print(u, x, x) main()
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
def GETBIT(x, bit): return x >> bit & 1 def solve(u, v): if u > v: print(-1) return if v == 0: print(0) return v -= u if v == 0: print(1) print(u) return rs = 1 lst = [0] * 3 lst[0] += u if v % 2 == 1: print(-1) return for i in range(64): if GETBIT(v, i) == 1: if GETBIT(u, i - 1) == 1: rs = max(rs, 3) lst[1] += 1 << i - 1 lst[2] += 1 << i - 1 else: rs = max(rs, 2) lst[1] += 1 << i - 1 lst[0] += 1 << i - 1 print(rs) print(*(lst[i] for i in range(rs))) u, v = map(int, input().split()) solve(u, v)
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
bit = 67 x, s = map(int, input().split()) if x == s: if s != 0: print(1) print(s) else: print(0) exit(0) s -= x if s < 0 or s & 1: print(-1) exit(0) a = 0 for i in range(1, bit): if s >> i & 1: a += 1 << i - 1 if a & x: print(3) print(a, a, x) else: x |= a print(2) print(a, x)
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
a, b = map(int, input().split()) def f(a, b): if b - a < 0 or (b - a) % 2 == 1: print(-1) elif b == 0: print(0) elif a == b: print(1) print(b) else: x = (b - a) // 2 if a ^ x == a + x: sol = [a + x, x] else: sol = [a, x, x] print(len(sol)) print(" ".join([str(i) for i in sol])) f(a, b)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
u, v = map(int, input().split()) kouho = [u] k = v - u if k < 0 or k % 2 != 0: if u == v: print(1) print(u) else: print(-1) exit() k //= 2 kouho.append(k) kouho.append(k) if kouho[1] == 0: if u == 0: print(0) else: print(1) print(u) elif kouho[0] ^ kouho[1] == kouho[0] + kouho[1]: print(2) print(kouho[0] + kouho[1], kouho[2]) else: print(3) print(kouho[0], kouho[1], kouho[2])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
import sys def main(): u0, v = map(int, input().split()) if u0 > v or (v - u0) % 2 != 0: print(-1) return 0 u = [(0) for i in range(100)] curr = 0 while u0 > 0: u[curr] = u0 % 2 u0 //= 2 curr += 1 out = [(0) for i in range(100)] s = 0 for i in range(99, -1, -1): if u[i]: s += 1 << i out[0] += 1 << i for i in range(99, -1, -1): cnt = 0 if u[i]: cnt = 1 while s + (1 << i + 1) <= v: s += 1 << i + 1 out[cnt] += 1 << i out[cnt + 1] += 1 << i cnt += 2 if s != v: print(-1) return 0 ans = 0 for i in range(0, 100): ans += out[i] != 0 print(ans) for i in range(0, 100): if out[i] == 0: break print(out[i], end=" ") main()
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
u, v = list(map(int, input().split())) def function(u, y): dict1 = {} a = bin(u)[2:] b = len(a) for i in range(b): if a[i] == "1": dict1[b - i] = 1 c = bin(y)[2:] d = len(c) for i in range(d): if c[i] == "1": if d - i in dict1.keys(): return False return True if u > v: print(-1) elif u == v: if u == 0: print(0) else: print(1) print(u) else: x = v - u if x % 2 == 1: print(-1) else: y = x // 2 if function(u, y): print(2) print(u | y, y) else: print(3) print(y, y, u)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR RETURN NUMBER RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
x, s = map(int, input().split()) if x > s: print(-1) exit(0) if x == s == 0: print(0) exit(0) if x == s: print(1) print(x) exit(0) if x == 0 and s % 2 == 1: print(-1) exit(0) elif x == 0: print(2) print(s // 2, s // 2) exit(0) if (s + x) % 2 == 1: print(-1) exit(0) lol = (s - x) // 2 if lol ^ s - lol == x: print(2) print(lol, s - lol) exit(0) print(3) print(lol, lol, x)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
x, s = map(int, input().split()) def func(x, s): if s < x or abs((s - x) % 2) == 1: return [-1] elif s == x: return [s] else: andd = (s - x) // 2 a = 0 b = 0 c = 0 for i in range(64): xi = x & 1 << i ai = andd & 1 << i if xi == 0 and ai == 0: pass elif xi == 0 and ai > 0: a = 1 << i | a b = 1 << i | b elif xi > 0 and ai == 0: a = 1 << i | a else: c = 1 << i | c if c > 0: x = x ^ c s = s - c d = [] d.extend(func(x, s)) d.append(c) return d else: return [a, b] a = func(x, s) ok = 0 for i in a: if i == -1: print(-1) ok = 1 if ok == 0: if x == 0 and s == 0: print(0) else: print(len(a)) for i in a: print(i, end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN LIST NUMBER IF VAR VAR RETURN LIST VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
import sys readline = sys.stdin.readline ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) def solve(): u, v = nm() if u == v: if u == 0: print(0) else: print(1) print(u) return elif u > v: print(-1) return w = v - u if w & 1: print(-1) else: l = [u, w // 2, w // 2] if not l[0] & l[-1]: l[0] ^= l.pop() print(len(l)) print(*l) return solve()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
import sys input = sys.stdin.readline u, v = map(int, input().split()) if u == v == 0: print(0) elif u == v: print(1) print(u) elif v > u and (v - u) % 2 == 0: a = (v - u) // 2 if u & a: print(3) print(a, a, u) else: print(2) x = a | u print(x, a) else: print(-1)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
import sys def fun(u, v): x = [0] * 64 z = (v - u) // 2 a = list(bin(u)[2:]) aa = len(a) for i in range(aa): if a[aa - i - 1] == "1": x[i] += 1 a = list(bin(z)[2:]) aa = len(a) for i in range(aa): if a[aa - i - 1] == "1": x[i] += 2 xxx = max(x) op = [] for i in range(xxx): a = 0 for j in range(64): if x[j]: x[j] -= 1 a += 2**j op.append(a) print(len(op)) print(*op) a, b = list(map(int, sys.stdin.readline().strip().split())) u, v = a, b if a > b: print(-1) elif u % 2 == 1: if v % 2 == 1: fun(u, v) else: print(-1) elif v % 2 == 0: fun(u, v) else: print(-1)
IMPORT FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
x, s = map(int, input().split()) t = (s - x) // 2 a = 0 b = 0 f = 0 if x > int(s) or int(x) % 2 != int(s) % 2: print(-1) elif int(x) == 0 and int(s) == 0: print(0) elif x == s: print(1) print(x) else: for i in range(64): y = x & 1 << i z = t & 1 << i if y == 0 and z == 0: continue elif y == 0 and z > 0: a = 1 << i | a b = 1 << i | b elif y > 0 and z == 0: a = 1 << i | a else: f = 1 break if f == 0: print(2) print(a, b) else: print(3) print(int(x), t, t)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
from sys import stdin def compute(S, X): A = (S - X) // 2 a = 0 b = 0 for i in range(64): Xi = X & 1 << i Ai = A & 1 << i if Xi == 0 and Ai == 0: pass elif Xi == 0 and Ai > 0: a = 1 << i | a b = 1 << i | b elif Xi > 0 and Ai == 0: a = 1 << i | a else: return -1 return a, b def main(): inp = stdin.readline u, v = map(int, inp().split()) if u == 0 and v == 0: print(0) elif u > v or (v - u) % 2 != 0: print("-1") elif v - u == 0: print(1) print(u) else: f = compute(v, u) if f != -1: print(2) print(f[0], f[1]) else: a = u b = (v - u) // 2 print(3) print(a, b, b) main()
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
def compute(y, x): A = (y - x) // 2 a = 0 b = 0 for i in range(64): Xi = x & 1 << i Ai = A & 1 << i if Xi == 0 and Ai == 0: pass elif Xi == 0 and Ai > 0: a = 1 << i | a b = 1 << i | b elif Xi > 0 and Ai == 0: a = 1 << i | a else: return [False, 0, 0] return [True, a, b] u, v = map(int, input().split()) if u == 0 and v == 0: print(0) elif u == 0 and v % 2 == 0: print(2) print(v // 2, v // 2) elif u > v: print(-1) elif u == v: print(1) print(u) else: if u % 2 != v % 2: print(-1) exit() ans = compute(v, u) if ans[0] == True and ans[1] != 0 and ans[2] != 0: print(2) print(ans[1], ans[2]) else: print(3) print(u, (v - u) // 2, (v - u) // 2)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN LIST NUMBER NUMBER NUMBER RETURN LIST NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. -----Input----- The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$. -----Output----- If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any. -----Examples----- Input 2 4 Output 2 3 1 Input 1 3 Output 3 1 1 1 Input 8 5 Output -1 Input 0 0 Output 0 -----Note----- In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length. Notice that in the fourth sample the array is empty.
def main(): x, y = list(map(int, input().split())) if x > y: print(-1) elif x == 0 and y == 0: print(0) elif x == y: print(1) print(x) elif ( y // 2 - x // 2 ^ y // 2 + (x + 1) // 2 == x and y // 2 - x // 2 + (y // 2 + (x + 1) // 2) == y ): print(2) print(y // 2 - x // 2, y // 2 + (x + 1) // 2) elif (y - x) % 2 == 0: print(3) print(x, (y - x) // 2, (y - x) // 2) else: print(-1) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def powerof2(n): res = 0 for i in range(n, 0, -1): if i & i - 1 == 0: res = i return res t = int(input()) for j in range(t): n = int(input()) arr = [int(x) for x in input().split()] ans = [0] * 3 i = powerof2(n) while i > 0: diff = arr[i] - arr[0] if diff < 0: diff = diff * -1 ct = diff / i if ct == 1: ct = 2 if ans[0] ^ i <= n: ans[0] = ans[0] ^ i ct -= 1 if (ct and ans[1] ^ i) <= n: ans[1] = ans[1] ^ i ct -= 1 if ct > 0 and ans[2] ^ i <= n: ans[2] = ans[2] ^ i elif ct == 3: ans[0] = ans[0] ^ i ans[1] = ans[1] ^ i ans[2] = ans[2] ^ i else: ct = diff / i if ct == 1: if ans[0] ^ i <= n: ans[0] = ans[0] ^ i elif ans[1] ^ i <= n: ans[1] = ans[1] ^ i else: ans[2] = ans[2] ^ i i = i // 2 ans.sort() print(ans[0], ans[1], ans[2])
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
for _ in range(int(input())): n = int(input()) ll = list(map(int, input().split())) x = ll[0] mm = min(ll) c = ll.index(mm) ok = False if x == 0: print(0, 0, 0) ok = True for a in range(x + 1): if ok: break b = x - c - a for i in range(n + 1): if (a ^ i) + (b ^ i) + (c ^ i) != ll[i] or max(a, b, c) > n: break elif i == n: print(b, a, c) ok = True break
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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
t = int(input()) for tt in range(t): n = int(input()) arr = list(map(int, input().split())) a = int(0) b = int(0) c = int(0) pp = 0 for pp in range(2000): pp = pp + 1 for i in range(20): if 2**i > n: break delta = int(arr[2**i] - arr[0]) delta = int(delta / 2**i) if delta == -3: a = a + 2**i b = b + 2**i c = c + 2**i elif delta == -1: a = a + 2**i b = b + 2**i elif delta == 1: a = a + 2**i else: cv = 0 cv = cv + 1 if a > n: j = 20 for i in reversed(range(21)): k = 2**i if k & a == 0: continue if b & k and c & k: continue a = a - k c = c + k j = i break if b > n: for i in reversed(range(j)): k = 2**i if k & b == 0: continue if a & k and c & k: continue if a & k == 0: a = a + k b = b - k break else: if c + k > n: continue b = b - k c = c + k break print(a, b, c)
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 NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def power2(n): res = 0 for i in range(n, 0, -1): if i & i - 1 == 0: res = i break return res t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) arr = [0, 0, 0] x = power2(n) while x > 0: dif = l[x] - l[0] if dif < 0: dif *= -1 ct = dif / x if ct == 1: ct = 2 if arr[0] ^ x <= n: arr[0] ^= x ct = ct - 1 if (ct and arr[1] ^ x) <= n: arr[1] ^= x ct = ct - 1 if ct > 0 and arr[2] ^ x <= n: arr[2] **= x elif ct == 3: arr[0] ^= x arr[1] ^= x arr[2] ^= x else: ct = dif / x if ct == 1: if arr[0] ^ x <= n: arr[0] ^= x elif arr[1] ^ x <= n: arr[1] ^= x else: arr[2] ^= x x = x // 2 arr.sort() print(arr[0], arr[1], arr[2])
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def find_p(p): for i in range(p, 0, -1): if i & i - 1 == 0: return i for _ in range(int(input())): n = int(input()) li = [int(i) for i in input().split()] i = find_p(n) res = [0] * 3 while i > 0: d = li[i] - li[0] if d < 0: d *= -1 c = d / i if c == 1: c = 2 if res[0] ^ i <= n: res[0] ^= i c -= 1 if c and res[1] ^ i <= n: res[1] ^= i c -= 1 if c > 0 and res[2] ^ i <= n: res[2] ^= i elif c == 3: res[0] ^= i res[1] ^= i res[2] ^= i else: c = d / i if c == 1: if res[0] ^ i <= n: res[0] ^= i elif res[1] ^ i <= n: res[1] ^= i else: res[2] ^= i res.sort() i = int(i / 2) print(res[0], res[1], res[2])
FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def isPowerofTwo(number): while number != 1: if number % 2: return False number /= 2 return True def hpot(n): res = 0 for i in range(n, 0, -1): if isPowerofTwo(i): res = i break return res T = int(input()) for i in range(T): N = int(input()) arr = list(map(int, input().split())) flag = 0 ans = [0, 0, 0] lis = [] marker = 0 maxi = 123456789 i = hpot(N) mini = 0 bool = True while i > 0: diff = arr[i] - arr[0] flag += 1 if diff < 0: maxi = max(marker, maxi) diff *= -1 marker += 2 ct = diff // i if ct == 1: ct = 2 mini = min(mini, flag) lis.append(marker) if ans[0] ^ i <= N: ans[0] ^= i bool = False ct -= 1 if ct and ans[1] ^ i <= N: flag += 2 ans[1] ^= i bool = True ct -= 1 lis.append(marker) if ct > 0 and ans[2] ^ i <= N: ans[2] ^= i maxi = max(flag, marker) mini += 1 elif ct == 3: flag += 1 marker -= 1 ans[0] ^= i check = 0 ans[1] ^= i ans[2] ^= i else: ct = diff // i check = 1 lis.append(mini) lis.append(maxi) if ct == 1: if ans[0] ^ i <= N: ans[0] ^= i bool = False elif ans[1] ^ i <= N: check += 2 ans[1] ^= i bool = False else: check = 0 lis.append(check) ans[2] ^= i ans.sort() i //= 2 mini = min(flag, marker) print(str(ans[0]) + " " + str(ans[1]) + " " + str(ans[2]))
FUNC_DEF WHILE VAR NUMBER IF BIN_OP VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def check(x, y, z, b): for i in range(len(b)): if (x ^ i) + (y ^ i) + (z ^ i) != b[i]: return False return True for x in range(int(input())): a = int(input()) b = list(map(int, input().split())) if 0 in b: c = b.index(0) print(c, c, c) else: c = b.index(min(b)) d = b[0] - c l = d // 2 r = d // 2 + d % 2 while l >= 0 and r <= a + 1: if check(c, l, r, b): print(c, l, r) break l -= 1 r += 1
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN 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 IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def isPowerofTwo(number): while number != 1: if number % 2: return False number /= 2 return True def hpot(n): res = 0 for i in range(n, 0, -1): if isPowerofTwo(i): res = i break return res T = int(input()) for i in range(T): N = int(input()) arr = list(map(int, input().split())) ans = [0, 0, 0] i = hpot(N) while i > 0: diff = arr[i] - arr[0] if diff < 0: diff *= -1 ct = diff // i if ct == 1: ct = 2 if ans[0] ^ i <= N: ans[0] ^= i ct -= 1 if ct and ans[1] ^ i <= N: ans[1] ^= i ct -= 1 if ct > 0 and ans[2] ^ i <= N: ans[2] ^= i elif ct == 3: ans[0] ^= i ans[1] ^= i ans[2] ^= i else: ct = diff // i if ct == 1: if ans[0] ^ i <= N: ans[0] ^= i elif ans[1] ^ i <= N: ans[1] ^= i else: ans[2] ^= i ans.sort() i //= 2 print(str(ans[0]) + " " + str(ans[1]) + " " + str(ans[2]))
FUNC_DEF WHILE VAR NUMBER IF BIN_OP VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
for t in range(int(input())): n = int(input()) f = list(map(int, input().split())) m = bin(n) po = len(m) - 2 a = "0b" b = "0b" c = "0b" s = f[0] q = 2 ** (po - 1) saved = [False, False] for i in range(po): r = f[q] - s if r == 3 * q: a += "0" b += "0" c += "0" elif r == -3 * q: a += "1" b += "1" c += "1" elif r == q: quan = saved.count(True) if quan == 0: a += "0" b += "0" c += "1" saved[0] = True saved[1] = True else: a += "1" b += "0" c += "0" else: quan = saved.count(True) if quan == 0: a += "0" b += "1" c += "1" saved[0] = True elif quan == 1: a += "1" b += "0" c += "1" saved[1] = True else: a += "1" b += "1" c += "0" q //= 2 print(int(a, 2), int(b, 2), int(c, 2))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP NUMBER VAR VAR STRING VAR STRING VAR STRING IF VAR BIN_OP NUMBER VAR VAR STRING VAR STRING VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER NUMBER VAR STRING VAR STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
T = int(input()) def find(v, o, j): if v == o: return -1 elif v > o: if v - o == 2**j: return 1 else: return 0 elif o - v == 2**j: return 2 else: return 3 def bits(N): i = 0 while N >= 2**i: i += 1 return i def algo(): N = int(input()) A = list(map(int, input().split())) t = A[0] out = [0, 0, 0] bi = bits(N) for j in range(bi - 1, -1, -1): k = find(A[2**j], t, j) n = 0 for i in range(k): while out[n] + 2**j > N: n += 1 out[n] += 2**j n += 1 out.sort() for i in out: print(i, end=" ") print() for i in range(T): algo()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN 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 LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
for t in range(int(input())): n = int(input()) arr = list(map(int, input().split())) i = 1 while i <= n: if i << 1 > n: break else: i = i << 1 ans = [0, 0, 0] while i > 0: k = arr[i] - arr[0] if k < 0: k *= -1 z = k // i if z == 3: ans[0] ^= i ans[1] ^= i ans[2] ^= i elif z == 1: z = 2 if ans[0] ^ i <= n: ans[0] ^= i z -= 1 if z and ans[1] ^ i <= n: ans[1] ^= i z -= 1 if z > 0 and ans[2] ^ i <= n: ans[2] ^= i else: z = k // i if z == 1: if ans[0] ^ i <= n: ans[0] ^= i elif ans[1] ^ i <= n: ans[1] ^= i else: ans[2] ^= i i = i // 2 ans.sort() print(*ans, sep=" ")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def maxPowOf2(n): while n: if n & n - 1 == 0: return n n -= 1 return 1 t = int(input()) while t: t -= 1 n = int(input()) x = list(map(int, input().split())) s = x[0] idx = maxPowOf2(n) ans = [0, 0, 0] while idx > 0: ans.sort() if s > x[idx]: noOfOnes = (s - x[idx]) // idx for i in range(noOfOnes): ans[i] = ans[i] + idx if noOfOnes == 1: ans[1] = ans[1] + idx elif (x[idx] - s) // idx < 3: ans[0] = ans[0] + idx idx //= 2 for i in ans: if i > n: while 1: print("hlnow") print(i, end=" ") print("")
FUNC_DEF WHILE VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR WHILE NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
for t in range(int(input())): n = int(input()) arr = list(map(int, input().split())) a, b, c = [], [], [] isA, isB, isC = False, False, False nbin = bin(n)[2:] d = len(nbin) i = 0 curr = 2 ** (d - 1) while i < d: diff = (arr[curr] - arr[0]) // curr if diff == 3: if nbin[i] == "1": isA, isB, isC = True, True, True a.append("0") b.append("0") c.append("0") if diff == 1: if isA: a.append("1") b.append("0") c.append("0") if nbin[i] == "1": isB, isC = True, True elif isB: a.append("0") b.append("1") c.append("0") if nbin[i] == "1": isA, isC = True, True else: a.append("0") b.append("0") c.append("1") if nbin[i] == "1": isA, isB = True, True if diff == -1: if not isA: a.append("0") b.append("1") c.append("1") if nbin[i] == "1": isA = True elif not isB: a.append("1") b.append("0") c.append("1") if nbin[i] == "1": isB = True else: a.append("1") b.append("1") c.append("0") if nbin[i] == "1": isC = True if diff == -3: a.append("1") b.append("1") c.append("1") i += 1 curr //= 2 x, y, z = int("".join(a), 2), int("".join(b), 2), int("".join(c), 2) print(x, y, z)
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 VAR VAR LIST LIST LIST ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING ASSIGN VAR VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
t = int(input()) while t: n = int(input()) array = list(map(int, input().split())) for j in range(n, 0, -1): if j & j - 1 == 0: i = j break res = [0, 0, 0] while i > 0: temp = 0 m = array[i] - array[0] if m < 0: m *= -1 calino = m / i if calino == 1: calino = 2 for alpha in range(10): temp += alpha if res[0] ^ i <= n: res[0] ^= i calino -= 1 if calino and res[1] ^ i <= n: res[1] ^= i calino -= 1 if calino > 0 and res[2] ^ i <= n: res[2] ^= i elif calino == 3: for alpha in range(10): temp += alpha res[0] ^= i res[1] ^= i res[2] ^= i else: for alpha in range(10): temp += alpha calino = m / i if calino == 1: for alpha in range(10): temp += alpha if res[0] ^ i <= n: res[0] ^= i elif res[1] ^ i <= n: res[1] ^= i else: res[2] ^= i temp = temp - res[0] res.sort() i = int(i / 2) name = "yashvardhan" print(*res) t -= 1 name += " Rathore"
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER VAR STRING
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) for i in range(n, 0, -1): if i & i - 1 == 0: res = i break val = [0] * 3 i = res while i > 0: dif = l[i] - l[0] if dif < 0: dif = dif * -1 c = dif // i if c == 1: c = 2 if val[0] ^ i <= n: val[0] = val[0] ^ i c -= 1 if c and val[1] ^ i <= n: val[1] ^= i c -= 1 if c > 0 and val[2] ^ i <= n: val[2] ^= i elif c == 3: val[0] ^= i val[1] ^= i val[2] ^= i else: c = dif // i if c == 1: if val[0] ^ i <= n: val[0] ^= i elif val[1] ^ i <= n: val[1] ^= i else: val[2] ^= i i = i // 2 val.sort() for i in val: print(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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def deep_dive(a, b, c, bundles, base, level): if level == len(bundles): if a <= n and b <= n and c <= n: return [a, b, c] return False bundle = bundles[level] is_success = deep_dive( a + bundle[0] * base, b + bundle[1] * base, c + bundle[2] * base, bundles, base * 2, level + 1, ) if is_success: return is_success is_success = deep_dive( a + bundle[1] * base, b + bundle[2] * base, c + bundle[0] * base, bundles, base * 2, level + 1, ) if is_success: return is_success is_success = deep_dive( a + bundle[2] * base, b + bundle[0] * base, c + bundle[1] * base, bundles, base * 2, level + 1, ) return is_success T = int(input()) for _ in range(T): n = int(input()) values = [int(x) for x in input().split()] two_places = [values[0]] jump = 1 while jump < len(values): two_places.append(values[jump]) jump = jump * 2 _A, _B, _C = [], [], [] for i in range(1, len(two_places)): change = two_places[0] - two_places[i] if abs(change) == 2 ** (i - 1): if change > 0: _A.append(1) _B.append(1) _C.append(0) else: _A.append(1) _B.append(0) _C.append(0) elif change > 0: _A.append(1) _B.append(1) _C.append(1) else: _A.append(0) _B.append(0) _C.append(0) bundles = [] for a, b, c in zip(_A, _B, _C): bundle = a, b, c bundles.append(bundle) final_ans = deep_dive(0, 0, 0, bundles, 1, 0) print(*final_ans, sep=" ")
FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN LIST VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST LIST LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) li2 = [0, 0, 0] temp1 = 0 for i in range(n, 0, -1): if i & i - 1 == 0: temp1 = i break j = temp1 while j > 0: x = a[j] - a[0] if x < 0: x = x * -1 count = x // j if count == 1: count = 2 if li2[0] ^ j <= n: li2[0] ^= j count = count - 1 if count & (li2[1] ^ j) <= n: li2[1] ^= j count = count - 1 if count > 0 & (li2[2] ^ j <= n): li2[2] ^= j elif count == 3: li2[0] ^= j li2[1] ^= j li2[2] ^= j else: count = x // j if count == 1: if li2[0] ^ j <= n: li2[0] ^= j elif li2[1] ^ j <= n: li2[1] ^= j else: li2[2] ^= j li2.sort() j //= 2 for i in range(len(li2)): print(li2[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 NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
for test in range(int(input())): n = int(input()) lst = list(map(int, input().split())) if lst[0] == 0: print("0 0 0") else: a = lst.index(min(lst)) lst = [(lst[i] - (a ^ i)) for i in range(n + 1)] rev = lst[::-1] b = n - rev.index(min(rev)) lst = [(lst[i] - (b ^ i)) for i in range(n + 1)] c = lst.index(0) print(*sorted([a, b, c]), sep=" ")
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 IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR VAR STRING
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def indexes(ar, n): ind = n min = ar[n] for i in range(n, -1, -1): if min > ar[i]: ind = i min = ar[i] return ind def valid(ar, a, i, n): b_p = i ^ a c_p = ar[a] - i ^ a if max(b_p, c_p) > n: return False check = 0 if (a ^ b_p) + (c_p ^ b_p) == ar[b_p]: check += 1 if (a ^ c_p) + (c_p ^ b_p) == ar[c_p]: check += 1 if check == 2: return True else: return False def cal(ar, a, n): for i in range(ar[a] // 2 + 1): if valid(ar, a, i, n): return [i ^ a, ar[a] - i ^ a] return [a, a] t = int(input()) while t > 0: n = int(input()) ar = [int(i) for i in input().split(" ")] a = indexes(ar, n) ar2 = [] for i in range(n + 1): ar2.append(ar[i] - a ^ i) ans = cal(ar, a, n) print(a, ans[0], ans[1]) t -= 1
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR RETURN LIST BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
from sys import stdin a = int(stdin.readline()) for t in range(0, a): b = int(stdin.readline()) c = stdin.readline().split() d = [int(x) for x in c] start = d[0] f = dict() counter = 0 solution = 0 while 2**counter < len(d): f[counter] = 0 if d[2**counter] - start == 2**counter * 3: f[counter] += 0 elif d[2**counter] - start == 2**counter * 1: f[counter] += 1 elif d[2**counter] - start == 2**counter * -1: f[counter] += 2 elif d[2**counter] - start == 2**counter * -3: f[counter] += 0 solution += 2**counter counter = counter + 1 if 2**counter >= len(d): counter -= 1 break counter2 = counter solution2 = solution while counter2 >= 0: if solution + 2**counter2 <= b and f[counter2] > 0: solution += 2**counter2 f[counter2] -= 1 counter2 -= 1 counter3 = counter while counter3 >= 0: if f[counter3] == 2: solution2 += 2**counter3 f[counter3] = 0 counter3 -= 1 while counter >= 0: if solution2 + 2**counter <= b and f[counter] > 0: solution2 += 2**counter f[counter] -= 1 counter -= 1 print(solution, solution2, start - solution - solution2)
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) L = [0, 0, 0] for i in range(20, -1, -1): if 2**i > n: continue L = list(sorted(L)) delta = (3 - (arr[2**i] - arr[0]) // 2**i) // 2 for j in range(delta): L[j] += 2**i print(L[0], L[1], L[2])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
def pow(i): return i & i - 1 == 0 for _ in range(int(input())): n = int(input()) f = list(map(int, input().split())) a, b, c = 0, 0, 0 numXbits = [ ((f[0] - f[i] + 3 * i) // (2 * i) if i != 0 and pow(i) else 0) for i in range(n + 1) ] for i in range(n, -1, -1): if numXbits[i] == 1: if min(a, b, c) == a: a += i elif min(a, b, c) == b: b += i else: c += i elif numXbits[i] == 2: if max(a, b, c) == c: a += i b += i elif max(a, b, c) == a: b += i c += i else: a += i c += i elif numXbits[i] == 3: a += i b += i c += i print(a, b, c)
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER 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 VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
for _ in range(int(input())): N = int(input()) input_list = list(map(int, input().split())) next_idx = 1 bits_count = {} for idx, val in enumerate(input_list): if idx == next_idx: diff = int((input_list[idx] - input_list[0]) / idx) if diff == -3: bits_count[idx] = 3 elif diff == -1: bits_count[idx] = 2 elif diff == 1: bits_count[idx] = 1 next_idx = idx * 2 total = 0 for k in bits_count: if bits_count[k] == 3: total = total + k data = [total, total, total] for k in sorted(bits_count, reverse=True): if bits_count[k] == 2: data[0] = data[0] + k data[1] = data[1] + k elif bits_count[k] == 1: data[0] = data[0] + k data.sort() print(f"{data[0]} {data[1]} {data[2]}")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) l = [0, 0, 0] v = 1 dc = {} while v <= n: d = (a[v] - a[0]) // v d = (3 - d) // 2 dc[v] = d v = v << 1 for k in sorted(dc.keys())[::-1]: d = dc[k] for i in range(d): l[i] |= k l.sort() print(*l)
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 NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) f = list(map(int, input().split())) ans = [0, 0, 0] ones = [] i = 1 while i <= n: ones.append((3 - (f[i] - f[0]) // i) // 2) i *= 2 while len(ones) > 0: for i in range(3): ans[i] *= 2 for i in range(ones[-1]): ans[i] += 1 ones.pop() ans.sort() print(ans[0], ans[1], ans[2])
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
Chef has 3 hidden numbers A, B, and C such that 0 ≀ A, B, C ≀ N. Let f be a function such that f(i) = (A \oplus i) + (B \oplus i) + (C \oplus i). Here \oplus denotes the [bitwise XOR] operation. Given the values of f(0), f(1), \dots, f(N), determine the values of A, B, and C. It is guaranteed that at least one tuple exists for the given input. If there are multiple valid tuples of A, B, C, print any one. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of multiple lines of input. - The first line of each test case contains a single integer N denoting the upper bound on the values of A, B, C. - Next line contains N+1 space-separated integers denoting f(0), f(1), \dots, f(N). ------ Output Format ------ For each test case, output on a new line, three space-separated integers, the values of A, B, and C. If there are multiple valid tuples of A, B, C, print any one. ------ Constraints ------ $1 ≀ T ≀ 2 \cdot 10^{4}$ $2 ≀ N ≀ 10^{5}$ - Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 2 0 3 6 2 4 7 2 5 9 6 11 8 13 10 ----- Sample Output 1 ------ 0 0 0 2 0 2 1 3 5 ----- explanation 1 ------ Test case $1$: The tuple $A = 0, B=0, C=0$ satisfies as: - $f(0)= 0\oplus 0 + 0\oplus 0 + 0\oplus 0 = 0$. - $f(1)= 0\oplus 1 + 0\oplus 1 + 0\oplus 1 = 3$. - $f(2)= 0\oplus 2 + 0\oplus 2 + 0\oplus 2 = 6$. Test case $2$: The tuple $A = 2, B=0, C=2$ satisfies as: - $f(0)= 2\oplus 0 + 0\oplus 0 + 2\oplus 0 = 4$. - $f(1)= 2\oplus 1 + 0\oplus 1 + 2\oplus 1 = 7$. - $f(2)= 2\oplus 2 + 0\oplus 2 + 2\oplus 2 = 2$. Test case $3$: The tuple $A = 1, B=3, C=5$ satisfies as: - $f(0)= 1\oplus 0 + 3\oplus 0 + 5\oplus 0 = 9$. - $f(1)= 1\oplus 1 + 3\oplus 1 + 5\oplus 1 = 6$. - $f(2)= 1\oplus 2 + 3\oplus 2 + 5\oplus 2 = 11$. - $f(3)= 1\oplus 3 + 3\oplus 3 + 5\oplus 3 = 8$. - $f(4)= 1\oplus 4 + 3\oplus 4 + 5\oplus 4 = 13$. - $f(5)= 1\oplus 5 + 3\oplus 5 + 5\oplus 5 = 10$.
t = int(input()) for _ in range(t): n = int(input()) f = list(map(int, input().split())) abc = [0, 0, 0] j = 0 for i in range(n, 0, -1): if i & i - 1 == 0: j = i break while j > 0: diff = f[j] - f[0] if diff < 0: diff *= -1 count = diff // j if count == 1: count = 2 if abc[0] ^ j <= n: abc[0] ^= j count -= 1 if count != 0 and abc[1] ^ j <= n: abc[1] ^= j count -= 1 if count != 0 and abc[2] ^ j <= n: abc[2] ^= j elif count == 3: abc[0], abc[1], abc[2] = abc[0] ^ j, abc[1] ^ j, abc[2] ^ j else: count = diff // j if count == 1: if abc[0] ^ j <= n: abc[0] ^= j elif abc[1] ^ j <= n: abc[1] ^= j else: abc[2] ^= j abc.sort() j = j // 2 print(*abc, sep=" ", end="\n")
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 NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def getints(): return map(int, input().split()) z, o, k = getints() if k == 0: print("Yes") s = "1" * o + "0" * z print(s) print(s) elif o == 1 or z == 0: print("No") elif k <= z + o - 2: print("Yes") if k >= o: mx = z + o - 2 print( "1" + "0" * (mx - k) + "1" + "0" * (z - 1 - (mx - k)) + "1" * (o - 2) + "0" ) else: print("1" + "0" * (z - 1) + "1" * k + "0" + "1" * (o - k - 1)) print("1" + "0" * z + "1" * (o - 1)) else: print("No")
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
from sys import stdin, stdout t = 1 for _ in range(t): a, b, k = map(int, input().split()) if a == 0 and k == 0: print("YES") val = ["1" for i in range(b)] s = "".join(val) print(s) print(s) continue if a == 0: print("NO") continue if k > a + b - 2: print("NO") continue if b == 1: if k != 0: print("NO") continue print("YES") out = ["1"] for i in range(a): out.append("0") s = "".join(out) print(s) print(s) continue if k == 0: print("YES") val = [] for i in range(b): val.append("1") for i in range(a): val.append("0") s = "".join(val) print(s) print(s) continue val1 = [] val2 = [] if k <= a: val1 = [] val2 = [] for i in range(b): val1.append("1") if i == b - 1: val2.append("0") else: val2.append("1") count = 0 for i in range(a): val1.append("0") count += 1 if count == k: val2.append("1") else: val2.append("0") s1 = "".join(val1) s2 = "".join(val2) print("YES") print(s1) print(s2) continue for i in range(b): val1.append("1") for i in range(a): val1.append("0") val2.append("1") c = 0 for i in range(a - 1): val2.append("0") k -= a used = 1 for i in range(k): used += 1 val2.append("1") val2.append("0") for i in range(b - used): val2.append("1") val2 = val2[::-1] s1 = "".join(val1) s2 = "".join(val2) print("YES") print(s1) print(s2)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def main(): inp = input().rstrip().split(" ") a, b, k = int(inp[0]), int(inp[1]), int(inp[2]) x = [] y = [] if b == 1 or a == 0: if k == 0: print("Yes") for _ in range(b): x.append("1") y.append("1") for _ in range(a): x.append("0") y.append("0") print("".join(x)) print("".join(y)) else: print("No") elif k > a + b - 2: print("No") else: print("Yes") if k <= a: y.append("1") for _ in range(k): x.append("0") y.append("0") x.append("1") for _ in range(k, a): x.append("0") y.append("0") for _ in range(b - 1): x.append("1") y.append("1") x.reverse() y.reverse() else: for _ in range(b): x.append("1") y.append("1") for _ in range(a): x.append("0") y.append("0") y[-1] = "1" y[a + b - 2 - k + 1] = "0" print("".join(x)) print("".join(y)) main()
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def arrIn(): return list(map(int, input().split())) def mapIn(): return map(int, input().split()) a, b, k = mapIn() if b == 0: if k > 0: print("NO") else: print("YES") s = "0" * a + "1" * b print(s) print(s) elif b == 1: if k == 0: print("YES") s = "1" + "0" * a print(s) print(s) else: print("NO") elif k > a + b - 2: print("NO") elif a == 0: if k > 0: print("NO") else: print("YES") s = "1" * b print(s) print(s) else: print("YES") n = a + b s = "" x = b for i in range(n): if x: x -= 1 s += "1" else: s += "0" x = [0] * n x[0] = 1 x[1] = 0 y = b - 2 for i in range(2, n - 1): if y: x[i] = 1 y -= 1 x[n - 1] = 1 y = b - 2 z = n - 2 - k if z > 0: i = 2 if x[i] != 0: y -= 1 z -= 1 while y > 0 and z > 0: y -= 1 z -= 1 i += 1 x[1], x[i] = x[i], x[1] if z > 0: z -= 1 i = n - 2 while z: z -= 1 i -= 1 x[i], x[n - 1] = x[n - 1], x[i] print(s) for i in range(n): print(x[i], end="")
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def solve(): global x, y if b == 1 or a == 0 or k == 0: if k > 0: return print("No") print("Yes") x = "1" * b + "0" * a print(x + "\n" + x) return if k >= a + b - 1: return print("No") c = min(k - 1, a - 1) d = max(0, k - 1 - c) x = "1" + "1" + "0" * c + "1" * d + "0" + "0" * (a - 1 - c) + "1" * (b - 2 - d) y = "1" + "0" + "0" * c + "1" * d + "1" + "0" * (a - 1 - c) + "1" * (b - 2 - d) print("Yes") print(x + "\n" + y) check = lambda x, y: bin(int(x, 2) - int(y, 2))[2:] read = lambda: map(int, input().split()) a, b, k = read() solve()
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR RETURN IF VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING STRING BIN_OP STRING VAR BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING STRING BIN_OP STRING VAR BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
from sys import stdin, stdout input = stdin.readline def main(inp): a, b, k = inp if b == 1: if k != 0: print("No") else: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) return if a == 0: if k != 0: print("No") else: print("Yes") print("1" * b) print("1" * b) return if k == a + b: print("No") return if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) return if k <= a: print("Yes") print("1" * b + "0" * a) print("1" * (b - 1) + "0" * k + "1" + "0" * (a - k)) return if k - a < b - 1: num = k - a print("Yes") print("1" * (b - num) + "0" * (a - 1) + "1" * num + "0") print("1" * (b - 1 - num) + "0" * a + "1" * num + "1") return print("No") main(map(int, input().split()))
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR RETURN IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR RETURN IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR RETURN IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR BIN_OP STRING VAR BIN_OP STRING VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
from sys import gettrace, stdin if gettrace(): def inputi(): return input() else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def main(): a, b, k = map(int, input().split()) if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) return if k > a + b - 2 or b < 2 or a == 0: print("No") return print("Yes") print("1" * b + "0" * a) if k < a: print("1" * (b - 1) + "0" * k + "1" + "0" * (a - k)) else: print("1" * (a + b - k - 1) + "0" + "1" * (k - a) + "0" * (a - 1) + "1") main()
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR RETURN IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
x = input().split() a = int(x[0]) b = int(x[1]) k = int(x[2]) if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) elif k < b and a > 0: print("Yes") print("1" * b + "0" * a) print("1" * (b - k) + "0" + "1" * k + "0" * (a - 1)) elif k < a + b and b > 1 and a > k - b + 1 and a > 0: print("Yes") print("11" + "0" * (k - b + 1) + "1" * (b - 2) + "0" * (a + b - k - 1)) print("10" + "0" * (k - b + 1) + "1" * (b - 1) + "0" * (a + b - k - 2)) else: print("No")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def solution(): a, b, k = map(int, input().split()) if k > max(a + b - 2, 0) or b == 1 and k != 0 or a == 0 and k != 0: print("No") elif k <= a: print( "Yes", b * "1" + a * "0", (b - 1) * "1" + k * "0" + "1" + (a - k) * "0", sep="\n", ) else: print( "Yes", b * "1" + a * "0", (b + a - k - 1) * "1" + "0" + (k - a) * "1" + (a - 1) * "0" + "1", sep="\n", ) solution()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER STRING BIN_OP VAR STRING STRING BIN_OP BIN_OP VAR VAR STRING STRING EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING STRING BIN_OP BIN_OP VAR VAR STRING BIN_OP BIN_OP VAR NUMBER STRING STRING STRING EXPR FUNC_CALL VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys zz = 1 sys.setrecursionlimit(10**5) if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def fori(n): return [fi() for i in range(n)] def inc(d, c, x=1): d[c] = d[c] + x if c in d else x def ii(): return input().rstrip() def li(): return [int(xx) for xx in input().split()] def fli(): return [float(x) for x in input().split()] def dadd(d, p, val): if p in d: d[p].append(val) else: d[p] = [val] def gi(): return [xx for xx in input().split()] def gtc(tc, ans): print("Case #" + str(tc) + ":", ans) def cil(n, m): return n // m + int(n % m > 0) def fi(): return int(input()) def pro(a): return reduce(lambda a, b: a * b, a) def swap(a, i, j): a[i], a[j] = a[j], a[i] def prec(a, pre): for i in a: pre.append(pre[-1] + i) pre.pop(0) def si(): return list(input().rstrip()) def mi(): return map(int, input().split()) def gh(): sys.stdout.flush() def isvalid(i, j, n, m): return 0 <= i < n and 0 <= j < m def bo(i): return ord(i) - ord("a") def graph(n, m): for i in range(m): x, y = mi() a[x].append(y) a[y].append(x) t = 1 uu = t while t > 0: t -= 1 a, b, k = mi() w = k if min(a, b) >= 2 and k > a + b - 2: print("No") else: b -= 1 a1 = "1" a2 = "1" if min(a, b) == 1: if k > max(a, b): print("No") exit(0) if min(a, b) == 0: if k == 0: print("Yes") if a == 0: print(a1 + "1" * b) print(a2 + "1" * b) else: print(a1 + "0" * a) print(a2 + "0" * a) else: print("No") exit(0) if k <= a: a1 += "1" + "0" * k a2 += "0" * k + "1" a1 += "0" * (a - k) + "1" * (b - 1) a2 += "0" * (a - k) + "1" * (b - 1) elif k <= b: a1 += "1" * k + "0" a2 += "0" + "1" * k a1 += "0" * (a - 1) + "1" * (b - k) a2 += "0" * (a - 1) + "1" * (b - k) else: if k == a + b - 1: a1 += "1" * b + "0" * a a2 += "0" + "1" * (b - 1) + "0" * (a - 1) + "1" print("Yes") print(a1) print(a2) exit(0) a1 += "1" + "0" * (a - 1) a2 += "0" * (a - 1) + "1" k -= a - 1 a = 1 b -= 1 a1 += "1" * min(k, b) + "0" a2 += "0" + "1" * min(k, b) a1 += "0" * (a - 1) + "1" * (b - k) a2 += "0" * (a - 1) + "1" * (b - k) print("Yes") print(a1) print(a2)
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP STRING BIN_OP STRING VAR VAR BIN_OP BIN_OP STRING VAR STRING VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP STRING VAR STRING VAR BIN_OP STRING BIN_OP STRING VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR VAR STRING VAR BIN_OP STRING BIN_OP STRING FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) n = a + b if k == n: print("no") elif k == 0: print("yes") s = ["1"] * b + ["0"] * a print("".join(s)) print("".join(s)) elif a == 0: print("no") elif k == n - 1: print("no") elif k + 1 <= b: print("yes") res1 = ["1"] + ["1"] * k + ["0"] + ["1"] * (b - (k + 1)) + ["0"] * (a - 1) res2 = ["1", "0"] + ["1"] * k + ["1"] * (b - (k + 1)) + ["0"] * (a - 1) print("".join(res1)) print("".join(res2)) elif b == 1: print("No") else: print("yes") res1 = ( ["0"] + ["1"] * (b - 2) + ["0"] * (k - b + 1) + ["1"] + ["0"] * (n - k - 2) + ["1"] ) res2 = ["1"] * (b - 1) + ["0"] * a + ["1"] print("".join(res1[::-1])) print("".join(res2[::-1]))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP LIST STRING BIN_OP LIST STRING VAR LIST STRING BIN_OP LIST STRING BIN_OP VAR BIN_OP VAR NUMBER BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST STRING STRING BIN_OP LIST STRING VAR BIN_OP LIST STRING BIN_OP VAR BIN_OP VAR NUMBER BIN_OP LIST STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP LIST STRING BIN_OP LIST STRING BIN_OP VAR NUMBER BIN_OP LIST STRING BIN_OP BIN_OP VAR VAR NUMBER LIST STRING BIN_OP LIST STRING BIN_OP BIN_OP VAR VAR NUMBER LIST STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST STRING BIN_OP VAR NUMBER BIN_OP LIST STRING VAR LIST STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) x = "1" * (b - 1) + "0" * (a - 1) if k == 0: print("YES", "1" * b + "0" * a, "1" * b + "0" * a, sep="\n") elif a + b - 2 >= k and b != 1 and a != 0: print( "YES", x[: a + b - 1 - k] + "1" + x[a + b - 1 - k :] + "0", x[: a + b - 1 - k] + "0" + x[a + b - 1 - k :] + "1", sep="\n", ) else: print("NO")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR STRING BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR STRING STRING EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) s1 = "1" s2 = "1" if b == 1: if k == 0: print("Yes") print("1" + "0" * a) print("1" + "0" * a) exit(0) print("No") exit() pos1 = 1 pos2 = 1 + k s1 = list("0" * (a + b)) s2 = list("0" * (a + b)) s1[0] = s2[0] = "1" try: s1[pos1] = "1" s2[pos2] = "1" have = b - 2 for i in range(a + b): if not have: break if s1[i] == "0" and s2[i] == "0": have -= 1 s1[i] = s2[i] = "1" if have != 0: print("No") exit(0) except IndexError: print("No") exit(0) try: s1 = "".join(s1) s2 = "".join(s2) m = int(s1, 2) n = int(s2, 2) c = bin(m - n)[2:] assert c.count("1") == k except Exception as e: print("No") exit(0) print("Yes") print(s1) print(s2)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys def main(): a, b, k = readIntArr() if k == 0: x = b * "1" + a * "0" print("Yes") print(x) print(x) elif k >= a + b - 1: print("No") elif not (a >= 1 and b >= 2): print("No") else: n = a + b x = [None for _ in range(n)] y = [None for _ in range(n)] x[0] = y[0] = "1" x[n - 1] = "0" y[n - 1] = "1" x[n - k - 1] = "1" y[n - k - 1] = "0" a -= 1 b -= 2 for i in range(n): if x[i] == None: if a > 0: x[i] = "0" y[i] = "0" a -= 1 else: x[i] = "1" y[i] = "1" print("Yes") print("".join(x)) print("".join(y)) return input = lambda: sys.stdin.readline().rstrip("\r\n") def oneLineArrayPrint(arr): print(" ".join([str(x) for x in arr])) def multiLineArrayPrint(arr): print("\n".join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print("\n".join([" ".join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] inf = float("inf") MOD = 10**9 + 7 main()
IMPORT FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = list(map(int, input().split())) if a == 0 and k != 0: print("No") elif k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) elif b == 1 or k > a + b - 2: print("No") else: shift = a + b - 2 - k print("Yes") ans_1 = ["1" for _ in range(b)] + ["0" for _ in range(a)] ans_2 = ( ["1"] + ["0"] + ["1" for _ in range(b - 2)] + ["0" for _ in range(a - 1)] + ["1"] ) if shift <= a - 1: ans_2 = ( ["1"] + ["0"] + ["1" for _ in range(b - 2)] + ["0" for _ in range(a - 1 - shift)] + ["1"] + ["0" for _ in range(shift)] ) else: ans_2 = ( ["1"] + ["1" for _ in range(shift - (a - 1))] + ["0"] + ["1" for _ in range(b - 2 - (shift - (a - 1)))] + ["1"] + ["0" for _ in range(a - 1)] ) print("".join(ans_1)) print("".join(ans_2))
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP LIST STRING LIST STRING STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER LIST STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP LIST STRING LIST STRING STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR LIST STRING STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP LIST STRING STRING VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER LIST STRING STRING VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER LIST STRING STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) exit(0) if a == 0 or b == 0: print("No") exit(0) a -= 1 b -= 1 if b == 0: print("No") exit(0) s = "1" * b + "0" * a b -= 1 k -= 1 if k > a + b: print("No") exit(0) print("Yes") print(s[: len(s) - k] + "1" + s[len(s) - k :] + "0") print(s[: len(s) - k] + "0" + s[len(s) - k :] + "1")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) if k != 0 and (b == 1 or a == 0) or a < min(k, k - b + 2): print("No") else: print("Yes") print("1" * b + "0" * a) if k <= a: print("1" * (b - 1) + "0" * k + "1" + "0" * (a - k)) else: print("1" * (a + b - k - 1) + "0" + "1" * (k - a) + "0" * (a - 1) + "1")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) if a == 0: if k == 0: print("YES") print("1" * b) print("1" * b) else: print("NO") exit(0) if b == 1: if k == 0: print("YES") print("1" + "0" * a) print("1" + "0" * a) else: print("NO") exit(0) if k > a + b - 2: print("NO") exit(0) print("YES") print("1" * b + "0" * a) if k <= a: print("1" * (b - 1) + k * "0" + "1" + "0" * (a - k)) exit(0) t = k - a print("1" * (b - t - 1) + "0" + "1" * t + "0" * (a - 1) + "1")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR STRING STRING BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) if k == 0: x = [1] for i in range(a + b - 1): if a: x.append(0) a -= 1 else: x.append(1) print("Yes") print("".join(map(str, x))) print("".join(map(str, x))) elif k >= a + b - 1: print("No") elif b == 1 or a == 0: print("No") else: print("Yes") x = [1, 1] y = [1, 0] b -= 2 a -= 1 for i in range(k - 1): if a > 0: x.append(0) y.append(0) a -= 1 else: x.append(1) y.append(1) b -= 1 x.append(0) y.append(1) while a > 0: x.append(0) y.append(0) a -= 1 while b > 0: x.append(1) y.append(1) b -= 1 print("".join(map(str, x))) print("".join(map(str, y)))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) b -= 1 if a == 0: if k == 0: x = "1" * b y = "1" * b else: x = None y = None elif b == 0: if k == 0: x = "0" * a y = "0" * a else: x = None y = None elif k >= a + b: x = None y = None elif k <= b: x = "0" * (a - 1) + "1" * k + "0" + "1" * (b - k) y = "0" * a + "1" * b else: x = "0" * (a + b - 1 - k) + "1" + "0" * (k - b) + "1" * (b - 1) + "0" y = "0" * a + "1" * b if x is None: print("No") else: print("Yes") x = "1" + x y = "1" + y print(x) print(y)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NONE ASSIGN VAR NONE IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NONE ASSIGN VAR NONE IF VAR BIN_OP VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys input = sys.stdin.readline l = input().split() a = int(l[0]) b = int(l[1]) k = int(l[2]) if k == 0: print("Yes") print("1" * b, end="") print("0" * a) print("1" * b, end="") print("0" * a) quit() if a == 0: if k == 0: print("Yes") print("1" * b) print("1" * b) else: print("No") quit() if b == 1: if k == 0: print("Yes") print(1, end="") print("0" * a) print(1, end="") print("0" * a) else: print("No") quit() if k > a + b - 2: print("No") quit() print("Yes") l1 = [] l2 = [] l1.append(1) l2.append(1) rem1 = b - 1 rem0 = a l1.append(1) l2.append(0) rem1 -= 1 for i in range(k - 1): if rem1: l1.append(1) l2.append(1) rem1 -= 1 else: l1.append(0) l2.append(0) rem0 -= 1 l1.append(0) l2.append(1) for i in range(a + b - (k + 2)): if rem1: l1.append(1) l2.append(1) rem1 -= 1 else: l1.append(0) l2.append(0) rem0 -= 1 for i in l1: print(i, end="") print() for i in l2: print(i, end="") print()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys __version__ = "2.1" __date__ = "2021-03-10" def solve(a, b, k): x = "1" * b + "0" * a if k <= b and k <= a: y = "1" * (b - 1) + "0" * k + "1" + "0" * (a - k) elif k > b: y = "10" + "1" * (b - 2) + "0" * (k - b + 1) + "1" + "0" * (a + b - k - 2) else: y = ( "1" * (b - k + min(a - 1, 1)) + "0" + "1" * (k - 2) + "0" * min(a - 1, 1) + "1" + "0" * (a - 1 - min(a - 1, 1)) + "1" * (1 - min(a - 1, 1)) ) if int(x, 2) < int(y, 2): return False if y[0] == "0": return False return x, y def main(argv=None): a, b, k = map(int, input().split()) answer = solve(a, b, k) if answer: print("Yes") print(answer[0]) print(answer[1]) else: print("No") return 0 STATUS = main() sys.exit(STATUS)
IMPORT ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER STRING RETURN NUMBER RETURN VAR VAR FUNC_DEF NONE ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, c = map(int, input().split()) if c == 0: print("YES") print("1" * b + "0" * a) print("1" * b + "0" * a) elif c > a + b - 2 or b < 2 or a < 1: print("NO") else: print("YES") s1 = "1" s2 = "1" ost = a + b - 2 - c while a > 1 and ost > 0: s1 += "0" s2 += "0" a -= 1 ost -= 1 while b > 2 and ost > 0: s1 += "1" s2 += "1" b -= 1 ost -= 1 b -= 2 s1 += "1" s2 += "0" s1 += "1" * b + "0" * a s2 += "1" * b + "0" * (a - 1) + "1" print(s1) print(s2)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR WHILE VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys input = sys.stdin.readline a, b, k = map(int, input().split()) if a == 0 or b == 1: if k == 0: print("YES") for i in range(b): print(1, end="") for i in range(a): print(0, end="") print() for i in range(b): print(1, end="") for i in range(a): print(0, end="") print() else: print("NO") elif k > b - 1 + a - 1: print("NO") else: print("YES") for i in range(b): print(1, end="") for i in range(a): print(0, end="") print() if k <= a: for i in range(b - 1): print(1, end="") for i in range(k): print(0, end="") print(1, end="") for i in range(a - k): print(0, end="") print() else: for i in range(a + b - k - 1): print(1, end="") print(0, end="") for i in range(k - a): print(1, end="") for i in range(a - 1): print(0, end="") print(1)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) for _ in range(1): zero, one, k = I() if k == 0: x = "1" * one + "0" * zero print("Yes") print(x) print(x) break one -= 1 if (one and zero) and k <= zero + one - 1: x = "1" * (one + 1) + "0" * zero if k <= zero: y = "1" * one + "0" * k + "1" + "0" * (zero - k) else: rm = k - zero y = "1" * (one - rm) + "0" + "1" * rm + "0" * (zero - 1) + "1" print("Yes") print(x) print(y) else: print("No")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) def actual(): a1 = a - 1 b1 = b - 1 ab = a + b if a == 0: if k != 0: return else: x = y = "1" * b return x, y elif k <= a: if b > 1: x = "1" * b + "0" * a y = "1" * b1 + "0" * k + "1" + "0" * (a - k) return x, y elif k == 0: y = x = "1" * b + "0" * a return x, y else: return elif k < ab - 1: if b > k: x = "1" * b + "0" * a y = "1" * (b - k) + "0" + "1" * k + "0" * a1 elif b >= 2: z = "1" * (b - 2) + "0" * a1 x = "11" + z[: k - 1] + "0" + z[k - 1 :] y = "10" + z[: k - 1] + "1" + z[k - 1 :] return x, y ans = actual() if ans: print("Yes") print(ans[0]) print(ans[1]) else: print("No")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN ASSIGN VAR VAR BIN_OP STRING VAR RETURN VAR VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR RETURN VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR RETURN VAR VAR RETURN IF VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().strip().split()) if a == 0 or b == 1: if k == 0: print("Yes") x = "" for i in range(b): x += "1" for i in range(a): x += "0" print(x, x) else: print("No") elif k <= a + b - 2: print("Yes") x = "" for i in range(b): x += "1" for i in range(a): x += "0" y = x y = list(y) mn = min(k, a) last = b - 1 y[last] = "0" y[last + mn] = "1" if k >= mn: dif = k - mn p = dif last = b - 2 while dif > 0: y[last] = "0" y[last + 1] = "1" dif -= 1 last -= 1 y2 = "" for c in y: y2 += c print(x, y2) else: print("No")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().strip().split()) if k == 0: S = "1" * b + "0" * a print("Yes\n" + S + "\n" + S) elif a == 0 or b == 1: print("No") elif k <= a + b - 2: S = "1" * (b - 1) + "0" * (a - 1) print( f"Yes\n{S[:a + b - k - 1]}1{S[a + b - k - 1:]}0\n{S[:a + b - k - 1]}0{S[a + b - k - 1:]}1" ) else: print("No")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys input = sys.stdin.readline def stupid(a, b, k): if a + b == 1: if k == 0: return "YES", "0" if a == 1 else "1", "0" if a == 1 else "1" return "NO", 0, 0 n = a + b for x in range(2**n - 1, 2 ** (n - 1) - 1, -1): xb = bin(x) if xb.count("0") == a + 1 and xb.count("1") == b: for y in range(x, 2**n): yb = bin(y) if yb.count("1") == b and yb.count("0") == a + 1: c = bin(y - x) if c.count("1") == k: return "YES", bin(y)[2:], bin(x)[2:] return "NO", 0, 0 def smart(a, b, k): c = "1" * b + "0" * a if a + b == 1: if k == 0: return "YES", c, c return "NO", 0, 0 if b == 1: if k == 0: return "YES", c, c return "NO", 0, 0 if k <= a: return "YES", c, "1" * (b - 1) + "0" * (a - (a - k)) + "1" + "0" * (a - k) elif a != 0 and b >= 3 and k >= a + 1 and k <= a + b - 2: t = a + b - 2 return ( "YES", c, "1" * (t - k + 1) + "0" + "1" * (b - (t - k + 1) - 1) + "0" * (a - 1) + "1", ) return "NO", 0, 0 def check(ans, a, b, k): if ans[0] == "NO": return True x, y = ans[1], ans[2] if ( x.count("0") == a and y.count("0") == a and x.count("1") == b and y.count("1") == b ): xv = int(x, 2) yv = int(y, 2) z = xv - yv if z >= 0: return bin(z).count("1") == k return False def solve(): a, b, k = map(int, input().split()) ans2 = smart(a, b, k) if ans2[0] == "NO": print("NO") return else: print("YES") print(ans2[1]) print(ans2[2]) solve()
IMPORT ASSIGN VAR VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER IF VAR NUMBER RETURN STRING VAR NUMBER STRING STRING VAR NUMBER STRING STRING RETURN STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING VAR RETURN STRING FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN STRING NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER RETURN STRING VAR VAR RETURN STRING NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER RETURN STRING VAR VAR RETURN STRING NUMBER NUMBER IF VAR VAR RETURN STRING VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN STRING VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP STRING BIN_OP VAR NUMBER STRING RETURN STRING NUMBER NUMBER FUNC_DEF IF VAR NUMBER STRING RETURN NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN FUNC_CALL FUNC_CALL VAR VAR STRING VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ a, b, k = list(map(int, input().split())) if a == 0: if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) else: print("No") elif k > a: if k > a + b: print("No") else: ans1 = b * "1" + a * "0" ans2 = (a + b - k - 1) * "1" + "0" + (k - a) * "1" + (a - 1) * "0" + "1" if ans1[0] == "1" and ans2[0] == "1": print("Yes") print(ans1) print(ans2) else: print("No") elif k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) elif k > 0 and b == 0: print("No") else: ans1 = (b - 1) * "1" + (a - k) * "0" + "1" + "0" * k ans2 = (b - 1) * "1" + (a - k) * "0" + "0" * k + "1" if ans1[0] == "0" or ans2[0] == "0": print("No") else: print("Yes") print(ans1) print(ans2)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING STRING BIN_OP BIN_OP VAR VAR STRING BIN_OP BIN_OP VAR NUMBER STRING STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER STRING BIN_OP BIN_OP VAR VAR STRING STRING BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER STRING BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) if b == 1: if k == 0: print("Yes") print("1" + "0" * a) print("1" + "0" * a) else: print("No") elif k <= a: print("Yes") print("1" * b + "0" * a) print("1" * (b - 1) + "0" * k + "1" + "0" * (a - k)) elif a >= 1 and a + b >= k + 2: print("Yes") print("1" * b + "0" * a) print("1" * (a + b - k - 1) + "0" + "1" * (k - a) + "0" * (a - 1) + "1") else: print("No")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split(" ")) b -= 1 if k == 0: print("Yes") print("1" * (b + 1) + "0" * a) print("1" * (b + 1) + "0" * a) elif a + b <= k: print("No") elif a == 0 or b == 0: print("No") else: print("Yes") if a + b - k <= a: print("1" * (b + 1) + "0" * a) print("10" + "1" * (b - 1) + "0" * (k - b) + "1" + "0" * (a + b - k - 1)) else: print("1" * (k + 1) + "0" + "1" * (b - k) + "0" * (a - 1)) print("10" + "1" * b + "0" * (a - 1))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def Solve(a, b, k): if ( a + b - 2 < k and k != 0 or b == 1 and k > 0 or (b == 0 or a == 0) and k > 0 or b == 0 ): print("No") return print("Yes") x = [0] * (a + b) y = [0] * (a + b) m = a + b - 1 if k != 0: x[0] = y[0] = 1 b -= 1 n = 1 + a + b - k - 1 for i in range(1, n): if a > 1: x[i] = y[i] = 0 a -= 1 else: x[i] = y[i] = 1 b -= 1 x[n] = y[m] = 1 x[m] = y[n] = 0 b -= 1 a -= 1 n += 1 for i in range(n, m): if a > 0: x[i] = y[i] = 0 a -= 1 else: x[i] = y[i] = 1 b -= 1 else: for i in range(a + b): if b > 0: x[i] = y[i] = 1 b -= 1 else: x[i] = y[i] = 0 a -= 1 for bit in x: print(int(bit), end="") print() for bit in y: print(int(bit), end="") a, b, k = map(int, input().split()) Solve(a, b, k)
FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1): z, o, k = lst() if o == 1 and k != 0 or z == 0 and k != 0: print("No") continue if k > z: sel = o + z - k - 1 if sel <= 0: print("No") else: s1 = [1] * o + [0] * z s2 = s1.copy() s2[sel], s2[-1] = s2[-1], s2[sel] print("Yes") for ch in s1: stdout.write(str(ch)) print() for ch in s2: stdout.write(str(ch)) else: s1 = [1] * o + [0] * z s2 = [1] * (o - 1) + [0] * (1 + z) s2[k + o - 1] = 1 print("Yes") for ch in s1: stdout.write(str(ch)) print() for ch in s2: stdout.write(str(ch))
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 ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = input().split() a = int(a) b = int(b) k = int(k) z = a o = b n = a + b s1 = [] s2 = [] for i in range(n): s1.append("0") s2.append("0") s1[0] = "1" s2[0] = "1" b -= 1 if a == 0 and b == 0 and k == 0: print("YES") print("1") print("1") exit(0) if k > n - 2: print("NO") exit(0) if b == 0: if k != 0: print("NO") exit(0) flag = -1 first = True i = n - 1 while b > 0 and i > 0: if first: i -= k s1[i] = "1" s2[n - 1] = "1" flag = i i -= 1 else: s1[i] = "1" s2[i] = "1" i -= 1 b -= 1 first = False i = n - 2 while i > flag and b > 0: s1[i] = "1" s2[i] = "1" b -= 1 i -= 1 ca = 0 cb = 0 for idx in range(n): ca += 1 if s1[idx] == "1" else 0 cb += 1 if s2[idx] == "1" else 0 if o != ca or o != cb: print("NO") exit(0) ca = 0 cb = 0 for idx in range(n): ca += 1 if s1[idx] == "0" else 0 cb += 1 if s2[idx] == "0" else 0 if z != ca or z != cb: print("NO") exit(0) print("YES") print("".join(s1)) print("".join(s2))
ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING NUMBER NUMBER VAR VAR VAR STRING NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING NUMBER NUMBER VAR VAR VAR STRING NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import itertools def main(): a, b, k = map(int, input().split()) maxi = 2 ** (a + b) - 2**a - 2 mini = 2 ** (a + b - 1) + 2 ** (b - 1) - 1 mini_k_ones = 2**k - 1 if b == 1 or a == 0: if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) else: print("No") elif k > a: if k >= a + b - 1: print("No") else: v = k - a x = "1" * (b - v) + (a - 1) * "0" + v * "1" + "0" y = "1" * (b - v - 1) + a * "0" + (v + 1) * "1" print("Yes") print(x) print(y) else: print("Yes") x = b * "1" + a * "0" y = "1" * (b - 1) + k * "0" + "1" + (a - k) * "0" print(x) print(y) main() def brute_force(a, b, k): for p in itertools.combinations(range(a + b - 1), b): for p2 in itertools.combinations(range(a + b - 1), b): n = sum(2**c for c in p) + 2 ** (b - 1) n2 = sum(2**c for c in p) + 2 ** (b - 1) print(str(n).count("1"))
IMPORT FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER STRING BIN_OP VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR STRING BIN_OP BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR STRING BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR STRING STRING BIN_OP BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = list(map(int, input().split())) if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) elif a + b - 1 <= k: print("No") elif a >= k: if b == 1 and k > 0: print("No") elif a == 0 and k == 0: print("Yes") print("1" * b) print("1" * b) else: print("Yes") print("1" * b + "0" * a) print("1" * (b - 1) + "0" * k + "1" + "0" * (a - k)) elif a == 0 and k > 0: print("No") else: c = k - a print("Yes") print("1" * b + "0" * a) print("1" * (b - c - 1) + "0" + "1" * c + "0" * (a - 1) + "1")
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) if b == 1: if k == 0: print("Yes") print("1" + "0" * a) print("1" + "0" * a) else: print("No") elif a == 0: if k == 0: print("Yes") print("1" * b) print("1" * b) else: print("No") elif k <= a: print("Yes") LCP = (a - k) * "0" + (b - 2) * "1" zer = "0" * k print("1" + LCP + "1" + zer) print("1" + LCP + zer + "1") elif a < k < a + b - 1: print("Yes") n = k - a m = b - 1 - n print("1" * b + "0" * a) print("1" * m + "0" + "1" * n + "0" * (a - 1) + "1") else: print("No")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR STRING BIN_OP BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR STRING IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
z, o, k = map(int, input().split()) if k == 0: print("YES") print("1" * o + "0" * z) print("1" * o + "0" * z) elif z == 0 or o == 0: print("NO") elif z >= 1 and o >= 2 and k < z + o - 1: print("YES") z -= 1 o -= 2 zz = min(k - 1, z) oo = min(k - 1 - zz, o) a = "1" * (o - oo) + "11" + "0" * zz + "1" * oo + "0" + "0" * (z - zz) b = "1" * (o - oo) + "10" + "0" * zz + "1" * oo + "1" + "0" * (z - zz) print(a) print(b) else: print("NO")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING VAR BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING VAR BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def answer(v): if (k >= a + b - 1 or b == 1) and k != 0: print("No") return x, y = ["0"] * (a + b), ["0"] * (a + b) stop = -1 if k != 0: x[k], y[0] = "1", "1" v -= 1 stop += 1 for i in range(a + b - 1, stop, -1): if v == 0: break if not (x[i] == "1" or y[i] == "1"): x[i] = "1" y[i] = "1" v -= 1 if v == 0: print("Yes") print("".join(x[::-1])) print("".join(y[::-1])) else: print("No") a, b, k = map(int, input().split()) answer(b)
FUNC_DEF IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR BIN_OP LIST STRING BIN_OP VAR VAR BIN_OP LIST STRING BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) if not k: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) elif a + b <= k + 1 or not a or b == 1: print("No") else: s = "1" * (b - 1) + "0" * (a - 1) i = a + b - k - 1 print("Yes") print(s[:i] + "1" + s[i:] + "0") print(s[:i] + "0" + s[i:] + "1")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys a, b, k = [int(_) for _ in input().split()] if b == 1: if k != 0: print("No") else: print("Yes") print("1" + "0" * a) print("1" + "0" * a) sys.exit() if a == 0: if k != 0: print("No") else: print("Yes") print("1" * b) print("1" * b) sys.exit() if k > a + b - 2: print("No") sys.exit() bin1 = ["1"] + ["0"] * (a + b - 1) bin2 = ["1"] + ["0"] * (a + b - 1) bin1[1] = "1" bin2[1 + k] = "1" shit = b - 2 for i in range(a + b): if shit == 0: break if i != 0 and i != 1 and i != 1 + k: bin1[i] = "1" bin2[i] = "1" shit -= 1 print("Yes") print("".join(bin1)) print("".join(bin2))
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP LIST STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING BIN_OP LIST STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
zeroes, ones, k = map(int, input().split()) s = [0] * (zeroes + ones) t = [0] * (zeroes + ones) n = zeroes + ones exists = False if k == 0: s = [1] * ones + [0] * zeroes t = s.copy() exists = True elif zeroes: s[0] = 1 t[0] = 1 ones -= 1 t[n - 1] = 1 diff = min(k, zeroes) k -= diff i = n - diff - 1 ones -= 1 while k and ones and i > 0: s[i] = 1 t[i] = 1 i -= 1 k -= 1 ones -= 1 s[i] = 1 t[i] = 0 i -= 1 while ones and i > 0: s[i] = 1 t[i] = 1 i -= 1 ones -= 1 if not k and not ones: exists = True print("Yes" if exists else "No") if exists: print("".join(map(str, s))) print("".join(map(str, t)))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) if b == 1 and k != 0: print("NO") elif a == 0 and k != 0: print("NO") elif k == 0: print("YES") print("1" * b + "0" * a) print("1" * b + "0" * a) elif k >= a + b - 1: print("NO") elif k <= a: print("YES") print("1" * (b - 1) + "0" * (a - k) + "1" + "0" * k) print("1" * (b - 1) + "0" * a + "1") else: print("YES") print("1" * b + "0" * a) print("1" * (a + b - k - 1) + "0" + "1" * (k - a) + "0" * (a - 1) + "1")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
a, b, k = map(int, input().split()) a, b = b, a k1 = k if b == 0: if k == 0: print("Yes") print("1" * a) print("1" * a) else: print("No") exit(0) if a == 1: if k == 0: print("Yes") print("1" + "0" * b) print("1" + "0" * b) else: print("No") exit(0) s = "1" + "0" + (a - 2) * "1" + (b - 1) * "0" + "1" f = "00" for i in range(min(k, a - 2)): f += "1" k -= min(k, a - 2) while a + b - len(f) > k: f = f + "0" while len(f) < a + b: f += "1" f = "0b" + f s = "0b" + s f = f[2:] f = "0b" + f k = k1 if ( f[2:].count("1") != k or bin(eval(f + "+" + s))[2:].count("1") != a and bin(eval(f + "+" + s))[2:].count("0") != b ): print("No") else: print("Yes") print(bin(eval(f + "+" + s))[2:]) print(s[2:])
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING STRING BIN_OP BIN_OP VAR NUMBER STRING BIN_OP BIN_OP VAR NUMBER STRING STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR STRING VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR STRING WHILE FUNC_CALL VAR VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR IF FUNC_CALL VAR NUMBER STRING VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR NUMBER STRING VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() inf = 10**16 md = 10**9 + 7 a, b, k = MI() if a == 0: if k == 0: print("Yes") s = "1" * b print(s) print(s) else: print("No") exit() if b == 1: if k == 0: print("Yes") s = "1" + "0" * a print(s) print(s) else: print("No") exit() if k > a + b - 2: print("No") exit() s = [1] * b + [0] * a t = [1] * b + [0] * a cur = min(k, a) t[b - 1] = 0 t[b - 1 + cur] = 1 i = b - 2 for _ in range(k - cur): t[i] = 0 t[i + 1] = 1 i -= 1 print("Yes") print(*s, sep="") print(*t, sep="")
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def mnm(a, b, k): if k == 0: s = "1" * b + "0" * a return [s, s] if a < 1 or b < 2: return ["0", "0"] if k > a + b - 2: return ["0", "0"] if a < k: s1 = "1" + "1" * (a + b - k - 2) + "1" + "1" * (k - a) + "0" * (a - 1) + "0" s2 = "1" + "1" * (a + b - k - 2) + "0" + "1" * (k - a) + "0" * (a - 1) + "1" else: s1 = "1" + "1" * (b - 2) + "0" * (a - k) + "1" + "0" * (k - 1) + "0" s2 = "1" + "1" * (b - 2) + "0" * (a - k) + "0" + "0" * (k - 1) + "1" return [s1, s2] a, b, k = map(int, input().split()) w = mnm(a, b, k) if w[0] == "0": print("NO") else: print("YES") print(w[0]) print(w[1])
FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR RETURN LIST VAR VAR IF VAR NUMBER VAR NUMBER RETURN LIST STRING STRING IF VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN LIST STRING STRING IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP VAR NUMBER STRING RETURN LIST VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (0 ≀ a; 1 ≀ b; 0 ≀ k ≀ a + b ≀ 2 β‹… 10^5) β€” the number of zeroes, ones, and the number of ones in the result. Output If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2. Otherwise print "No". If there are multiple possible answers, print any of them. Examples Input 4 2 3 Output Yes 101000 100001 Input 3 2 1 Output Yes 10100 10010 Input 3 2 5 Output No Note In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2. In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1. In the third example, one may show, that it's impossible to find an answer.
def check(a, b, k): if a == 0 or b == 1: if k == 0: return "1" * b + "0" * a, "1" * b + "0" * a return False if k >= a + b - 1: if k == 0: return "1" * b + "0" * a, "1" * b + "0" * a return False x = "1" * b + "0" * a y = "1" * (b - 1) + "0" * min(a, k) + "1" + max(0, a - k) * "0" if k > a: yL = list(y) yL[b - 1], yL[b - (k - a + 1)] = yL[b - (k - a + 1)], yL[b - 1] y = "".join(yL) return x, y a, b, k = map(int, input().split()) if check(a, b, k): print("Yes") print(*check(a, b, k), sep="\n") else: print("No")
FUNC_DEF IF VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR RETURN NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING FUNC_CALL VAR VAR VAR STRING BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING