description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
n, k = list(map(int, input().split())) s = input() prefixes = [0] for i in range(n): prefixes.append(prefixes[i] + (int(s[i]) + 1) % 2) a = n for i in range(n): if s[i] == "0": left = 0 right = n while right - left > 1: middle = (right + left) // 2 if prefixes[min(n, 1 + i + middle)] - prefixes[max(0, i - middle)] > k: right = middle else: left = middle a = min(a, right) print(a)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
n, k = map(int, input().split()) t = [i for i, v in enumerate(input()) if v == "0"] s, m = n, 0 f = lambda m: max(r - t[m], t[m] - l) for l, r in zip(t, t[k:]): while f(m) > f(m + 1): m += 1 s = min(s, f(m)) print(s)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
n, k = [int(_) for _ in input().split()] a = input() def next_free(x): x += 1 while x < n and a[x] == "1": x += 1 return x l = next_free(-1) r = -1 k += 1 for _ in range(k): r = next_free(r) i = l dis = max(i - l, r - i) next_i = next_free(i) while True: cur_dis = max(i - l, r - i) next_dis = max(next_i - l, r - next_i) if cur_dis <= next_dis: break i = next_i dis = min(dis, next_dis) next_i = next_free(i) while True: r = next_free(r) if r >= n: break l = next_free(l) if i < l: i = l prev_dis = max(i - l, r - i) dis = min(dis, prev_dis) m = next_free(i) while m <= r: cur_dis = max(m - l, r - m) if cur_dis >= prev_dis: break prev_dis = cur_dis i = m dis = min(dis, cur_dis) m = next_free(m) print(dis)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
n, k = map(int, input().split()) t = [i for i, v in enumerate(input()) if v == "0"] s, i = n, 0 a, b = t[:2] for l, r in zip(t, t[k:]): while max(r - a, a - l) > max(r - b, b - l): i += 1 a, b = t[i : i + 2] s = min(s, max(r - a, a - l)) print(s)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
n, k = [int(_) for _ in input().split()] a = input() k += 1 f = [0] * (n + 1) f[1] = int(a[0] == "0") for i in range(2, n + 1): f[i] = f[i - 1] + int(a[i - 1] == "0") def check(dis): for i in range(n): if a[i] == "0": left = max(i - dis, 0) right = min(i + dis, n - 1) total = f[right + 1] - f[left] if total >= k: return True return False l = 1 r = n - 1 while l < r: mid = (l + r) // 2 if check(mid): r = mid else: l = mid + 1 print(l)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
import sys r = sys.stdin.readline n, k = map(int, r().split()) rooms = list(r().strip()) def nextRoom(i): i += 1 while i < n and rooms[i] == "1": i += 1 return i l = nextRoom(-1) r, m = l, l ans = sys.maxsize for i in range(k): r = nextRoom(r) while r < n: while max(m - l, r - m) > max(nextRoom(m) - l, r - nextRoom(m)): m = nextRoom(m) ans = min(ans, max(m - l, r - m)) l, r = nextRoom(l), nextRoom(r) print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR WHILE FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
import sys def can_book(mid, n, k, accum_arr): for i in range(1, n + 1): if accum_arr[i] == accum_arr[i - 1]: continue max_idx = min(i + mid, n) min_idx = max(i - mid - 1, 0) if accum_arr[max_idx] - accum_arr[min_idx] >= k + 1: return True return False def solve(n, k, arr): accum_arr = [0] for i in range(1, n + 1): accum_arr.append(accum_arr[i - 1] + (1 - arr[i - 1])) l = 0 h = len(arr) while l + 1 < h: mid = (l + h) // 2 if can_book(mid, n, k, accum_arr): h = mid else: l = mid return h n, k = input().split() n = int(n) k = int(k) arr = list(map(int, sys.stdin.readline().rstrip())) print(solve(n, k, arr))
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
n, k = list(map(int, input().split())) a = [int(i) for i in input()] i, j, l = 0, -1, 0 z = n b = [] c = -1 for i in range(n): if a[i] == 0: c = i b.append(c) c = -1 for i in range(n - 1, -1, -1): if a[i] == 0: c = i if c != -1 and (b[i] == -1 or c - i < i - b[i]): b[i] = c while i < n and j < n: if l <= k: j += 1 if j < n: l += 1 - a[j] else: break else: z = min( z, max(j - b[(i + j) // 2], b[(i + j) // 2] - i), max(j - b[(i + j) // 2 + 1], b[(i + j) // 2 + 1] - i), ) l -= 1 - a[i] i += 1 print(z)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
[n, k] = [int(x) for x in input().split()] room_free = [bool(1 - int(x)) for x in input()] closest_before = [] closest_after = [] before = -1 for i in range(n): if room_free[i]: before = i closest_before.append(before) after = 11**8 for i in range(n - 1, -1, -1): if room_free[i]: after = i closest_after.append(after) closest_after.reverse() l = -1 r = -1 taken = 0 ans = 10**8 while True: if taken != k + 1: r += 1 if r >= n: break if room_free[r]: taken += 1 else: l += 1 if room_free[l]: mid = int((l + r) / 2) ans = min(ans, closest_after[mid + 1] - l, r - closest_before[mid]) taken -= 1 print(ans)
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
ans = 1000000000 n, k = [int(i) for i in input().split()] s = input() l = len(s) d = [k // 2, (k + 1) // 2] nearl = [0] * n nearr = [0] * n last = 1000000000 for i in range(n): if s[i] == "0": last = i nearl[i] = last for i in range(n - 1, -1, -1): if s[i] == "0": last = i nearr[i] = last for i in d: itl = 0 nf = 0 itr = 0 while s[itl] == "1": itl += 1 cnt = 0 nf = itl while cnt < i: cnt += 1 nf += 1 while s[nf] == "1": nf += 1 cnt = 0 itr = nf while cnt < k - i: cnt += 1 itr += 1 while s[itr] == "1": itr += 1 while True: pos = (itr + itl) // 2 pos1 = nearl[pos] ans = min(ans, max(pos1 - itl, itr - pos1)) pos1 = nearr[pos] ans = min(ans, max(pos1 - itl, itr - pos1)) itr += 1 while itr < l and s[itr] == "1": itr += 1 if itr == l: break itl += 1 while s[itl] == "1": itl += 1 print(ans)
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
n, k = map(int, input().split()) rooms = input() count = [0] * (n + 1) for i in range(n): count[i] = count[i - 1] if rooms[i] == "0": count[i] += 1 ans = float("inf") for i in range(n): l = 0 r = n while l + 1 < r: m = (r + l) // 2 if rooms[i] == "0" and count[min(i + m, n - 1)] - count[max(-1, i - m - 1)] > k: r = m else: l = m ans = min(r, ans) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of n rooms located in a row, some of which are occupied. Farmer John wants to book a set of k + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms i and j is defined as |j - i|. Help Farmer John protect his cows by calculating this minimum possible distance. -----Input----- The first line of the input contains two integers n and k (1 ≤ k < n ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length n describing the rooms. The i-th character of the string will be '0' if the i-th room is free, and '1' if the i-th room is occupied. It is guaranteed that at least k + 1 characters of this string are '0', so there exists at least one possible choice of k + 1 rooms for Farmer John and his cows to stay in. -----Output----- Print the minimum possible distance between Farmer John's room and his farthest cow. -----Examples----- Input 7 2 0100100 Output 2 Input 5 1 01010 Output 2 Input 3 2 000 Output 1 -----Note----- In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
import sys input = sys.stdin.readline def judge(i, x): return acc[min(n, i + x + 1)] - acc[max(0, i - x)] >= k + 1 def binary_search(i): l, r = 0, n while l <= r: mid = (l + r) // 2 if judge(i, mid): r = mid - 1 else: l = mid + 1 return l n, k = map(int, input().split()) S = input()[:-1] acc = [0] for Si in S: acc.append(acc[-1] + (1 if Si == "0" else 0)) ans = n for i in range(n): if S[i] == "0": ans = min(ans, binary_search(i)) print(ans)
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
from sys import stdin input = stdin.readline for _ in range(int(input())): a, b, c = map(int, input().strip().split(" ")) if a == b == c: print("YES") continue f = 0 for i in range(31): if a == b and b == c: f = 1 break bit = 1 << i cnt = (bit & a != 0) + (bit & b != 0) + (bit & c != 0) if cnt == 0 or cnt == 3: break elif cnt == 2: if bit & a == 0: a += bit elif bit & b == 0: b += bit else: c += bit elif bit & a: a += bit elif bit & b: b += bit else: c += bit if f == 1 and (a == b and b == c): print("YES") else: print("NO")
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for h in range(int(input())): x, y, z = map(int, input().split()) i, k = 0, 1 while i < 31: ze = [] o = [] if x & k == k: o.append(x) else: ze.append(x) if y & k == k: o.append(y) else: ze.append(y) if z & k == k: o.append(z) else: ze.append(z) if len(ze) == 3 or len(o) == 3: break elif len(ze) == 1: if x == ze[0]: x += k elif y == ze[0]: y += k else: z += k elif x == o[0]: x += k elif y == o[0]: y += k else: z += k k = k << 1 i += 1 if x == y and y == z: print("YES") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def solve(a, b, c): flag = True for i in range(0, 31): if a == b and b == c: break x = 1 << i cnt = (x & a != 0) + (x & b != 0) + (x & c != 0) if cnt == 0 or cnt == 3: flag = False break elif cnt == 1: if x & a: a += x elif x & b: b += x else: c += x elif x & a == 0: a += x elif x & b == 0: b += x else: c += x if flag and a == b and b == c: print("YES") else: print("NO") t = int(input()) for _ in range(t): a, b, c = list(map(int, input().split())) solve(a, b, c)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
n = int(input()) for _ in range(n): A, B, C = map(int, input().split()) for i in range(33): if A == B == C: print("YES") break elif A == B < C or A == C < B or B == C < A: print("NO") break bit = 2**i A_bit = A & bit B_bit = B & bit C_bit = C & bit if A_bit == B_bit == C_bit: print("NO") break elif A_bit == B_bit: C += bit elif B_bit == C_bit: A += bit elif A_bit == C_bit: B += bit
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for _ in range(int(input())): a, b, c = list(map(int, input().split())) flag = False for i in range(40): if a == b and c == b: flag = True else: p, q, r = a >> i & 1, b >> i & 1, c >> i & 1 if p + q + r == 2: if not p: a += 1 << i if not q: b += 1 << i if not r: c += 1 << i elif p + q + r == 1: if p == 1: a += 1 << i elif q == 1: b += 1 << i elif r == 1: c += 1 << i else: break if a == b and c == b: flag = True else: flag = False if flag: print("YES") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
import sys input = sys.stdin.readline M = int(1000000000.0) + 7 def solve(): l = list(map(int, input().split())) while l[1] != 0: ev = 0 for num in l: ev += num % 2 == 0 if ev == 0 or ev == 3: break if ev == 2: for i in range(3): if l[i] % 2 == 1: l[i] += 1 for i in range(3): l[i] //= 2 l.sort() if len(set(l)) == 1: return "YES" return "NO" for _ in range(int(input())): print(solve())
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for t in range(int(input())): n = list(map(int, input().strip().split())) p = 1 is_possible = True while is_possible and not n[0] == n[1] == n[2]: cnt = 0 if n[0] & p: cnt += 1 i = 0 else: j = 0 if n[1] & p: cnt += 1 i = 1 else: j = 1 if n[2] & p: cnt += 1 i = 2 else: j = 2 if cnt == 0 or cnt == 3: is_possible = False elif cnt == 2: n[j] += p else: t = p << 1 if n[i] < t and n[(i + 1) % 3] < t and n[(i + 2) % 3] < t: is_possible = False n[i] += p p <<= 1 print("YES" if is_possible else "NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for _ in range(int(input())): a, b, c = map(int, input().split()) mask = 1 for i in range(64): if a & mask != b & mask == c & mask: a += mask elif b & mask != a & mask == c & mask: b += mask elif c & mask != b & mask == a & mask: c += mask else: break mask <<= 1 if a == b == c: print("YES") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def fun(ar, i, nar, lar): newar = "" if nar == 1: if i < lar: c = 1 for x in range(i, lar): if ar[x] == 0: newar += "1" c = 0 for j in range(x + 1, lar): newar += str(ar[j]) break else: newar += "0" if c == 1: newar += "1" else: newar = "1" else: for x in range(i, lar): newar += str(ar[x]) return newar def update(a, b, c, i, na, nb, nc, la, lb, lc): newa = fun(a, i, na, la) newb = fun(b, i, nb, lb) newc = fun(c, i, nc, lc) if newa == newb and newb == newc: return True return False for t in range(int(input())): a, b, c = list(bin(int(i))[2:][::-1] for i in input().split()) la = len(a) lb = len(b) lc = len(c) a = [int(i) for i in a] b = [int(i) for i in b] c = [int(i) for i in c] pa = 0 pb = 0 pc = 0 i = 0 while True: if i > max(la, lb, lc) + 1: print("NO") break if i > la - 1: ca = 0 else: ca = a[i] if i > lb - 1: cb = 0 else: cb = b[i] if i > lc - 1: cc = 0 else: cc = c[i] na = 0 nb = 0 nc = 0 if pa == 1: if ca == 1: na = 1 ca = 0 else: ca = 1 na = 0 if pb == 1: if cb == 1: nb = 1 cb = 0 else: cb = 1 nb = 0 if pc == 1: if cc == 1: nc = 1 cc = 0 else: cc = 1 nc = 0 if ca == cb and cb != cc: if cc == 1: nc = 1 elif cb == cc and cb != ca: if ca == 1: na = 1 elif ca == cc and cb != ca: if cb == 1: nb = 1 else: if update(a, b, c, i + 1, na, nb, nc, la, lb, lc): print("YES") else: print("NO") break pa = na pb = nb pc = nc i += 1
FUNC_DEF ASSIGN VAR STRING IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR STRING IF VAR NUMBER VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER 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 FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
t = int(input()) for i in range(t): a, b, c = [int(x) for x in input().split()] x = a y = b z = c i = 0 while x and z or y and x or y and z: if a == b and b == c: break if a & 1 << i != 0 and b & 1 << i != 0 and c & 1 << i == 0: c += 1 << i z += 1 elif a & 1 << i == 0 and b & 1 << i != 0 and c & 1 << i != 0: a += 1 << i x += 1 elif a & 1 << i != 0 and b & 1 << i == 0 and c & 1 << i != 0: b += 1 << i y += 1 elif a & 1 << i != 0 and b & 1 << i == 0 and c & 1 << i == 0: a += 1 << i x += 1 elif a & 1 << i == 0 and b & 1 << i != 0 and c & 1 << i == 0: b += 1 << i y += 1 elif a & 1 << i == 0 and b & 1 << i == 0 and c & 1 << i != 0: c += 1 << i z += 1 else: break if a == b and b == c: break x >>= 1 y >>= 1 z >>= 1 i += 1 if a == b and b == c: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
t = int(input()) def solve(): a = list(map(int, input().split())) k = 1 if a[0] == a[1] and a[1] == a[2]: print("YES") return for _ in range(31): ones = 0 if a[0] == a[1] and a[1] == a[2]: print("YES") return for i in range(3): ones += a[i] & k != 0 if ones == 1: for i in range(3): if a[i] & k != 0: a[i] += k elif ones == 2: for i in range(3): if a[i] & k == 0: a[i] += k else: print("NO") return if a[0] == a[1] and a[1] == a[2]: print("YES") return k <<= 1 print("NO") for _ in range(t): solve()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for _ in range(int(input())): l = list(map(int, input().split())) i = 0 while (l[0] >> i, l[1] >> i, l[2] >> i).count(0) < 2: if len(set(l)) == 1: print("YES") break d = l[0] >> i & 1, l[1] >> i & 1, l[2] >> i & 1 if d.count(1) == 1: l[d.index(1)] += 1 << i elif d.count(0) == 1: l[d.index(0)] += 1 << i else: print("NO") break if len(set(l)) == 1: print("YES") break i += 1 else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for _ in range(int(input())): a, b, c = map(int, input().split()) ans = 0 for i in range(0, 129): pw2 = 2**i - 1 num = pw2 + a + b + c if num % 3 == 0: num = num // 3 if num >= max({a, b, c}): aa, bb, cc = num - a, num - b, num - c if aa & bb == 0 and bb & cc == 0 and aa & cc == 0: ans = 1 break print(["YES", "NO"][ans ^ 1])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING BIN_OP VAR NUMBER
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for _ in range(int(input())): a, b, c = map(int, input().split()) c1 = 0 f = 0 while c1 < 32: if a == b and b == c: print("YES") f = 1 break val = 1 << c1 f1 = a & val f2 = b & val f3 = c & val if f1 == f2 and f2 == f3: print("NO") f = 1 break elif f1 == f2: c = c + val elif f1 == f3: b = b + val else: a = a + val c1 += 1 if f == 0: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
T = int(input()) for case in range(T): a, b, c = map(int, input().split(" ")) while True: a, b, c = sorted([a, b, c]) if a % 2 == b % 2 == c % 2 or a + b + c == 1: break rem = (a + b + c) % 2 if a % 2 == rem: a += 1 elif b % 2 == rem: b += 1 else: c += 1 a, b, c = 0, b - a, c - a b, c = b // 2, c // 2 print("YES" if a == b == c else "NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING WHILE NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR LIST VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
t = int(input()) while t: a, b, c = map(int, input().split()) poss = False for i in range(40): if a == b and b == c: poss = True break ct = (a >> i & 1) + (b >> i & 1) + (c >> i & 1) if ct == 2: if a >> i & 1 == 0: a += 1 << i if b >> i & 1 == 0: b += 1 << i if c >> i & 1 == 0: c += 1 << i elif ct == 1: if a >> i & 1: a += 1 << i if b >> i & 1: b += 1 << i if c >> i & 1: c += 1 << i else: break if poss: print("YES") else: print("NO") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for _ in range(int(input())): last = None li = list(map(int, input().split())) while True: if li == last: print("NO") break last = li[:] if li[0] == li[1] == li[2]: print("YES") break c0 = 0 c1 = 0 for i in li: if i % 2 == 0: c0 += 1 else: c1 += 1 if c1 == 0 or c0 == 0: print("NO") break for i in range(len(li)): if c0 == 1: li[i] = li[i] >> 1 elif li[i] % 2 == 1: li[i] = li[i] >> 1 li[i] = li[i] + 1 else: li[i] = li[i] >> 1
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
n = int(input()) def comp(x, y, z): l = [x, y, z] l.sort() x = l[2] y = l[1] z = l[0] if x == y == z: return "YES" if y == z or x % 2 == y % 2 == z % 2: return "NO" if x % 2 + y % 2 + z % 2 == 1: if x % 2 == 1: x = x + 1 if y % 2 == 1: y = y + 1 if z % 2 == 1: z = z + 1 return comp(x // 2, y // 2, z // 2) for i in range(n): x, y, z = map(int, input().split()) print(comp(x, y, z))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR RETURN STRING IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN STRING IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def solve(_in): if _in[0] == _in[1] and _in[0] == _in[2]: return "YES" _in.sort() if _in[0] == 0: if _in[1] == 0: return "NO" Sum = sum(_in) remainders = [(x % 2) for x in _in] if Sum % 3 in [0, 2] and sum(remainders) in [1, 2]: if sum(remainders) == 1: i = remainders.index(1) else: i = remainders.index(0) _in[i] += 1 _in[1] = (_in[1] - _in[0]) // 2 _in[2] = (_in[2] - _in[0]) // 2 _in[0] = 0 return solve(_in) else: return "NO" for _ in range(int(input())): _in = list(map(int, input().split())) print(solve(_in))
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER LIST NUMBER NUMBER FUNC_CALL VAR VAR LIST NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def sol(): a, b, c = map(int, input().split()) for i in range(31): if a == b and b == c: return "YES" bit = 1 << i cnt = (a & bit != 0) + (b & bit != 0) + (c & bit != 0) if cnt == 0 or cnt == 3: return "NO" elif cnt == 2: if a & bit == 0: a += bit elif b & bit == 0: b += bit else: c += bit elif a & bit: a += bit elif b & bit: b += bit else: c += bit return "NO" for i in range(int(input())): print(sol())
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN STRING ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def win(a, b, c): if a == b == c: return True elif (a, b, c) in [(0, 0, 1), (0, 1, 0), (1, 0, 0)]: return False elif a % 2 == b % 2 == c % 2: return False elif a % 2 == b % 2: return win(a // 2, b // 2, (c + 1) // 2) elif a % 2 == c % 2: return win(a // 2, (b + 1) // 2, c // 2) elif b % 2 == c % 2: return win((a + 1) // 2, b // 2, c // 2) for _ in range(int(input())): A, B, C = map(int, input().split()) print({(0): "NO", (1): "YES"}[win(A, B, C)])
FUNC_DEF IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR DICT NUMBER NUMBER STRING STRING FUNC_CALL VAR VAR VAR VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for _ in range(int(input())): a, b, c = map(int, input().split()) x = min(min(a, b), c) a -= x b -= x c -= x temp = True while temp: if a == 0 and b == 0 and c == 0: break if ( a == 0 and b == 0 or b == 0 and c == 0 or c == 0 and a == 0 or a % 2 == b % 2 and a % 2 == c % 2 ): temp = False continue if a % 2 == b % 2: c += 1 elif a % 2 == c % 2: b += 1 else: a += 1 a = a >> 1 b = b >> 1 c = c >> 1 print("YES") if temp else print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
for _ in range(int(input())): a, b, c = map(int, input().split()) ans = True ar = True while True: if a == b and b == c: break cnt = 0 zer = 0 if a == 0: cnt += 1 zer += 1 if b == 0: cnt += 1 zer += 1 if c == 0: cnt += 1 zer += 1 if cnt == 3: break elif zer == 2: ans = False break if a % 2 == 0: aval = 0 else: aval = 1 if b % 2 == 0: bval = 0 else: bval = 1 if c % 2 == 0: cval = 0 else: cval = 1 if aval == bval and bval == cval: ans = False break elif cval == 0 and bval == 0: a += 1 elif bval == 0 and aval == 0: c += 1 elif cval == 0 and aval == 0: b += 1 a = a >> 1 b = b >> 1 c = c >> 1 if ans: print("YES") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def mi(): return map(int, input().split()) def li(): return list(mi()) def si(): return str(input()) def ni(): return int(input()) for T in range(int(input())): a, b, c = mi() for i in range(32): x, y, z = a & 1 << i, b & 1 << i, c & 1 << i if x != y and x != z: a += 2**i elif y != x and y != z: b += 2**i elif z != x and z != y: c += 2**i else: break if a == b == c: print("YES") else: print("NO")
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
t = int(input()) def getbits(n): ans = [] while n > 0: ans.append(n % 2) n = n // 2 while t > 0: t = t - 1 a, b, c = list(map(int, input().split())) ans = "YES" while a > 0 or b > 0 or c > 0: if a == b == c: break if a < 2 and b < 2 and c < 2: if a + b + c == 1: ans = "NO" break else: break if a % 2 + b % 2 + c % 2 == 2: a = a // 2 b = b // 2 c = c // 2 elif a % 2 + b % 2 + c % 2 == 1: a = (a + a % 2) // 2 b = (b + b % 2) // 2 c = (c + c % 2) // 2 else: ans = "NO" break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING WHILE VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR STRING IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def ff(arr): ans = 0 for i in range(len(arr)): ans += arr[i] * 2**i return ans def convert(n): arr = [] while n > 0: r = n % 2 arr.append(r) n >>= 1 return arr def f(arr, n): while len(arr) < n: arr.append(0) def ad(ar, br, cr, x): c = 1 while x != len(ar) and c != 0: tm = ar[x] + c if tm == 1: ar[x] = 1 c = 0 else: ar[x] = 0 c = 1 x += 1 if c != 0: ar.append(c) br.append(0) cr.append(0) t = int(input()) for _ in range(t): a, b, c = map(int, input().split()) if a <= 0 or b <= 0 or c <= 0: print("NO") continue ar = convert(a) br = convert(b) cr = convert(c) s = max(len(ar), len(br), len(cr)) f(ar, s) f(br, s) f(cr, s) ch = False ans = True i = 0 while i < len(ar) - 1: tm = ar[i] + br[i] + cr[i] if ch and (tm == 1 or tm == 2): ans = False break if tm == 1: if ar[i] == 1: ad(ar, br, cr, i) elif br[i] == 1: ad(br, ar, cr, i) elif cr[i] == 1: ad(cr, ar, br, i) elif tm == 2: if ar[i] == 0: ad(ar, br, cr, i) elif br[i] == 0: ad(br, ar, cr, i) elif cr[i] == 0: ad(cr, ar, br, i) else: ch = True i += 1 x = len(ar) tm = ar[x - 1] + br[x - 1] + cr[x - 1] if tm == 1: ans = False elif tm == 2 and ch == False: if ar[x - 1] == 0: ar[x - 1] = 1 if br[x - 1] == 0: br[x - 1] = 1 if cr[x - 1] == 0: cr[x - 1] = 1 if ans and ar[x - 1] == br[x - 1] == cr[x - 1]: print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def bits(a, bit): if a & bit > 0: return 1 else: return 0 for _ in range(int(input())): a, b, c = map(int, input().split()) flag = True for i in range(31): if a == b == c: break bit = 1 << i cnt = bits(a, bit) + bits(b, bit) + bits(c, bit) if cnt == 0 or cnt == 3: flag = False break elif cnt == 1: if a & bit > 0: a += bit elif b & bit > 0: b += bit else: c += bit elif a & bit == 0: a += bit elif b & bit == 0: b += bit else: c += bit if a & bit != b & bit and a & bit != c & bit: flag = False break if flag and a == b and b == c: print("YES") else: print("NO")
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given 3 numbers A, B and C. You want to make all these 3 numbers equal. To do this, you can perform any finite number of operations: In the i^{th} operation, you must add 2^{(i-1)} to any one of these 3 numbers. Find whether you can make these 3 numbers equal in finite number of moves. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - Each test case contains of a single line of input, three integers A, B, and C. ------ Output Format ------ For each test case, output YES if you can make these 3 numbers equal, NO otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). ------ Constraints ------ $1 ≤ T ≤ 5000$ $1 ≤ A, B, C ≤ 10^{9}$ ----- Sample Input 1 ------ 4 4 4 3 1 6 7 3 4 3 2 3 4 ----- Sample Output 1 ------ YES YES NO YES ----- explanation 1 ------ Test Case $1$: It is optimal to do only $1$ operation which is adding $2^{0}$ to $C=3$. After this, all the numbers becomes equal to $4$. Test Case $2$: - In the first operation, add $2^{0}$ to $B=6$. Thus, numbers become $A=1, B=7,$ and $C=7$. - In the second operation, add $2^{1}$ to $A=1$. Thus, numbers become $A=3, B=7,$ and $C=7$. - In the third operation, add $2^{2}$ to $A=3$. Thus, numbers become $A=7, B=7,$ and $C=7$. Thus, all the numbers become equal. Test case $3$: It can be proven that the numbers cannot be made equal using any number of moves. Test case $4$: - In the first operation, add $2^{0}$ to $B=3$. Thus, numbers become $A=2, B=4,$ and $C=4$. - In the second operation, add $2^{1}$ to $A=2$. Thus, numbers become $A=4, B=4,$ and $C=4$. Thus, all the numbers become equal.
def set_bit(x, i): if 1 << i & x: return 1 return 0 for _ in range(int(input())): nums = list(map(int, input().split())) flag = 1 for i in range(31): if len(set(nums)) == 1: print("YES") flag = 0 break bit_sum = sum(set_bit(n, i) for n in nums) if bit_sum == 3 or bit_sum == 0: flag = 1 break elif bit_sum == 1: for x in range(3): if set_bit(nums[x], i): nums[x] += 1 << i else: for x in range(3): if not set_bit(nums[x], i): nums[x] += 1 << i if flag: print("NO")
FUNC_DEF IF BIN_OP BIN_OP NUMBER 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING
Let us call two integers $x$ and $y$ adjacent if $\frac{lcm(x, y)}{gcd(x, y)}$ is a perfect square. For example, $3$ and $12$ are adjacent, but $6$ and $9$ are not. Here $gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$, and $lcm(x, y)$ denotes the least common multiple (LCM) of integers $x$ and $y$. You are given an array $a$ of length $n$. Each second the following happens: each element $a_i$ of the array is replaced by the product of all elements of the array (including itself), that are adjacent to the current value. Let $d_i$ be the number of adjacent elements to $a_i$ (including $a_i$ itself). The beauty of the array is defined as $\max_{1 \le i \le n} d_i$. You are given $q$ queries: each query is described by an integer $w$, and you have to output the beauty of the array after $w$ seconds. -----Input----- The first input line contains a single integer $t$ ($1 \le t \le 10^5)$ — the number of test cases. The first line of each test case contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the length of the array. The following line contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10^6$) — array elements. The next line contain a single integer $q$ ($1 \le q \le 3 \cdot 10^5$) — the number of queries. The following $q$ lines contain a single integer $w$ each ($0 \le w \le 10^{18}$) — the queries themselves. It is guaranteed that the sum of values $n$ over all test cases does not exceed $3 \cdot 10^5$, and the sum of values $q$ over all test cases does not exceed $3 \cdot 10^5$ -----Output----- For each query output a single integer — the beauty of the array at the corresponding moment. -----Examples----- Input 2 4 6 8 4 2 1 0 6 12 3 20 5 80 1 1 1 Output 2 3 -----Note----- In the first test case, the initial array contains elements $[6, 8, 4, 2]$. Element $a_4=2$ in this array is adjacent to $a_4=2$ (since $\frac{lcm(2, 2)}{gcd(2, 2)}=\frac{2}{2}=1=1^2$) and $a_2=8$ (since $\frac{lcm(8,2)}{gcd(8, 2)}=\frac{8}{2}=4=2^2$). Hence, $d_4=2$, and this is the maximal possible value $d_i$ in this array. In the second test case, the initial array contains elements $[12, 3, 20, 5, 80, 1]$. The elements adjacent to $12$ are $\{12, 3\}$, the elements adjacent to $3$ are $\{12, 3\}$, the elements adjacent to $20$ are $\{20, 5, 80\}$, the elements adjacent to $5$ are $\{20, 5, 80\}$, the elements adjacent to $80$ are $\{20, 5, 80\}$, the elements adjacent to $1$ are $\{1\}$. After one second, the array is transformed into $[36, 36, 8000, 8000, 8000, 1]$.
from sys import stdin T = int(stdin.readline()) dct = {i: i for i in range(1000001)} for i in range(2, 1001): for j in range(1, 10**6 // i**2 + 1): dct[i**2 * j] = j for _ in range(T): n = int(stdin.readline()) arr = list(map(int, stdin.readline().split())) q = int(stdin.readline()) seen = {} for i in range(n): num = dct[arr[i]] if num not in seen: seen[num] = 1 else: seen[num] += 1 max1 = 1 max2 = 0 for val in seen.values(): max1 = max(max1, val) if val % 2 == 0: max2 += val if 1 in seen: if seen[1] % 2 == 0: pass else: max2 += seen[1] for k in range(q): if int(stdin.readline()) >= 1: print(max(max1, max2)) else: print(max1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR 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 FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR IF NUMBER VAR IF BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Let us call two integers $x$ and $y$ adjacent if $\frac{lcm(x, y)}{gcd(x, y)}$ is a perfect square. For example, $3$ and $12$ are adjacent, but $6$ and $9$ are not. Here $gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$, and $lcm(x, y)$ denotes the least common multiple (LCM) of integers $x$ and $y$. You are given an array $a$ of length $n$. Each second the following happens: each element $a_i$ of the array is replaced by the product of all elements of the array (including itself), that are adjacent to the current value. Let $d_i$ be the number of adjacent elements to $a_i$ (including $a_i$ itself). The beauty of the array is defined as $\max_{1 \le i \le n} d_i$. You are given $q$ queries: each query is described by an integer $w$, and you have to output the beauty of the array after $w$ seconds. -----Input----- The first input line contains a single integer $t$ ($1 \le t \le 10^5)$ — the number of test cases. The first line of each test case contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the length of the array. The following line contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10^6$) — array elements. The next line contain a single integer $q$ ($1 \le q \le 3 \cdot 10^5$) — the number of queries. The following $q$ lines contain a single integer $w$ each ($0 \le w \le 10^{18}$) — the queries themselves. It is guaranteed that the sum of values $n$ over all test cases does not exceed $3 \cdot 10^5$, and the sum of values $q$ over all test cases does not exceed $3 \cdot 10^5$ -----Output----- For each query output a single integer — the beauty of the array at the corresponding moment. -----Examples----- Input 2 4 6 8 4 2 1 0 6 12 3 20 5 80 1 1 1 Output 2 3 -----Note----- In the first test case, the initial array contains elements $[6, 8, 4, 2]$. Element $a_4=2$ in this array is adjacent to $a_4=2$ (since $\frac{lcm(2, 2)}{gcd(2, 2)}=\frac{2}{2}=1=1^2$) and $a_2=8$ (since $\frac{lcm(8,2)}{gcd(8, 2)}=\frac{8}{2}=4=2^2$). Hence, $d_4=2$, and this is the maximal possible value $d_i$ in this array. In the second test case, the initial array contains elements $[12, 3, 20, 5, 80, 1]$. The elements adjacent to $12$ are $\{12, 3\}$, the elements adjacent to $3$ are $\{12, 3\}$, the elements adjacent to $20$ are $\{20, 5, 80\}$, the elements adjacent to $5$ are $\{20, 5, 80\}$, the elements adjacent to $80$ are $\{20, 5, 80\}$, the elements adjacent to $1$ are $\{1\}$. After one second, the array is transformed into $[36, 36, 8000, 8000, 8000, 1]$.
from sys import stdin dct = {i: i for i in range(1000001)} for i in range(2, 1001): for j in range(1, 10**6 // i**2 + 1): dct[i**2 * j] = j t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) elements = map(int, stdin.readline().split()) q = int(stdin.readline()) dct2 = {} for i in elements: if dct[i] not in dct2: dct2[dct[i]] = 1 else: dct2[dct[i]] += 1 chan = 0 maxx = 0 for so, gia in dct2.items(): if so == 1: maxx = max(gia, maxx) chan += gia else: maxx = max(gia, maxx) if gia % 2 == 0: chan += gia maxx2 = max(chan, maxx) for times in range(q): quer = stdin.readline() if quer == "0\n": print(maxx) else: print(maxx2)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Let us call two integers $x$ and $y$ adjacent if $\frac{lcm(x, y)}{gcd(x, y)}$ is a perfect square. For example, $3$ and $12$ are adjacent, but $6$ and $9$ are not. Here $gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$, and $lcm(x, y)$ denotes the least common multiple (LCM) of integers $x$ and $y$. You are given an array $a$ of length $n$. Each second the following happens: each element $a_i$ of the array is replaced by the product of all elements of the array (including itself), that are adjacent to the current value. Let $d_i$ be the number of adjacent elements to $a_i$ (including $a_i$ itself). The beauty of the array is defined as $\max_{1 \le i \le n} d_i$. You are given $q$ queries: each query is described by an integer $w$, and you have to output the beauty of the array after $w$ seconds. -----Input----- The first input line contains a single integer $t$ ($1 \le t \le 10^5)$ — the number of test cases. The first line of each test case contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the length of the array. The following line contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10^6$) — array elements. The next line contain a single integer $q$ ($1 \le q \le 3 \cdot 10^5$) — the number of queries. The following $q$ lines contain a single integer $w$ each ($0 \le w \le 10^{18}$) — the queries themselves. It is guaranteed that the sum of values $n$ over all test cases does not exceed $3 \cdot 10^5$, and the sum of values $q$ over all test cases does not exceed $3 \cdot 10^5$ -----Output----- For each query output a single integer — the beauty of the array at the corresponding moment. -----Examples----- Input 2 4 6 8 4 2 1 0 6 12 3 20 5 80 1 1 1 Output 2 3 -----Note----- In the first test case, the initial array contains elements $[6, 8, 4, 2]$. Element $a_4=2$ in this array is adjacent to $a_4=2$ (since $\frac{lcm(2, 2)}{gcd(2, 2)}=\frac{2}{2}=1=1^2$) and $a_2=8$ (since $\frac{lcm(8,2)}{gcd(8, 2)}=\frac{8}{2}=4=2^2$). Hence, $d_4=2$, and this is the maximal possible value $d_i$ in this array. In the second test case, the initial array contains elements $[12, 3, 20, 5, 80, 1]$. The elements adjacent to $12$ are $\{12, 3\}$, the elements adjacent to $3$ are $\{12, 3\}$, the elements adjacent to $20$ are $\{20, 5, 80\}$, the elements adjacent to $5$ are $\{20, 5, 80\}$, the elements adjacent to $80$ are $\{20, 5, 80\}$, the elements adjacent to $1$ are $\{1\}$. After one second, the array is transformed into $[36, 36, 8000, 8000, 8000, 1]$.
from sys import stdin input = stdin.readline def calculate(): a = [i for i in range(10**6 + 1)] for square_root in range(1000, 1, -1): square = square_root**2 x = square while x <= 10**6: if a[x] % square == 0: a[x] //= square x += square return a def main(input): precalculated = calculate() t = int(input()) for _ in range(t): n = int(input()) d = {} for ai in map(int, input().split()): sai = precalculated[ai] d[sai] = d.get(sai, 0) + 1 c_1 = d.get(1, 0) c_even = 0 mx = 0 for k, c in d.items(): if c % 2 == 0 and k != 1: c_even += c if c > mx: mx = c w0 = mx w1 = max(mx, c_1 + c_even) q = int(input()) for _ in range(q): w = int(input()) print(w0 if w == 0 else w1) main(input)
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Let us call two integers $x$ and $y$ adjacent if $\frac{lcm(x, y)}{gcd(x, y)}$ is a perfect square. For example, $3$ and $12$ are adjacent, but $6$ and $9$ are not. Here $gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$, and $lcm(x, y)$ denotes the least common multiple (LCM) of integers $x$ and $y$. You are given an array $a$ of length $n$. Each second the following happens: each element $a_i$ of the array is replaced by the product of all elements of the array (including itself), that are adjacent to the current value. Let $d_i$ be the number of adjacent elements to $a_i$ (including $a_i$ itself). The beauty of the array is defined as $\max_{1 \le i \le n} d_i$. You are given $q$ queries: each query is described by an integer $w$, and you have to output the beauty of the array after $w$ seconds. -----Input----- The first input line contains a single integer $t$ ($1 \le t \le 10^5)$ — the number of test cases. The first line of each test case contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the length of the array. The following line contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10^6$) — array elements. The next line contain a single integer $q$ ($1 \le q \le 3 \cdot 10^5$) — the number of queries. The following $q$ lines contain a single integer $w$ each ($0 \le w \le 10^{18}$) — the queries themselves. It is guaranteed that the sum of values $n$ over all test cases does not exceed $3 \cdot 10^5$, and the sum of values $q$ over all test cases does not exceed $3 \cdot 10^5$ -----Output----- For each query output a single integer — the beauty of the array at the corresponding moment. -----Examples----- Input 2 4 6 8 4 2 1 0 6 12 3 20 5 80 1 1 1 Output 2 3 -----Note----- In the first test case, the initial array contains elements $[6, 8, 4, 2]$. Element $a_4=2$ in this array is adjacent to $a_4=2$ (since $\frac{lcm(2, 2)}{gcd(2, 2)}=\frac{2}{2}=1=1^2$) and $a_2=8$ (since $\frac{lcm(8,2)}{gcd(8, 2)}=\frac{8}{2}=4=2^2$). Hence, $d_4=2$, and this is the maximal possible value $d_i$ in this array. In the second test case, the initial array contains elements $[12, 3, 20, 5, 80, 1]$. The elements adjacent to $12$ are $\{12, 3\}$, the elements adjacent to $3$ are $\{12, 3\}$, the elements adjacent to $20$ are $\{20, 5, 80\}$, the elements adjacent to $5$ are $\{20, 5, 80\}$, the elements adjacent to $80$ are $\{20, 5, 80\}$, the elements adjacent to $1$ are $\{1\}$. After one second, the array is transformed into $[36, 36, 8000, 8000, 8000, 1]$.
import sys input = sys.stdin.readline for f in range(int(input())): n = int(input()) a = list(map(int, input().split())) q = int(input()) v = {} for x in a: f = [] i = 3 c = 0 while x % 2 == 0: x //= 2 c += 1 if c % 2 == 1: f.append(2) while i * i <= x: if x % i == 0: c = 0 while x % i == 0: c += 1 x //= i if c % 2 == 1: f.append(i) i += 2 if x > 1: f.append(x) f = tuple(f) if f in v: v[f] += 1 else: v[f] = 1 v0 = 1 vx = 0 for x in v: if x == tuple([]) or v[x] > 1: v0 = max(v0, v[x]) if v[x] % 2 == 0 or x == tuple([]): vx += v[x] vx = max(vx, v0) for i in range(q): w = int(input()) if w == 0: print(v0) else: print(vx)
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR LIST VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Let us call two integers $x$ and $y$ adjacent if $\frac{lcm(x, y)}{gcd(x, y)}$ is a perfect square. For example, $3$ and $12$ are adjacent, but $6$ and $9$ are not. Here $gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$, and $lcm(x, y)$ denotes the least common multiple (LCM) of integers $x$ and $y$. You are given an array $a$ of length $n$. Each second the following happens: each element $a_i$ of the array is replaced by the product of all elements of the array (including itself), that are adjacent to the current value. Let $d_i$ be the number of adjacent elements to $a_i$ (including $a_i$ itself). The beauty of the array is defined as $\max_{1 \le i \le n} d_i$. You are given $q$ queries: each query is described by an integer $w$, and you have to output the beauty of the array after $w$ seconds. -----Input----- The first input line contains a single integer $t$ ($1 \le t \le 10^5)$ — the number of test cases. The first line of each test case contains a single integer $n$ ($1 \le n \le 3 \cdot 10^5$) — the length of the array. The following line contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10^6$) — array elements. The next line contain a single integer $q$ ($1 \le q \le 3 \cdot 10^5$) — the number of queries. The following $q$ lines contain a single integer $w$ each ($0 \le w \le 10^{18}$) — the queries themselves. It is guaranteed that the sum of values $n$ over all test cases does not exceed $3 \cdot 10^5$, and the sum of values $q$ over all test cases does not exceed $3 \cdot 10^5$ -----Output----- For each query output a single integer — the beauty of the array at the corresponding moment. -----Examples----- Input 2 4 6 8 4 2 1 0 6 12 3 20 5 80 1 1 1 Output 2 3 -----Note----- In the first test case, the initial array contains elements $[6, 8, 4, 2]$. Element $a_4=2$ in this array is adjacent to $a_4=2$ (since $\frac{lcm(2, 2)}{gcd(2, 2)}=\frac{2}{2}=1=1^2$) and $a_2=8$ (since $\frac{lcm(8,2)}{gcd(8, 2)}=\frac{8}{2}=4=2^2$). Hence, $d_4=2$, and this is the maximal possible value $d_i$ in this array. In the second test case, the initial array contains elements $[12, 3, 20, 5, 80, 1]$. The elements adjacent to $12$ are $\{12, 3\}$, the elements adjacent to $3$ are $\{12, 3\}$, the elements adjacent to $20$ are $\{20, 5, 80\}$, the elements adjacent to $5$ are $\{20, 5, 80\}$, the elements adjacent to $80$ are $\{20, 5, 80\}$, the elements adjacent to $1$ are $\{1\}$. After one second, the array is transformed into $[36, 36, 8000, 8000, 8000, 1]$.
import sys input = lambda: sys.stdin.readline().rstrip() def gcd(a, b): while b: a, b = b, a % b return a def isPrimeMR(n): d = n - 1 d = d // (d & -d) L = ( [2, 7, 61] if n < 1 << 32 else ( [2, 3, 5, 7, 11, 13, 17] if n < 1 << 48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] ) ) for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = y * y % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 def findFactorRho(n): m = 1 << n.bit_length() // 8 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x - ys), n) if g < n: if isPrimeMR(g): return g elif isPrimeMR(n // g): return n // g return findFactorRho(g) def primeFactor(n): i = 2 ret = {} rhoFlg = 0 while i * i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += i % 2 + (3 if i % 3 == 1 else 1) if i == 101 and n >= 2**20: while n > 1: if isPrimeMR(n): ret[n], n = 1, 1 else: rhoFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if rhoFlg: ret = {x: ret[x] for x in sorted(ret)} return ret def divisors(N): pf = primeFactor(N) ret = [1] for p in pf: ret_prev = ret ret = [] for i in range(pf[p] + 1): for r in ret_prev: ret.append(r * p**i) return sorted(ret) def squareFree(n): pf = primeFactor(n) s = 1 for p in pf: s *= p ** (pf[p] % 2) return s T = int(input()) for _ in range(T): N = int(input()) A = [squareFree(int(a)) for a in input().split()] D = {} for a in A: if a not in D: D[a] = 1 else: D[a] += 1 D2 = {} for d in D.keys(): v = d if D[d] % 2 else 1 if v not in D2: D2[v] = D[d] else: D2[v] += D[d] X = [max(D.values()), max(D2.values())] Q = int(input()) for _ in range(Q): q = int(input()) print(X[min(q, 1)])
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER LIST NUMBER NUMBER NUMBER VAR BIN_OP NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER
Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a_{l} | a_{l} + 1 | ...  | a_{r}. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or". -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) — the number of elements of sequence a. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^6) — the elements of sequence a. -----Output----- Print a single integer — the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Examples----- Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 -----Note----- In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
n = int(input()) a = list(map(int, input().split())) s1, s2 = set(), set() for each in a: st = set() st.add(each) for i in s1: st.add(each | i) s1 = st s2.update(s1) print(len(s2))
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 FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a_{l} | a_{l} + 1 | ...  | a_{r}. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or". -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) — the number of elements of sequence a. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^6) — the elements of sequence a. -----Output----- Print a single integer — the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Examples----- Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 -----Note----- In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
input() a, b = set(), set() for i in map(int, input().split()): a = {(i | j) for j in a} a.add(i) b.update(a) print(len(b))
EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a_{l} | a_{l} + 1 | ...  | a_{r}. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or". -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) — the number of elements of sequence a. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^6) — the elements of sequence a. -----Output----- Print a single integer — the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Examples----- Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 -----Note----- In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
def subarrayBitwiseOR(A): res = set() pre = {0} for x in A: pre = {(x | y) for y in pre} | {x} res |= pre return len(res) n = int(input()) arr = list(map(int, input().split())) print(subarrayBitwiseOR(arr))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a_{l} | a_{l} + 1 | ...  | a_{r}. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or". -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) — the number of elements of sequence a. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^6) — the elements of sequence a. -----Output----- Print a single integer — the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Examples----- Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 -----Note----- In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
n = input() r = set() s = set() l = list(map(int, input().split(" "))) for i in l: s = {(i | a) for a in s} s.add(i) r |= s print(len(r))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a_{l} | a_{l} + 1 | ...  | a_{r}. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or". -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) — the number of elements of sequence a. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^6) — the elements of sequence a. -----Output----- Print a single integer — the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Examples----- Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 -----Note----- In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
n, p, q = input(), set(), set() for i in map(int, input().split()): q = set(i | j for j in q) q.add(i) p.update(q) print(len(p))
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a_{l} | a_{l} + 1 | ...  | a_{r}. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or". -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) — the number of elements of sequence a. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^6) — the elements of sequence a. -----Output----- Print a single integer — the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Examples----- Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 -----Note----- In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
def brand(arr): ans = set() temp = set() for i in arr: temp = {(i | j) for j in temp} temp.add(i) ans.update(temp) return len(ans) a = input() lst = list(map(int, input().strip().split())) print(brand(lst))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a_{l} | a_{l} + 1 | ...  | a_{r}. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or". -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) — the number of elements of sequence a. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^6) — the elements of sequence a. -----Output----- Print a single integer — the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Examples----- Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 -----Note----- In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
import sys In = sys.stdin n = int(In.readline().strip()) arr = [int(x) for x in In.readline().split()] res, m = set(), set() for i in range(n): s = set() s.add(arr[i]) s.update([(x | arr[i]) for x in m]) m = s res.update(s) print(len(res))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def solve(A, B): count = [0, 0] o, moves = 0, 0 for i in range(len(A)): if A[i]: o += 1 if o == len(A) or o == 0: return "Unlucky Chef" for i in range(len(A)): op = not A[i] if A[i] == B[i]: continue if count[op]: count[op] -= 1 moves += 1 else: count[A[i]] += 1 return "Lucky Chef\n%d" % (moves + count[0] + count[1]) t = int(input()) getBoolList = lambda: [(i == "1") for i in input()] for _ in range(t): A, B = getBoolList(), getBoolList() print(solve(A, B))
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER RETURN BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) while t: countone = 0 countzero = 0 flag1 = 0 flag2 = 0 str1 = input() str2 = input() length = len(str1) for i in range(length): if str1[i] == "1": flag1 = 1 elif str1[i] == "0": flag2 = 1 if flag1 == 1 and flag2 == 1: for i in range(length): if str1[i] == "1" and str2[i] == "0": countone = countone + 1 elif str1[i] == "0" and str2[i] == "1": countzero = countzero + 1 print("Lucky Chef") print(max(countone, countzero)) else: print("Unlucky Chef") t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for i in range(int(input())): a = input() b = input() a1 = a[0] temp = 0 c = list(a) if c.count(a1) == len(a): print("Unlucky Chef") else: cnt1 = 0 cnt2 = 0 for j in range(len(a)): if a[j] == "0" and b[j] == "1": cnt1 += 1 elif a[j] == "1" and b[j] == "0": cnt2 += 1 print("Lucky Chef") print(min(cnt1, cnt2) + abs(cnt1 - cnt2))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
n = int(input()) for i in range(n): a = 0 b = 0 f1 = 0 f2 = 0 str1 = input() str2 = input() for j in range(0, len(str1)): if str1[j] == "1": f1 = 1 else: f2 = 1 if str1[j] != str2[j]: if str1[j] == "1": a = a + 1 else: b = b + 1 if a != 0 and f2 == 0 or b != 0 and f1 == 0: print("Unlucky Chef") else: print("Lucky Chef") print(a + b - 2 * min(a, b) + min(a, b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
N = int(input()) gifts = [] for index in range(0, 2 * N): gifts.append(input()) def numbers_in_binary(A_string, B_string): zero_to_one = 0 one_to_zero = 0 zeroesA = 0 onesA = 0 zeroesB = 0 onesB = 0 for x in range(0, len(A_string)): if A_string[x] == "0": zeroesA += 1 elif A_string[x] == "1": onesA += 1 if B_string[x] == "0": zeroesB += 1 elif B_string[x] == "1": onesB += 1 if A_string[x] == "0" and B_string[x] == "1": zero_to_one += 1 elif A_string[x] == "1" and B_string[x] == "0": one_to_zero += 1 return zero_to_one, one_to_zero, zeroesA, onesA, zeroesB, onesB def number_of_ops(zero_to_one, one_to_zero): operations = 0 while zero_to_one != 0 or one_to_zero != 0: if zero_to_one > 0 and one_to_zero > 0: operations += 1 zero_to_one -= 1 one_to_zero -= 1 elif zero_to_one > 0 and one_to_zero == 0: operations += 1 zero_to_one -= 1 elif one_to_zero > 0 and zero_to_one == 0: operations += 1 one_to_zero -= 1 print("Lucky Chef") print(operations) for index in range(0, len(gifts)): if index % 2 == 0: A = gifts[index] B = gifts[index + 1] zero_to_one, one_to_zero, zeroesA, onesA, zeroesB, onesB = numbers_in_binary( A, B ) if one_to_zero > 0 and zeroesA == 0 or zero_to_one > 0 and onesA == 0: print("Unlucky Chef") else: number_of_ops(zero_to_one, one_to_zero)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER RETURN VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) while t != 0: t -= 1 s1 = input() s2 = input() i = 0 i0 = 0 i1 = 0 while i < len(s1): if s1[i] != s2[i]: if s1[i] == "0": i0 += 1 else: i1 += 1 i += 1 k0 = s1.count("0") k1 = s1.count("1") ans = min(i0, i1) + abs(i1 - i0) if i1 > i0: if k0 >= 1: print("Lucky Chef") print(ans) else: print("Unlucky Chef") elif i1 == i0: print("Lucky Chef") print(ans) elif k1 >= 1: print("Lucky Chef") print(ans) else: print("Unlucky Chef")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def same(a): x = a[0] for i in range(1, len(a)): if x != a[i]: return False return True t = int(input()) while t: a = input() b = input() count = 0 a1 = "" if same(a) == True: print("Unlucky Chef") t -= 1 continue for i in range(len(a)): if a[i] != b[i]: count += 1 a1 += a[i] if same(a1) == True: print("Lucky Chef") print(len(a1)) t -= 1 continue c = a1.count("1") d = len(a1) - c if c < d: print("Lucky Chef") print(c + (d - c)) t -= 1 continue if d < c: print("Lucky Chef") print(d + (c - d)) t -= 1 continue if d == c: print("Lucky Chef") print(d) t -= 1 continue
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) while t > 0: a = input() b = input() if len(set(list(a))) != 1: dist = [] for i, j in zip(a, b): if i != j: dist.append(i) print("Lucky Chef") d = dist.count("1") e = dist.count("0") print(max(d, e)) else: print("Unlucky Chef") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def check(a): x = a[0] for n in a: if n != x: return False return True t = int(input().strip()) while t: a = input().strip() b = input().strip() if check(a): print("Unlucky Chef") else: print("Lucky Chef") xor = 0 a1 = 0 b1 = 0 a0 = 0 b0 = 0 for i in range(0, len(a)): if a[i] != b[i]: xor += 1 if a[i] == "1": a1 += 1 if b[i] == "1": b1 += 1 oa = abs(b1 - a1) xor = (xor - oa) / 2 print(int(xor + oa)) t -= 1
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) while t: A = input() B = input() mp1 = 0 p1 = 0 mp0 = 0 p0 = 0 for i in range(len(B)): if A[i] == B[i] and B[i] == "1": p1 += 1 elif A[i] == B[i] and B[i] == "0": p0 += 1 elif A[i] != B[i] and B[i] == "1": mp0 += 1 else: mp1 += 1 if mp0 + p0 == len(A) or mp1 + p1 == len(A): con = False elif mp1 + p0 >= mp0 + p0: con = True op = mp1 - mp0 mp1 -= op op += mp1 else: con = True op = mp0 - mp1 mp0 -= op op += mp0 if con: print("Lucky Chef") print(op) else: print("Unlucky Chef") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) for _t in range(t): A = input() B = input() l, c01, c10 = len(A), 0, 0 if A == "0" * l or A == "1" * l: print("Unlucky Chef") continue else: for i in range(l): a, b = A[i], B[i] if a == "0" and b == "1": c01 += 1 if a == "1" and b == "0": c10 += 1 print("Lucky Chef") print(abs(c01 - c10) + min(c10, c01))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR STRING VAR STRING VAR NUMBER IF VAR STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for w in range(int(input())): i = input() f = input() i0 = 0 i1 = 0 zeroto1 = 0 up = 0 down = 0 move = 0 diff = 0 for p in range(len(i)): if i[p] == "0": i0 = 1 if i[p] == "1": i1 = 1 if i[p] == "0" and f[p] == "1": up += 1 if i[p] == "1" and f[p] == "0": down += 1 move = min(up, down) + abs(up - down) if i0 == 1 and i1 == 1: print("Lucky Chef") print(move) else: print("Unlucky Chef")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) for i in range(0, t): a = input() b = input() l = len(a) o = 0 z = 0 po = 0 pz = 0 for j in range(0, l): if a[j] == "1": po += 1 else: pz += 1 for j in range(0, l): if a[j] == "0" and b[j] == "1": z += 1 elif a[j] == "1" and b[j] == "0": o += 1 x = min(z, o) s = x z -= x o -= x if z > 0 and po >= 1: s += z po += z z = 0 elif o > 0 and pz >= 1: s += o pz += o o = 0 if o == 0 and z == 0: print("Lucky Chef") print(s) else: print("Unlucky Chef")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
T = int(input()) ZERO_TO_ONE = -1 ONE_TO_ZERO = 1 LUCKY_CHEF = "Lucky Chef" UNLUCKY_CHEF = "Unlucky Chef" def compare(A, B): for a, b in zip(A, B): if a == "0" and b == "1": yield ZERO_TO_ONE if a == "1" and b == "0": yield ONE_TO_ZERO for i in range(0, T): A = input() B = input() ops = list(compare(A, B)) result = sum(ops) if result == 0: print(LUCKY_CHEF) print(len(ops) // 2) elif result > 0 and "0" in A: print(LUCKY_CHEF) print((len(ops) + result) // 2) elif result < 0 and "1" in A: print(LUCKY_CHEF) print((len(ops) - result) // 2) else: print(UNLUCKY_CHEF)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING EXPR VAR IF VAR STRING VAR STRING EXPR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for _ in range(0, int(input())): a, b = input(), input() zero = one = 0 if a.count("1") == len(a) or a.count("0") == len(a): print("Unlucky Chef") else: print("Lucky Chef") i = 0 while i < len(a): if a[i] != b[i]: if a[i] == "1": one += 1 else: zero += 1 i += 1 print(max(zero, one))
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
T = int(input()) for i in range(T): A = input() B = input() if "0" not in A or "1" not in A: print("Unlucky Chef") else: to1 = 0 to0 = 0 for i in range(len(A)): if not A[i] == B[i]: if A[i] == "0": to1 += 1 else: to0 += 1 moves = max(to1, to0) print("Lucky Chef", moves, sep="\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
import sys T = int(sys.stdin.readline()) for _ in range(0, T): A = list(sys.stdin.readline().rstrip()) B = list(sys.stdin.readline().rstrip()) if A[0] == "0": firstCharComplement = "1" else: firstCharComplement = "0" if not firstCharComplement in A: print("Unlucky Chef") else: print("Lucky Chef") zeroes = 0 ones = 0 mismatches = 0 for i in range(0, len(A)): if A[i] != B[i]: if A[i] == "0": zeroes += 1 else: ones += 1 print(zeroes + ones - min(zeroes, ones))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for t in range(int(input())): a = [int(j) for j in input()] b = [int(j) for j in input()] x = y = c = 0 if 0 in a and 1 in a: for i in range(len(a)): if a[i] != b[i]: if a[i] == 1: x += 1 else: y += 1 while x > 0 and y > 0: c += 1 x -= 1 y -= 1 if x > 0: c += x if y > 0: c += y print("Lucky Chef") print(c) else: print("Unlucky Chef")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER IF NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
test = int(input().strip()) for each in range(test): A = input().strip() B = input().strip() e0 = "0" in A e1 = "1" in A if not (e0 and e1): print("Unlucky Chef") continue n0 = 0 n1 = 0 for i in range(len(A)): if not A[i] == B[i]: if A[i] == "0": n0 += 1 else: n1 += 1 print("Lucky Chef") if n0 == n1: print(n0) elif n0 > n1: print(n0) else: print(n1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR ASSIGN VAR STRING VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) while t > 0: a = input() b = input() l = len(a) count1 = 0 count0 = 0 ans = 0 c = 0 d = 0 for i in range(l): if a[i] == "1": c = c + 1 if b[i] == "0": count1 = count1 + 1 else: d = d + 1 if b[i] == "1": count0 = count0 + 1 if c == l or d == l: print("Unlucky Chef") else: minimum = min(count1, count0) ans = ans + minimum left = abs(count1 - count0) ans = ans + left print("Lucky Chef") print(ans) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
T = int(input()) for _ in range(T): A = input() B = input() A_zero, A_one, miss0, miss1 = 0, 0, 0, 0 for a, b in zip(A, B): if a == "0": A_zero += 1 if b == "1": miss1 += 1 else: A_one += 1 if b == "0": miss0 += 1 xor_count = min(miss0, miss1) miss0 -= xor_count miss1 -= xor_count if miss1 == miss0: print("Lucky Chef") print(xor_count) elif miss1 != 0: if A_one == 0: print("Unlucky Chef") else: print("Lucky Chef") print(xor_count + miss1) elif A_zero == 0: print("Unlucky Chef") else: print("Lucky Chef") print(xor_count + miss0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) for i in range(t): a = str(input()) b = str(input()) if a == b: print("Lucky Chef") print(0) continue z = a.count("0") o = a.count("1") if z == len(a) or o == len(a): print("Unlucky Chef") else: ones = 0 zeros = 0 for i, j in enumerate(a): if a[i] != b[i]: if a[i] == "0": zeros += 1 else: ones += 1 print("Lucky Chef") print(max(ones, zeros))
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 IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def fun(): f = input() t = input() zero, one = 0, 0 noz, noo = 0, 0 for i in range(len(f)): if f[i] is "0": noz += 1 else: noo += 1 if f[i] is not t[i]: if f[i] is "0": zero += 1 else: one += 1 if not noz or not noo: print("Unlucky Chef") return print("Lucky Chef") print(max(zero, one)) t = int(input()) while t: fun() t -= 1
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
tests = int(input()) for i in range(tests): A = input() B = input() if "0" not in A and "0" in B or "1" not in A and "1" in B: print("Unlucky Chef") else: ans = 0 zeroes_required = 0 ones_required = 0 length = len(A) for j in range(length): if A[j] != B[j]: if A[j] == "0": ones_required += 1 else: zeroes_required += 1 ans += max(zeroes_required, ones_required) print("Lucky Chef") print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) for _ in range(t): a = input() b = input() t = 0 za, zb = 0, 0 oa, ob = 0, 0 n = len(a) ans = 0 for i in range(n): if a[i] != b[i]: t += 1 if a[i] == "0": za += 1 else: oa += 1 if b[i] == "0": zb += 1 else: ob += 1 if za == n and ob > 0 or oa == n and zb > 0: print("Unlucky Chef") else: for i in range(n): if za == zb and oa == ob: break else: ans += 1 t -= 1 if za > zb: za -= 1 oa += 1 else: za += 1 oa -= 1 print("Lucky Chef") print(ans + t // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for i in range(int(input())): a = input() b = input() if "0" not in a and "0" in b or "1" not in a and "1" in b: print("Unlucky Chef") else: count = 0 onee = 0 for j in range(len(a)): if a[j] != b[j]: if a[j] == "0": count += 1 else: onee += 1 print("Lucky Chef") print(max(count, onee))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
T = int(input()) for tc in range(T): A = [int(x) for x in list(input())] B = [int(x) for x in list(input())] if len(B) != len(A): print("Unlucky Chef") continue ln = len(B) if 0 not in A or 1 not in A: print("Unlucky Chef") continue count = 0 same = 0 for i in range(ln): if A[i] == 0 and B[i] == 1: count += 1 elif A[i] == 1 and B[i] == 0: count -= 1 else: same += 1 if count < 0: count *= -1 swaps = ln - count - same if swaps % 2 != 0: print("ERROR") count += swaps // 2 print("Lucky Chef") print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for _ in range(int(input())): a = input() b = input() c, d = 0, 0 for i in range(len(a)): if a[i] == "0": c += 1 else: d += 1 if c == 0 or d == 0: print("Unlucky Chef") continue c, d = 0, 0 for i in range(len(a)): if a[i] != b[i]: if a[i] == "0": c += 1 else: d += 1 c += d - min(c, d) print("Lucky Chef") print(c)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) for T in range(t): c0to1 = 0 c1to0 = 0 a = input() b = input() for i in range(len(a)): if a[i] == "1" and b[i] == "0": c1to0 = c1to0 + 1 elif a[i] == "0" and b[i] == "1": c0to1 += 1 c = list(a) if "1" in c and "0" not in c or "0" in c and "1" not in c: print("Unlucky Chef") else: print("Lucky Chef") print(max(c0to1, c1to0))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for _ in range(int(input())): result = None a, b = input(), input() if len(a) == len(b): c = [(x == "1") for x, y in zip(a, b) if x != y] zeros, ones = len(c) - sum(c), sum(c) if ones > zeros and any(x == "0" for x in a): result = ones elif zeros > ones and any(x == "1" for x in a): result = zeros elif ones == zeros: result = ones if result is not None: print("Lucky Chef") print(result) else: print("Unlucky Chef")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR VAR IF VAR VAR FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def yes(n): print("Lucky Chef") print(n) def no(): print("Unlucky Chef") for _ in range(int(input())): a, b = input(), input() zes = True if "0" in a else False ones = True if "1" in a else False if len(a) == 1: no() continue ctr = 0 os = 0 zs = 0 for ai, bi in zip(a, b): if ai != bi: if bi == "1": os += 1 else: zs += 1 if zs > 0 and not zes: no() elif os > zs: if ones: yes(os) else: no() else: yes(zs)
FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR NUMBER NUMBER ASSIGN VAR STRING VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) while t > 0: t -= 1 a = list(input()) b = list(input()) a0 = 0 a1 = 0 b0 = 0 b1 = 0 mismatch = [0, 0] for i in range(len(a)): if a[i] == "1": a1 += 1 else: a0 += 1 if b[i] == "1": b1 += 1 else: b0 += 1 if a[i] != b[i]: if a[i] == "0": mismatch[0] += 1 else: mismatch[1] += 1 if a1 == 0 and b1 > 0 or a0 == 0 and b0 > 0: print("Unlucky Chef") continue print("Lucky Chef") ans = max(mismatch) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def ops(a, b): n = len(a) azeroes = a.count("0") aones = n - azeroes bzeroes = b.count("0") bones = n - bzeroes if azeroes == 0 or aones == 0: return 0 c0 = 0 c1 = 0 for i in range(n): if a[i] == b[i]: continue if a[i] == "0": c0 += 1 else: c1 += 1 return max(c0, c1) t = int(input()) for i in range(t): a = input() b = input() res = ops(a, b) if res == 0: print("Unlucky Chef") else: print("Lucky Chef") print(res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def main(): T = int(input()) result = [] for x in range(0, T): A = input() B = input() c = 0 Count1 = 0 Count0 = 0 CountA1 = 0 CountA0 = 0 for x in range(0, len(A)): if A[x] == "0": CountA0 = CountA0 + 1 else: CountA1 = CountA1 + 1 if A[x] == "0" and B[x] == "1": Count0 = Count0 + 1 if A[x] == "1" and B[x] == "0": Count1 = Count1 + 1 if CountA0 == len(A) or CountA1 == len(A): result.append("Unlucky Chef") continue if Count1 > Count0: c = Count1 else: c = Count0 result.append("Lucky Chef") result.append(c) for x in result: print(x) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
import sys t = int(input()) while t > 0: a = input() b = input() j = 0 diff_0 = 0 diff_1 = 0 diff = 0 while j < len(a) - 1: if a[j] != a[j + 1]: diff = 1 j += 1 break j += 1 i = 0 while i < len(a): if a[i] != b[i]: if a[i] == "1": diff_1 += 1 else: diff_0 += 1 i += 1 t -= 1 if diff == 0: if max(diff_1, diff_0) == 0: print("Lucky Chef") print("0") else: print("Unlucky Chef") elif max(diff_1, diff_0) == 0: print("Lucky Chef") print("0") else: print("Lucky Chef") print(max(diff_1, diff_0))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for t in range(int(input())): a = input() b = input() if a == b: print("Lucky Chef") print(0) elif max(a.count("0"), a.count("1")) == len(a): print("Unlucky Chef") else: zeros = 0 ones = 0 for i, j in zip(a, b): if i == j: continue elif i == "0": zeros += 1 else: ones += 1 print("Lucky Chef") print(min(zeros, ones) + abs(zeros - ones))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def solve(a, b): if "0" not in a: return 0 if "1" not in a: return 0 zc = oc = 0 otz = 0 zto = 0 for i in range(len(a)): if a[i] == "0": zc += 1 if a[i] != b[i]: zto += 1 elif a[i] == "1": oc += 1 if a[i] != b[i]: otz += 1 return max(otz, zto) t = int(input()) for i in range(t): s1 = input() s2 = input() ans = solve(s1, s2) if ans == 0: print("Unlucky Chef") else: print("Lucky Chef") print(ans)
FUNC_DEF IF STRING VAR RETURN NUMBER IF STRING VAR RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for _ in range(int(input())): s1 = input() s2 = input() su1 = 0 su2 = 0 for i in range(len(s1)): su1 += ord(s1[i]) - ord("0") su2 += ord(s2[i]) - ord("0") if su1 == 0 and su2 > 0 or su1 == len(s1) and su2 < len(s1): print("Unlucky Chef") continue else: print("Lucky Chef") a = 0 _0 = 0 _1 = 0 for i in range(len(s1)): if s1[i] != s2[i]: if s1[i] == "0": _0 += 1 else: _1 += 1 a = abs(_0 - _1) + min(_0, _1) print(a)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
def main(): testCases = int(input()) results = [] for i in range(testCases): a = input() b = input() a0 = 0 a1 = 0 a0_1 = 0 a1_0 = 0 for j in range(len(a)): aj = a[j] bj = b[j] if aj == bj: if aj == "0": a0 += 1 else: a1 += 1 elif aj == "0": a0_1 += 1 else: a1_0 += 1 if a0_1 != 0 and a1_0 != 0: results.append("Lucky Chef") results.append(a0_1 + a1_0 - min(a0_1, a1_0)) elif a0_1 != 0 and a1 != 0: results.append("Lucky Chef") results.append(a0_1) elif a1_0 != 0 and a0 != 0: results.append("Lucky Chef") results.append(a1_0) else: results.append("Unlucky Chef") for i in results: print(i) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) for i in range(t): a = list(input()) b = list(input()) l = len(a) ctr0 = 0 ctr1 = 0 for i in range(0, l): if a[i] != b[i]: if a[i] == "0": ctr0 += 1 else: ctr1 += 1 ctr = max(ctr0, ctr1) if "1" in a and "0" in a: print("Lucky Chef") print(ctr) else: print("Unlucky Chef")
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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) for i in range(t): a = input() b = input() if a == b: print("Lucky Chef") print(0) elif a.count("1") == len(a) or a.count("0") == len(b): print("Unlucky Chef") else: count1 = 0 count2 = 0 for j in range(0, len(a)): if a[j] == "0" and b[j] == "1": count1 += 1 elif a[j] == "1" and b[j] == "0": count2 += 1 print("Lucky Chef") print(max(count1, count2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for _ in range(int(input())): result = None a, b = ([(c == "1") for c in input()] for _ in range(2)) if len(a) == len(b): c = list(map(lambda x: x[0], filter(lambda x: x[0] != x[1], zip(a, b)))) ones = sum(c) zeros = len(c) - ones if ones > zeros: if not all(a): result = ones elif ones < zeros: if any(a): result = zeros else: result = ones if result is not None: print("Lucky Chef") print(result) else: print("Unlucky Chef")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR VAR VAR STRING VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
T = int(input()) for t in range(T): s1 = list(map(int, list(input()))) s2 = list(map(int, list(input()))) s3 = map(lambda x, y: x ^ y, s1, s2) n1 = sum(s1) n2 = sum(s2) n3 = sum(s3) l1 = len(s1) if n1 == 0 or n1 == l1: print("Unlucky Chef") else: print("Lucky Chef") d = abs(n2 - n1) print((n3 + d) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
for t in range(int(input())): a = list(input()) b = list(input()) zero_present = any(map(lambda x: x == "0", a)) one_present = any(map(lambda x: x == "1", a)) one_count = sum(map(lambda x, y: 1 if x == "0" and y == "1" else 0, b, a)) zero_count = sum(map(lambda x, y: 1 if x == "1" and y == "0" else 0, b, a)) ans = 0 if one_count < zero_count: zero_count -= one_count ans += one_count one_count = 0 else: one_count -= zero_count ans += zero_count zero_count = 0 ok = True if one_count > 0: if zero_present: ans += one_count else: ok = False elif zero_count > 0: if one_present: ans += zero_count else: ok = False if not ok: print("Unlucky Chef") else: print("Lucky Chef") print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR STRING NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR STRING NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
T = int(input()) aList = [] bList = [] for i in range(T): aList.append(input()) bList.append(input()) for i in range(T): a = aList[i] b = bList[i] temp = "" for j in range(len(a)): if a[j] != b[j]: temp = temp + a[j] oneCount = temp.count("1") zeroCount = len(temp) - oneCount totalLength = len(temp) if oneCount > zeroCount: minimum = zeroCount else: minimum = oneCount if oneCount == totalLength: if "0" in a: print("Lucky Chef") print(totalLength) else: print("Unlucky Chef") elif zeroCount == totalLength: if "1" in a: print("Lucky Chef") print(totalLength) else: print("Unlucky Chef") else: print("Lucky Chef") answer = minimum + (totalLength - 2 * minimum) print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
T = int(input()) for t in range(T): A = input() B = input() n = len(A) a = 0 b = 0 d = 0 if A == "1" * n or A == "0" * n: print("Unlucky Chef") else: for i in range(n): if A[i] != B[i]: d += 1 if A[i] == "1": a += 1 else: b += 1 c = min(a, b) ans = d - c print("Lucky Chef") print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) while t: t -= 1 a = input() b = input() x = True y = False ans1 = 0 ans2 = 0 for i in range(len(a)): x = x and int(a[i]) y = y or int(a[i]) if a[i] == "1" and b[i] == "0": ans1 += 1 if a[i] == "0" and b[i] == "1": ans2 += 1 if not x and y: print("Lucky Chef") ma = max(ans1, ans2) print(ma) else: print("Unlucky Chef")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
t = int(input()) while t > 0: a = list(input()) b = list(input()) r = 0 q = 0 x = a.count("1") y = a.count("0") z = b.count("0") for i in range(len(a)): if a[i] == "1" and b[i] == "0": r += 1 if a[i] == "0" and b[i] == "1": q += 1 if x == len(a) or y == len(a): print("Unlucky Chef") elif x != len(a) and y != len(a) and z == len(b): print("Lucky Chef") print(x) else: print("Lucky Chef") print(max(r, q)) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER