description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, L = tuple(map(int, input().split())) cost = list(map(int, input().split())) x = "0" * (n - len(bin(L)[2:])) + bin(L)[2:] z = [x] for i in range(len(x)): if x[i] == "0": l = x[:i] + "1" + "0" * (len(x) - i - 1) assert len(l) == len(x) z.append(l) for i in range(len(cost) - 1): cost[i + 1] = min(cost[i + 1], 2 * cost[i]) for i in range(len(cost), len(x)): cost.append(cost[-1] * 2) assert len(cost) == len(x) c = [] for l in z: co = 0 for i in range(len(x)): co += int(l[i]) * cost[len(x) - 1 - i] c.append(co) print(min(min(c), 2 * cost[-1]))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
def GETBIT(x, bit): return x >> bit & 1 n, volume = map(int, input().split()) c = list(map(int, input().split())) rs = 1000000000000000000 pos = 30 s = 0 while pos >= 0: if 1 << pos >= volume and pos <= n - 1: rs = min(rs, c[pos]) if GETBIT(volume, pos) == 1: for j in range(min(pos + 1, n)): rs = min(rs, s + (1 << pos + 1 - j) * c[j]) if pos < len(c) - 1: rs = min(rs, s + c[pos + 1]) mi = 1000000000000000000 for j in range(min(pos + 1, n)): mi = min(mi, (1 << pos - j) * c[j]) s += mi else: for j in range(min(pos + 1, n)): rs = min(rs, s + (1 << pos - j) * c[j]) pos -= 1 rs = min(rs, s) print(rs)
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, l = [int(x) for x in input().strip().split()] c = [int(x) for x in input().strip().split()] tc = 0 for i in range(1, len(c)): c[i] = min(c[i], 2 * c[i - 1]) for i in range(32): c.append(c[-1] * 2) tc = 0 bl = bin(l)[:1:-1] bl += "0" * (len(c) - len(bl) - 1) for i in range(len(bl)): if bl[i] == "1": tc += c[i] else: tc = min(tc, c[i]) print(tc)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
def f(bs): return int(bs, 2) // (1 << n - 1) * a[-1] + sum( a[i] for i in range(min(n - 1, len(bs))) if bs[-i - 1] == "1" ) n, x = map(int, input().split()) (*a,) = map(int, input().split()) for i in range(1, n): a[i] = min(a[i], 2 * a[i - 1]) bx = "0" * n + bin(x)[2:] ans = f(bx) for i in range(len(bx)): if bx[i] == "0": ans = min(ans, f(bx[:i] + "1" + "0" * (len(bx) - i - 1))) print(ans)
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, L = map(int, input().split()) lst = [] for x in input().split(): lst.append(int(x)) lst.extend([10**20] * (31 - n)) for x in range(len(lst) - 1): lst[x + 1] = min(lst[x + 1], 2 * lst[x]) s = bin(L)[2:] s = s[::-1] price = 0 for x in range(len(s)): price += int(s[x]) * lst[x] for x in range(len(lst)): if x >= len(s): price = min(price, lst[x]) elif s[x] == "0": p = lst[x] for y in range(x + 1, len(s)): p += int(s[y]) * lst[y] price = min(price, p) print(price)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
def ceil(a, b): if a % b: return a // b + 1 return a // b n, k = map(int, input().split()) a = list(map(int, input().split())) b = [0] * n b[0] = a[0] for i in range(1, n): b[i] = min(a[i], 2 * b[i - 1]) def check(i, k, b): if i == -1: return 0 return min(b[i] * (k // 2**i) + check(i - 1, k % 2**i, b), b[i] * ceil(k, 2**i)) print(check(n - 1, k, b))
FUNC_DEF IF BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, l = map(int, input().split()) p = list(map(int, input().split())) d = [] d = [[p[i] / 2**i, i + 1] for i in range(n)] d.sort(key=lambda x: x[0]) res = 10**18 q = l curres = 0 for i in d: if i[1] == 1: curres += p[i[1] - 1] * q res = min(res, curres) break curb = q // 2 ** (i[1] - 1) curres += curb * p[i[1] - 1] res = min(res, curres + p[i[1] - 1]) q %= 2 ** (i[1] - 1) print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, L = map(int, input().split()) c = list(map(int, input().split())) p = [10**18] * 31 p[0] = c[0] for i in range(1, 31): if i < n: p[i] = c[i] for j in range(i): p[i] = min(p[i], p[j] * 2 ** (i - j)) s = bin(L)[::-1][:-2] ans = 0 for i in range(len(s)): if s[i] == "1": ans += p[i] for i in range(len(s), 31): ans = min(ans, p[i]) s = bin(L)[2:] cur = p[len(s) - 1] for i in range(1, len(s)): if s[i] == "1": cur += p[len(s) - i - 1] continue if s[i + 1 :].count("1"): ans = min(ans, cur + p[len(s) - i - 1]) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
num_types, req_l = list(map(int, input().split())) costs = [0] costs.extend(map(int, input().split())) if req_l == 0: print(0) else: volumes = [0] for x in range(num_types): if 2**x <= req_l: volumes.append(2**x) else: break volume_len = len(volumes) extra_part = costs[volume_len:] + [999999999999999999999999999999] min_extra = min(extra_part) min_idx = extra_part.index(min_extra) + volume_len costs = costs[:volume_len] best = 999999999999999999999999999 for idx, v in enumerate(volumes): if idx == 0: continue new_best = costs[idx] / v if new_best < best: best = new_best else: costs[idx] = -1 for i in range(len(volumes) - 1, -1, -1): if costs[i] < 0: costs[i : i + 1] = [] volumes[i : i + 1] = [] volume_len = len(volumes) out = [] for i in range(volume_len - 1, -1, -1): if req_l > 0: needed = req_l // volumes[i] req_l -= volumes[i] * needed out.append((costs[i] * needed, costs[i] * (1 + needed))) else: out.append((0, costs[i])) prev = 999999999999999999999999999999 running_total = 0 for curr_contrib, override_cost in out[::-1]: running_total += curr_contrib if override_cost < running_total: running_total = override_cost ans = min(running_total, min_extra) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER LIST ASSIGN VAR VAR BIN_OP VAR NUMBER LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, l = input().split() n = int(n) l = int(l) c = list(map(int, input().strip().split()))[:n] pow2 = [1] for i in range(n - 1): pow2.append(2 * pow2[i]) for i in range(n - 1): c[i + 1] = min(c[i + 1], 2 * c[i]) def cost(pos, money): if pos == 0: return c[pos] * money take = int(money / pow2[pos]) ret = c[pos] * take money -= pow2[pos] * take if money == 0: return ret return c[pos] * take + min(cost(pos - 1, money), c[pos]) print(cost(n - 1, l))
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 FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
def main(): n, m = map(int, input().split()) v, l, nxt = 1, [], [(0, m)] for c in map(int, input().split()): l.append((c / v, v, c)) v *= 2 minv = hi = 1 << 60 for _, v, c in sorted(l): if minv > v: minv, cur, nxt = v, nxt, [] for cost, rest in cur: nxt.append((cost + rest // v * c, rest % v)) cost += (rest + v - 1) // v * c if hi > cost: hi = cost print(hi) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER LIST LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
def get_ints(): return list(map(int, input().strip().split())) def lemonade(): n, L = get_ints() costs = get_ints() mini = L * costs[0] ratio = [(costs[i] / 2**i, 2**i, costs[i]) for i in range(n)] ratio.sort() mini_overweight = mini current_cost = 0 remaining = L for cost, liters, c in ratio: nb_of_bottle = remaining // liters current_cost += nb_of_bottle * c remaining -= nb_of_bottle * liters if remaining > 0: overweight = current_cost + c if overweight < mini_overweight: mini_overweight = overweight print(min(mini_overweight, current_cost)) lemonade()
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) n, L = mi() C = li() for i in range(1, n): C[i] = min(C[i], C[i - 1] * 2) x = 2 ** (n - 1) y = 0 z = 10**18 for i in range(n - 1, -1, -1): t = L // x y += C[i] * t z = min(z, y + C[i]) L %= x x //= 2 z = min(z, y) print(z)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
s = input() s1 = s.split() tot = int(s1[1]) s = input() s1 = s.split() l = [int(i) for i in s1] avg = [[l[i] / 2**i, i] for i in range(len(l))] avg.sort() cost = 0 i = 0 d = {} def fun(i, tot): if i == len(avg): return 100000000.0 elif (i, tot) in d: return d[i, tot] elif tot % 2 ** avg[i][1] == 0: return tot // 2 ** avg[i][1] * l[avg[i][1]] else: a = (tot // 2 ** avg[i][1] + 1) * l[avg[i][1]] b = tot // 2 ** avg[i][1] * l[avg[i][1]] + fun(i + 1, tot % 2 ** avg[i][1]) d[i, tot] = min(a, b) return min(a, b) print(fun(0, tot))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, l = map(int, input().split()) m = [0] + list(map(int, input().split())) for i in range(2, n + 1): m[i] = min(m[i], m[i - 1] * 2) ans = 10**18 z = 1 k = 0 while z < n + 1: k += l // 2 ** (n - z) * m[-z] l = l % 2 ** (n - z) if l == 0: ans = min(ans, k) break else: ans = min(ans, k + m[-z]) z += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, L = map(int, input().split()) pr = list(map(int, input().split())) res = 0 poss = [] ber = [(pr[i] / 2**i, i) for i in range(n)] ber.sort() for i in range(n): d = L // 2 ** ber[i][1] res += d * pr[ber[i][1]] L -= d * 2 ** ber[i][1] if L == 0: poss.append(res) poss.append(res + pr[ber[i][1]]) print(min(poss))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
n, L = map(int, input().split()) c = list(map(int, input().split())) + [0] * (30 - n) for i in range(len(c) - 1): if c[i + 1] > 2 * c[i]: c[i + 1] = 2 * c[i] if c[i + 1] == 0: c[i + 1] = 2 * c[i] k = 0 litres = 0 cost = 0 x = L while k < 30: if c[k] <= cost: cost = c[k] litres = pow(2, k) if x & 1: cost += c[k] litres += pow(2, k) x >>= 1 k += 1 print(cost)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
T = int(input()) for _ in range(0, T): n = int(input()) s = [int(x) for x in input().split()] pos = [0] * 35 for i in range(0, len(s)): tt = bin(s[i])[2:] tt = "0" * (35 - len(tt)) + tt for j in range(35): pos[j] += int(tt[j]) ans = "DRAW" turn = 0 for i in range(0, 35): if pos[i] % 2 != 0: if pos[i] % 4 == 3 and (n - pos[i]) % 2 == 0: ans = "LOSE" else: ans = "WIN" break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
import sys inpy = [int(x) for x in sys.stdin.read().split()] t = inpy[0] index = 1 for _ in range(t): n = inpy[index] num = inpy[index + 1 : index + 1 + n] index += 1 + n memo = [0] * 32 for i in range(32): x = 1 << i for j in num: if j & x: memo[i] += 1 res = 0 for i in reversed(memo): if i % 2 == 0: continue elif i % 4 == 1 or i % 4 == 3 and n % 2 == 0: print("WIN") res = 1 break elif i % 4 == 3: print("LOSE") res = 3 break if res == 0: print("DRAW")
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) bits = [0] * 32 for a in A: for i in range(31, -1, -1): if a & 1 << i: bits[i] += 1 for b in reversed(bits): if b % 4 == 1: print("WIN") break if b % 4 == 3: print("LOSE" if N % 2 else "WIN") break else: print("DRAW")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING EXPR FUNC_CALL VAR STRING
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) flg = 1 for i in range(31, -1, -1): cnt = 0 for a in A: if a >> i & 1: cnt += 1 if cnt & 1: flg = 0 if cnt % 4 == 1: print("WIN") elif N & 1: print("LOSE") else: print("WIN") break if flg: print("DRAW") main()
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ones = [0] * 40 for i in range(40): for ai in a: ones[i] += ai >> i & 1 for i in range(39, -1, -1): if ones[i] % 2 == 0: continue else: if ones[i] % 4 == 3 and (n - ones[i]) % 2 == 0: print("LOSE") else: print("WIN") break else: print("DRAW")
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 BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) ar = [int(x) for x in input().split()] bit = [0] * 32 dr = True for i in range(32): for j in ar: bit[i] += 1 if 1 << i & j else 0 bit = bit[::-1] for i in bit: if i % 2 != 0: dr = False if i % 4 == 3 and (n - i) % 2 == 0: print("LOSE") else: print("WIN") break if dr: print("DRAW")
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
import sys input = sys.stdin.readline d = {(1): "WIN", (0): "LOSE", (-1): "DRAW"} def main(): t = int(input()) for _ in range(t): n = int(input()) a = map(int, input().split()) f = [0] * 30 for x in a: for b in range(30): if x >> b & 1: f[b] += 1 ans = -1 for x in reversed(range(30)): if f[x] % 2 == 1: ans = 0 if f[x] % 4 == 3 and (n - f[x]) % 2 == 0 else 1 break print(d[ans]) main()
IMPORT ASSIGN VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) c = [(0) for j in range(31)] msb = 0 for j in l: a = bin(j).lstrip("0b") msb = max(msb, len(a) - 1) for k in range(len(a) - 1, -1, -1): if a[k] == "1": c[len(a) - 1 - k] += 1 ans = "DRAW" for j in range(msb, -1, -1): if c[j] % 2 == 0: continue else: if c[j] % 4 == 3 and (n - c[j]) % 2 == 0: ans = "LOSE" else: ans = "WIN" break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
from sys import stdin, stdout fullans = "" for _ in range(int(stdin.readline())): n = int(stdin.readline()) ls = list(map(int, stdin.readline().split())) bit = 32 check = True while bit >= 0 and check: x = 0 for i in ls: if i & 1 << bit: x += 1 y = n - x if not x & 1: bit -= 1 else: check = False if x % 4 == 1: fullans += "WIN\n" elif y % 2 == 0: fullans += "LOSE\n" else: fullans += "WIN\n" if check: fullans += "DRAW\n" stdout.write(fullans)
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) (t,) = I() for _ in range(t): (n,) = I() l = I() an = -1 for i in range(30, -1, -1): x = 0 y = 0 for j in range(n): if l[j] >> i & 1: x += 1 else: y += 1 if x % 2: if x % 4 == 3 and y % 2 == 0: an = 0 else: an = 1 break if an != -1: print("LWOISNE"[an::2]) else: print("DRAW")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
def solution(n, arr): nums = {} for el in arr: if el in nums: nums[el][1] += 1 else: nums[el] = [el, 1] if 0 in nums: del nums[0] order_num = 2**29 del_els, k = [], 0 while nums: for el in nums: if nums[el][0] >= order_num: k += nums[el][1] nums[el][0] -= order_num if not nums[el][0]: del_els.append(el) for el in del_els: del nums[el] if k % 2: return "WIN" if k % 4 == 1 or (n - k) % 2 else "LOSE" k = 0 del_els.clear() order_num >>= 1 return "DRAW" for test_i in range(int(input())): n = int(input()) arr = list(map(int, input().split())) print(solution(n, arr))
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST VAR NUMBER IF NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER WHILE VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
def DecimalToBinary(a): s = [] while a >= 1: s.append(a % 2) a = a // 2 return s def find_sum(a, p, sum): for i in range(len(a)): if a[i] // 2**p > 0: for j in range(p): a[i] = a[i] // 2 sum = sum + a[i] % 2 return sum t = int(input()) l = [] for i in range(t): n = int(input()) sum = 0 a = list(map(int, input().split())) xor = a[0] for i in range(1, n): xor = xor ^ a[i] xor = DecimalToBinary(xor) lenth = len(xor) - 1 sum = find_sum(a, lenth, sum) if sum == 1: l.append("WIN") elif sum % 2 == 0: l.append("DRAW") elif (n - sum) % 2 == 0: if sum % 4 == 1: l.append("WIN") else: l.append("LOSE") else: l.append("WIN") for i in l: print(i)
FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
for _ in range(int(input())): n = int(input()) a = [int(o) for o in input().split()] ones = [0] * 35 zeros = [0] * 35 for i in a: ba = bin(i)[2:][::-1] j = -1 for k in ba: if k == "1": ones[j] += 1 else: zeros[j] += 1 j -= 1 res = "DRAW" for i in range(35): if ones[i] % 2 != 0: if ones[i] % 4 == 3 and (n - ones[i]) % 2 == 0: res = "LOSE" else: res = "WIN" break print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
import sys def solve(significant, filler): if filler % 2 == 0: return significant % 4 == 1 return True def i(): return sys.stdin.readline()[:-1] for _ in range(int(i())): digits = [0] * 30 n = int(i()) nums = map(int, i().split()) for num in nums: binNum = bin(num) binNum = binNum[2:] binNum = binNum[::-1] for index, char in enumerate(binNum): if char == "1": digits[index] += 1 digits = digits[::-1] msb = 0 draw = False for x in range(30): if digits[x] % 2 != 0: msb = digits[x] break else: print("DRAW") draw = True if not draw: if solve(msb, n - msb): print("WIN") else: print("LOSE")
IMPORT FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
def solve(): n = int(input()) lst = list(map(int, input().split())) k = 1 while k < 10**9: k *= 2 num = 0 while k and num % 2 == 0: num = 0 for i in lst: if i % (k * 2) // k == 1: num += 1 k //= 2 if k == 0 and num % 2 == 0: print("DRAW") return 0 if num % 4 == 1 or n % 2 == 0: print("WIN") else: print("LOSE") for i in range(int(input())): solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s) sys.stdout.write("\n") def wi(n): sys.stdout.write(str(n)) sys.stdout.write("\n") def wia(a, sep=" "): sys.stdout.write(sep.join([str(x) for x in a])) sys.stdout.write("\n") def go(n, k): if k % 4 == 1: return True else: return n % 2 == 0 def solve(n, a): for bit in range(32, -1, -1): cnt = 0 for i in range(n): if a[i] & 1 << bit > 0: cnt += 1 if cnt % 2 == 0: continue if go(n, cnt): ws("WIN") else: ws("LOSE") return ws("DRAW") def main(): for _ in range(ri()): n = ri() a = ria() solve(n, a) main()
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN BIN_OP VAR NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
d = {(1): "WIN", (0): "LOSE", (-1): "DRAW"} ans = [] for _ in range(int(input())): n = int(input()) u = list(map(int, input().split())) f = [0] * 30 for x in u: for b in range(30): if x >> b & 1: f[b] += 1 ansi = -1 for x in range(29, -1, -1): if f[x] % 2 == 1: if f[x] % 4 == 3 and (n - f[x]) % 2 == 0: ansi = 0 else: ansi = 1 break ans.append(d[ansi]) print("\n".join(ans))
ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move in the game: * During his move, a player chooses any element of the array and removes it from this array, xor-ing it with the current score of the player. More formally: if the current score of the player is x and the chosen element is y, his new score will be x ⊕ y. Here ⊕ denotes [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that after a move element y is removed from a. * The game ends when the array is empty. At the end of the game the winner is the player with the maximum score. If both players have the same score then it's a draw. If both players play optimally find out whether Koa will win, lose or draw the game. Input Each test contains multiple test cases. The first line contains t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows. The first line of each test case contains the integer n (1 ≤ n ≤ 10^5) — the length of a. The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — elements of a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print: * WIN if Koa will win the game. * LOSE if Koa will lose the game. * DRAW if the game ends in a draw. Examples Input 3 3 1 2 2 3 2 2 3 5 0 0 0 2 2 Output WIN LOSE DRAW Input 4 5 4 1 5 1 3 4 1 0 1 6 1 0 2 5 4 Output WIN WIN DRAW WIN Note In testcase 1 of the first sample we have: a = [1, 2, 2]. Here Koa chooses 1, other player has to choose 2, Koa chooses another 2. Score for Koa is 1 ⊕ 2 = 3 and score for other player is 2 so Koa wins.
for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) for i in range(30, -1, -1): cnt = 0 for j in l: if j & 1 << i: cnt += 1 if cnt % 4 == 1 or cnt % 4 == 3 and n - cnt & 1: print("WIN") break elif cnt % 4 == 3: print("LOSE") break else: print("DRAW")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1
class Solution: def integerReplacement(self, n): ans = 0 while n > 1: if n % 2 == 0: n = n // 2 elif n % 4 == 1 or n == 3: n -= 1 else: n += 1 ans += 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1
class Solution: def integerReplacement(self, n): variants = [n] nsteps = 0 seen = set() while True: n = len(variants) for i in range(n): v = variants[i] if v == 1: return nsteps if v % 2 == 0: x = v // 2 if x in seen: variants[i] = 0 else: variants[i] = x seen.add(x) else: for x in (v - 1, v + 1): if x not in seen: variants.append(x) seen.add(x) nsteps += 1
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1
class Solution: def Is2(self, n): root = int(math.log(n, 2)) return 2**root == n def GetNear2(self, n): if n == 0: return -1 if n == 1: return 0 if n == 2: return 1 if self.Is2(n): return n for ind in range(n - 1, n + 2): if self.Is2(ind): return ind return -1 def integerReplacement(self, n): m = n cnt = 0 while m != 1: if m == 1: return cnt if m == 2: return 1 + cnt if m <= 4: return 2 + cnt if m <= 6: return 3 + cnt if m % 2 == 0: cnt += 1 m = int(m / 2) continue k = m % 4 if k == 1: cnt += 1 m = int(m - 1) elif k == 3: cnt += 1 m = int(m + 1) return cnt
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP NUMBER VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN BIN_OP NUMBER VAR IF VAR NUMBER RETURN BIN_OP NUMBER VAR IF VAR NUMBER RETURN BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1
class Solution: def integerReplacement(self, n): queue = collections.deque([n]) step = 0 while len(queue): sz = len(queue) while sz > 0: sz -= 1 num = queue.popleft() if num == 1: return step if num & 1: queue.append(num + 1) queue.append(num - 1) else: queue.append(num // 2) step += 1 return step
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1
class Solution: def integerReplacement(self, n): def dfs(n): if n == 1: return 0 if n == 3: return 2 if n & 1 == 0: return dfs(n >> 1) + 1 elif n >> 1 & 1 == 0: return dfs(n - 1) + 1 else: return dfs(n + 1) + 1 return dfs(n)
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1
class Solution: def integerReplacement(self, n): return self.integerReplacementDP(n) if n == 1: return 0 if n % 2 == 0: return 1 + self.integerReplacement(n / 2) else: return 1 + min( self.integerReplacement(n + 1), self.integerReplacement(n - 1) ) def integerReplacementDP(self, n, dp=None): if dp is None: dp = {} if n == 1: return 0 if n not in dp: if n % 2 == 0: dp[n] = 1 + self.integerReplacementDP(n / 2, dp=dp) else: dp[n] = 1 + min( self.integerReplacementDP(n + 1, dp=dp), self.integerReplacementDP(n - 1, dp=dp), ) return dp[n] def integerReplacementBitwise(self, n): count = 0 while n != 1: if n & 1 == 0: n >>= 1 elif n == 3 or bin(n + 1).count("1") > bin(n - 1).count("1"): n -= 1 else: n += 1 count += 1 return count
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF NONE IF VAR NONE ASSIGN VAR DICT IF VAR NUMBER RETURN NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1
class Solution: def integerReplacement(self, n): table = {} def helper(i): if i == 1: return 0 if i in table: return table[i] if i % 2 == 0: return helper(i // 2) + 1 table[i] = min(helper(i + 1), helper(i - 1)) + 1 return table[i] return helper(n)
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR RETURN FUNC_CALL VAR VAR
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number of replacements needed for n to become 1? Example 1: Input: 8 Output: 3 Explanation: 8 -> 4 -> 2 -> 1 Example 2: Input: 7 Output: 4 Explanation: 7 -> 8 -> 4 -> 2 -> 1 or 7 -> 6 -> 3 -> 2 -> 1
class Solution: def integerReplacement(self, n): steps = 0 while n > 1: if n & 1 == 0: n >>= 1 steps += 1 else: if n == 3: n -= 1 else: n += 1 if n & 2 else -1 n >>= 1 steps += 2 return steps
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the new office he will have not a single bookshelf, but exactly $k$ bookshelves. He decided that the beauty of the $k$ shelves is the bitwise AND of the values of all the shelves. He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $k$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty. -----Input----- The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office. The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 < a_i < 2^{50}$) — the prices of the books in the order they stand on the old shelf. -----Output----- Print the maximum possible beauty of $k$ shelves in the new office. -----Examples----- Input 10 4 9 14 28 1 7 13 15 29 2 31 Output 24 Input 7 3 3 14 15 92 65 35 89 Output 64 -----Note----- In the first example you can split the books as follows: $$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$ In the second example you can split the books as follows: $$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$
import sys 3.7 n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] cur = 0 def is_submask(n, mask): return n & mask == mask def f(mask): s = [[(False) for j in range(n)] for i in range(n)] for l in range(n): cur = 0 for r in range(l, n): cur += a[r] s[l][r] = is_submask(cur, mask) dp = [[(False) for j in range(n)] for i in range(k)] dp[0] = s[0][:] for k1 in range(1, k): for r in range(n): for l in range(1, r + 1): dp[k1][r] |= dp[k1 - 1][l - 1] & s[l][r] return dp[k - 1][n - 1] cur = 0 for i in range(56, -1, -1): if f(cur + 2**i): cur += 2**i print(cur)
IMPORT EXPR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the new office he will have not a single bookshelf, but exactly $k$ bookshelves. He decided that the beauty of the $k$ shelves is the bitwise AND of the values of all the shelves. He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $k$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty. -----Input----- The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office. The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 < a_i < 2^{50}$) — the prices of the books in the order they stand on the old shelf. -----Output----- Print the maximum possible beauty of $k$ shelves in the new office. -----Examples----- Input 10 4 9 14 28 1 7 13 15 29 2 31 Output 24 Input 7 3 3 14 15 92 65 35 89 Output 64 -----Note----- In the first example you can split the books as follows: $$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$ In the second example you can split the books as follows: $$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$
n, k = map(int, input().split()) a = list(map(int, input().split())) a_sum = [0] for i in range(n): a_sum.append(a_sum[-1] + a[i]) a = [0] + a def get(i, j): assert 0 <= i <= j <= n if i > 0: return a_sum[j] - a_sum[i - 1] else: return a_sum[j] ans = 0 nowmax = 0 for bit in range(60, -1, -1): tmpmax = nowmax + (1 << bit) dp = [([0] * (n + 10)) for i in range(n + 10)] dp[0][0] = tmpmax for pos in range(1, n + 1): for div in range(1, k + 1): for l in range(1, pos + 1): dp[pos][div] = max( dp[pos][div], dp[pos - l][div - 1] & get(pos - l + 1, pos) & tmpmax ) if dp[n][k] == tmpmax: nowmax += 1 << bit print(nowmax)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF NUMBER VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the new office he will have not a single bookshelf, but exactly $k$ bookshelves. He decided that the beauty of the $k$ shelves is the bitwise AND of the values of all the shelves. He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $k$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty. -----Input----- The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office. The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 < a_i < 2^{50}$) — the prices of the books in the order they stand on the old shelf. -----Output----- Print the maximum possible beauty of $k$ shelves in the new office. -----Examples----- Input 10 4 9 14 28 1 7 13 15 29 2 31 Output 24 Input 7 3 3 14 15 92 65 35 89 Output 64 -----Note----- In the first example you can split the books as follows: $$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$ In the second example you can split the books as follows: $$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$
[n, k] = map(int, input().strip().split()) ais = list(map(int, input().strip().split())) iais = [(0) for _ in range(n + 1)] for i in range(n): iais[i + 1] = iais[i] + ais[i] def calc(k, split): res = 0 for i in range(k): res &= iais[split[i + 1]] - iais[split[i]] return res def check_mask(mask): dp = [[(False) for j in range(n + 1)] for i in range(k + 1)] for j in range(1, n - k + 1 + 1): dp[1][j] = iais[j] & mask == mask if not any(dp[1]): return False for i in range(2, k + 1): for j in range(i, n - (k - i) + 1): dp[i][j] = any( dp[i - 1][r] and iais[j] - iais[r] & mask == mask for r in range(i - 1, j - 1 + 1) ) if not any(dp[i]): return False return dp[k][n] mask = 0 for i in range(55, -1, -1): if check_mask(mask | 1 << i): mask |= 1 << i print(mask)
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the new office he will have not a single bookshelf, but exactly $k$ bookshelves. He decided that the beauty of the $k$ shelves is the bitwise AND of the values of all the shelves. He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $k$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty. -----Input----- The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office. The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 < a_i < 2^{50}$) — the prices of the books in the order they stand on the old shelf. -----Output----- Print the maximum possible beauty of $k$ shelves in the new office. -----Examples----- Input 10 4 9 14 28 1 7 13 15 29 2 31 Output 24 Input 7 3 3 14 15 92 65 35 89 Output 64 -----Note----- In the first example you can split the books as follows: $$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$ In the second example you can split the books as follows: $$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$
[n, k] = [int(x) for x in input().split()] sum = [int(x) for x in input().split()] for i in range(1, n): sum[i] += sum[i - 1] def check(mask, all): dp = [[(False) for j in range(n)] for i in range(k)] for i in range(n): dp[0][i] = sum[i] & all & mask == mask for i in range(1, k): for j in range(n): dp[i][j] = any( dp[i - 1][p] and sum[j] - sum[p] & all & mask == mask for p in range(0, j) ) return dp[k - 1][n - 1] ans = 0 for i in range(60, -1, -1): if check(ans | 1 << i, ~((1 << i) - 1)): ans |= 1 << i print(ans)
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR RETURN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 10^18. -----Input----- The first line contains two space-separated integers, m and k (0 ≤ m ≤ 10^18; 1 ≤ k ≤ 64). -----Output----- Print the required number n (1 ≤ n ≤ 10^18). If there are multiple answers, print any of them. -----Examples----- Input 1 1 Output 1 Input 3 2 Output 5
N = 70 C = [[(0) for _ in range(N)] for _ in range(N)] for i in range(N): C[i][0] = C[i][i] = 1 for j in range(1, i): C[i][j] = C[i - 1][j - 1] + C[i - 1][j] l, r = 1, int(1e19) m, k = [int(x) for x in input().split(" ")] k -= 1 def ok(x: int): s = bin(x)[2:] s = s[::-1] t = k ans = 0 for i in range(len(s) - 1, -1, -1): if s[i] == "1": ans += C[i][t] t -= 1 if t < 0: break return ans >= m while l < r: mid = l + r >> 1 if ok(mid): r = mid else: l = mid + 1 print(l)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR VAR 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
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 10^18. -----Input----- The first line contains two space-separated integers, m and k (0 ≤ m ≤ 10^18; 1 ≤ k ≤ 64). -----Output----- Print the required number n (1 ≤ n ≤ 10^18). If there are multiple answers, print any of them. -----Examples----- Input 1 1 Output 1 Input 3 2 Output 5
comb = [[(0) for i in range(67)] for j in range(67)] for i in range(67): comb[i][0], comb[i][i] = 1, 1 for j in range(1, i): comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j] def calc(x): cnt = 0 digit = [] while x > 0: digit.append(x % 2) x //= 2 cnt += 1 ans, one = 0, 0 for i in reversed(list(range(cnt))): if digit[i] == 1: if k - one >= 0: ans += comb[i][k - one] one += 1 return ans m, k = list(map(int, input().split())) lcur, rcur = 0, 2**64 while lcur + 2 <= rcur: mid = (lcur + rcur) // 2 if calc(mid * 2) - calc(mid) < m: lcur = mid else: rcur = mid print(rcur)
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 10^18. -----Input----- The first line contains two space-separated integers, m and k (0 ≤ m ≤ 10^18; 1 ≤ k ≤ 64). -----Output----- Print the required number n (1 ≤ n ≤ 10^18). If there are multiple answers, print any of them. -----Examples----- Input 1 1 Output 1 Input 3 2 Output 5
MX_BIT = 64 C = [[int(0) for i in range(MX_BIT)] for j in range(MX_BIT)] def ck(x, i): return x >> i & 1 def tot_bits(x): x = bin(x)[2:] return len(x) def mkt(): C[0][0] = 1 for i in range(1, MX_BIT): for j in range(i + 1): C[i][j] = C[i - 1][j] + (C[i - 1][j - 1] if j else 0) def solve(x, k): a = 0 for i in reversed(range(MX_BIT)): if ck(x, i) != 0: a += C[i][k] k -= 1 if k == 0: break return a mkt() m, k = list(input().split()) m = int(m) k = int(k) l = 1 r = 1e18 if not m: l = 1 else: while l < r: mid = int((l + r) // 2) if solve(2 * mid, k) - solve(mid, k) < m: l = mid + 1 else: r = mid print(l)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 10^18. -----Input----- The first line contains two space-separated integers, m and k (0 ≤ m ≤ 10^18; 1 ≤ k ≤ 64). -----Output----- Print the required number n (1 ≤ n ≤ 10^18). If there are multiple answers, print any of them. -----Examples----- Input 1 1 Output 1 Input 3 2 Output 5
import sys def b(n): c = 0 while n: if n & 1: c += 1 n //= 2 return c c = {} def f(n, k): if (n, k) in c.keys(): return c[n, k] if n == 1: return 1 if k == 1 else 0 c[n, k] = f(n // 2, k) + f(n // 2, k - 1) + int(n & 1 and b(n // 2) == k - 1) return c[n, k] m, k = map(int, input().split()) hi = int(1e18) lo = 1 while hi - lo >= 0: mid = (lo + hi) // 2 val = f(mid, k) if val == m: print(mid) sys.exit() elif val < m: lo = mid + 1 else: hi = mid - 1
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR FUNC_CALL VAR RETURN VAR VAR VAR IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 10^18. -----Input----- The first line contains two space-separated integers, m and k (0 ≤ m ≤ 10^18; 1 ≤ k ≤ 64). -----Output----- Print the required number n (1 ≤ n ≤ 10^18). If there are multiple answers, print any of them. -----Examples----- Input 1 1 Output 1 Input 3 2 Output 5
def dfs(n, k, cache={}): if k > n or k < 0: return 0 if k == 0 or k == n: return 1 if (n, k) in cache: return cache[n, k] z = cache[n, k] = dfs(n - 1, k - 1) + dfs(n - 1, k) return z def bits(n): b = 0 while n: if n & 1: b += 1 n >>= 1 return b def count(n, k): z, b, c = 0, 63, 0 for b in reversed(range(64)): if n >> b & 1: z += dfs(b, k - c) c += 1 if not k: break return z + (bits(n) == k) def solve(m, k): low, high = 1, 10**18 while low < high: mid = (low + high) // 2 if count(2 * mid, k) - count(mid, k) < m: low = mid + 1 else: high = mid return high m, k = [int(x) for x in input().split()] print(solve(m, k))
FUNC_DEF DICT IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys MAX = 10**9 def main(): n, m = readIntArr() arrs = [] for _ in range(n): arrs.append(readIntArr()) def checkPossible(minB): binRepresentations = set() for arr in arrs: binRepresentations.add(convertToBinary(arr, minB)) binList = list(binRepresentations) ii = jj = -1 n = len(binList) for i in range(n): for j in range(i, n): if binList[i] | binList[j] == (1 << m) - 1: ii = binList[i] jj = binList[j] if ii != -1: ansi = ansj = -1 for i in range(len(arrs)): b = convertToBinary(arrs[i], minB) if b == ii: ansi = i if b == jj: ansj = i return ansi, ansj else: return None def convertToBinary(arr, minB): b = 0 for i in range(m): if arr[i] >= minB: b |= 1 << i return b minB = -1 i = j = -1 b = MAX while b > 0: temp = checkPossible(minB + b) if temp == None: b //= 2 else: minB += b i, j = temp i += 1 j += 1 print("{} {}".format(i, j)) return input = sys.stdin.buffer.readline def oneLineArrayPrint(arr): print(" ".join([str(x) for x in arr])) def multiLineArrayPrint(arr): print("\n".join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print("\n".join([" ".join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] def makeArr(*args): assert ( len(args) >= 2 ), "makeArr args should be (default value, dimension 1, dimension 2,..." if len(args) == 2: return [args[0] for _ in range(args[1])] else: return [makeArr(args[0], *args[2:]) for _ in range(args[1])] def queryInteractive(x, y): print("? {} {}".format(x, y)) sys.stdout.flush() return int(input()) def answerInteractive(ans): print("! {}".format(ans)) sys.stdout.flush() inf = float("inf") MOD = 10**9 + 7 for _abc in range(1): main()
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NONE VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR RETURN ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_CALL VAR VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys input = sys.stdin.readline max_val = 0 n, m = [int(item) for item in input().split()] array = [] for i in range(n): line = [int(item) for item in input().split()] array.append(line) max_val = max(max_val, max(line)) good = (1 << m) - 1 l = 0 r = max_val + 1 a = 0 b = 0 while r - l > 1: mid = (l + r) // 2 bit_array = dict() for k, line in enumerate(array): val = 0 for i, item in enumerate(line): if item >= mid: val |= 1 << i bit_array[val] = k ok = False for key1 in bit_array.keys(): for key2 in bit_array.keys(): if key1 | key2 == good: ok = True i = bit_array[key1] j = bit_array[key2] break if ok: a = i b = j l = mid else: r = mid print(a + 1, b + 1)
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys INF = 10**10 def main(): n, m = get_list() mat = [get_list() for _ in range(n)] def fn(x): st = [-1] * (1 << m) st[0] = 0 for index, li in enumerate(mat): no = 0 for i, ele in enumerate(li): if ele >= x: no |= 1 << i li = [0] k = 2**m - 1 - no if st[k] > -1: return True, st[k], index b = 0 b = b - no & no while b != 0: st[b] = index b = b - no & no continue return False, -1, -1 x = 0 base = 10**8 while base > 0: while fn(x + base)[0]: x += base base //= 2 res, a, b = fn(x) print(a + 1, b + 1) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ out = [] get_int = lambda: int(input()) get_list = lambda: list(map(int, input().split())) main()
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR IF VAR VAR NUMBER RETURN NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST 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
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys reader = (s.rstrip() for s in sys.stdin) inp = reader.__next__ n, m = map(int, inp().split()) arr = tuple(tuple(map(int, inp().split())) for i in range(n)) lower_bound = 0 upper_bound = int(1000000000.0) + 1 mask = (1 << m) - 1 ans = 0, 0 def can_upper(mid): global ans d = dict() for i in range(n): bit = 0 for j in range(m): if arr[i][j] >= mid: bit += 1 << j d[bit] = i keys = tuple(d.keys()) for i in range(len(keys)): a1 = keys[i] for j in range(i, len(keys)): a2 = keys[j] if a1 | a2 == mask: ans = d[a1], d[a2] return True return False while upper_bound - lower_bound > 1: middle = upper_bound + lower_bound >> 1 if can_upper(middle): lower_bound = middle else: upper_bound = middle print(ans[0] + 1, ans[1] + 1)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ m, n = [int(ele) for ele in input().split()] a = [] for i in range(m): a.append(list(map(int, input().split()))) ina, mo = 0, 10**9 + 1 pos1, pos2 = 0, 0 mask = (1 << n) - 1 def check(tang): key = set() dic = dict() for i in range(m): temp = 0 for j in range(n): if a[i][j] >= tang: temp += 1 << j if temp in key: continue key.add(temp) tempk = temp while tempk >= 0: tempk &= temp dic[tempk] = i tempk -= 1 tocheck = mask ^ temp if tocheck in dic: return dic[tocheck], i, True return -1, -1, False while ina < mo - 1: tang = (ina + mo) // 2 temppos1, temppos2, status = check(tang) if status: pos1, pos2 = temppos1, temppos2 ina = tang else: mo = tang print(pos1 + 1, pos2 + 1)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR VAR VAR NUMBER RETURN NUMBER NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
from sys import stdin def solve(x: int) -> bool: global ans dp = {} for i in range(n): temp = 0 for j in range(m): if a[i][j] >= x: temp = temp | 1 << j dp[temp] = i for aa, bb in dp.items(): for cc, dd in dp.items(): if aa | cc == 2**m - 1: ans = bb + 1, dd + 1 return True return False ans = -1, -1 n, m = map(int, stdin.readline().split()) a = [] for i in range(n): a.append(list(map(int, stdin.readline().split()))) l, r = 0, 10**9 while l <= r: mid = (l + r) // 2 if solve(mid): l = mid + 1 else: r = mid - 1 print(*ans)
FUNC_DEF VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys readline = sys.stdin.readline def popcount(i): assert 0 <= i < 4294967296 i = i - (i >> 1 & 1431655765) i = (i & 858993459) + (i >> 2 & 858993459) return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24 N, M = map(int, readline().split()) Ar = [tuple(map(int, readline().split())) for _ in range(N)] pc = [popcount(i) for i in range(1 << M + 1)] inf = 1 << 31 maxi = [0] * (1 << M) for i in range(N): a = Ar[i] dp = [0] * (1 << M) for S in range(1, 1 << M): p = pc[S] if p == 1: k = S.bit_length() - 1 dp[S] = a[k] else: dp[S] = min(dp[-S & S], dp[S ^ -S & S]) maxi[S] = max(maxi[S], dp[S]) for i in range(M): for j in range(1 << M): if not j & 1 << i: maxi[j] = max(maxi[j], maxi[j | 1 << i]) D = (1 << M) - 1 ans = maxi[D] aS, bS = D, D for S in range(1 << M): candi = min(maxi[S], maxi[D ^ S]) if candi > ans: aS, bS = S, D ^ S ans = candi Ans = [None] * 2 pre = False fro = False for i in range(N): a = Ar[i] resa = inf resb = inf for j in range(M): if 1 << j & aS: resa = min(resa, a[j]) else: resb = min(resb, a[j]) if resa >= ans: pre = True Ans[0] = i + 1 if resb >= ans: fro = True Ans[1] = i + 1 if pre and fro: break print(*Ans)
IMPORT ASSIGN VAR VAR FUNC_DEF NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys input = sys.stdin.readline n, m = map(int, input().split()) mask = (1 << m) - 1 l = [] for i in range(n): l.append(list(map(int, input().split()))) lo = -1 hi = 10**9 + 1 while hi - lo > 1: test = (hi + lo) // 2 things = dict() for i in range(n): curr = 0 for v in l[i]: curr *= 2 if v >= test: curr += 1 things[curr] = i works = False for v1 in things: for v2 in things: if v1 | v2 == mask: outi = things[v1] outj = things[v2] works = True break if works: break if works: lo = test else: hi = test print(outi + 1, outj + 1)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ n, m = map(int, input().split()) a = [] for i in range(n): ai = list(map(int, input().split())) a.append(ai) def check(mid): mask = (1 << m) - 1 s = set() d = dict() for i in range(n): state = 0 for j in range(m): if a[i][j] >= mid: state += 1 << j if state in s: continue s.add(state) k = state while k >= 0: k &= state d[k] = i k -= 1 need = mask ^ state if need in d: q1, q2 = d[need], i if q1 > q2: q1, q2 = q2, q1 return True, (q1, q2) return False, (-1, -1) left = 0 right = 10**9 + 1 i, j = 0, 0 while right - left > 1: mid = (right + left) // 2 flag, (q1, q2) = check(mid) if flag: left = mid i, j = q1, q2 else: right = mid print(i + 1, j + 1)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR RETURN NUMBER VAR VAR RETURN NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
def main(): N, M = map(int, input().split()) L = [tuple(map(int, input().split())) for _ in range(N)] maxi = max(max(t) for t in L) + 1 mini, res = max((min(t), i) for i, t in enumerate(L)) res = res, res BITMASK = 1 << M while True: mid = (maxi + mini) // 2 if mid == mini: break masks = [None] * BITMASK for i, t in enumerate(L): tmask = 0 for v in t: tmask *= 2 if v >= mid: tmask += 1 if masks[tmask] is not None: continue masks[tmask] = i for k in range(BITMASK): if masks[k] is not None and k | tmask == BITMASK - 1: res = masks[k], i mini = mid = min(max(a, b) for a, b in zip(L[res[0]], L[res[1]])) break else: continue break else: maxi = mid print(res[0] + 1, res[1] + 1) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR NONE ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
n, m = [int(i) for i in input().split(" ")] arrmv = [] for i in range(n): arrmv.append([int(i) for i in input().split(" ")]) x = 0 y = int(1000000000.0 + 1) sucls = [0, 0] tols = [] mstr = "" powls = [int(pow(2, i)) for i in range(10)] twodarray = [(0) for i in range(257)] while x + 1 < y: mid = x + (y - x) // 2 for idx, ele in enumerate(twodarray): twodarray[idx] = 0 tols.clear() for topidx, eletop in enumerate(arrmv): tmp = 0 for idx, ele in enumerate(eletop): if ele >= mid: tmp += powls[idx] if not twodarray[tmp]: twodarray[tmp] = 1 tols.append((tmp, topidx)) sz = len(tols) suc = 0 no = int(pow(2, m)) for i in range(sz): for j in range(i, sz): if tols[i][0] | tols[j][0] == no - 1: sucls[0], sucls[1] = tols[i][1], tols[j][1] suc = 1 break if suc: break if suc: x = mid else: y = mid print(sucls[0] + 1, sucls[1] + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys inp = sys.stdin.readline input = lambda: inp().strip() flush = sys.stdout.flush def iin(): return int(input()) def lin(): return list(map(int, input().split())) def main(): n, m = lin() a = [lin() for i in range(n)] sl = 2**m - 1 l, r = 0, 10**9 sol = [1, 1] sol1 = 0 while l < r: md = l + r + 1 >> 1 ans1 = 0 done = 1 a2 = [0] * (sl + 1) for i in range(n): ch = 0 for j in range(m): ch = (ch << 1) + (a[i][j] >= md) a2[ch] = i + 1 for i in range(sl + 1): if done: if a2[i]: for j in range(i + 1): if a2[j] and i | j == sl: done = 0 ans1 = [a2[i], a2[j]] else: break if ans1: if sol1 < md: sol1 = md sol = ans1 l = md else: r = md - 1 print(sol[0], sol[1]) main()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR IF VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys input = sys.stdin.readline n, m = map(int, input().split()) l = [] for i in range(n): l.append([int(i) for i in input().split()]) left = 0 right = 10**9 + 1 while left < right: mid = (left + right) // 2 dicta = {} for i in range(n): mask = 0 for j in range(m): mask <<= 1 if l[i][j] >= mid: mask += 1 dicta[mask] = i ok = False for i in dicta: for j in dicta: if i | j == 2**m - 1: ok = True ans = dicta[i] + 1, dicta[j] + 1 break if ok == True: break if ok == True: left = mid + 1 else: right = mid print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
n, m = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] def get_ans(x): lim = 1 << m match = lim - 1 track = [(-1) for i in range(lim)] for i in range(n): mask = 0 for j in range(m): if a[i][j] >= x: mask |= 1 << j track[mask] = i for i in range(lim): for j in range(lim): if i | j == match and track[i] != -1 and track[j] != -1: return track[i], track[j] return -1, -1 lo = 0 hi = 1000000000 while lo < hi - 1: mid = (lo + hi) / 2 i, j = get_ans(mid) if i == -1: hi = mid - 1 else: lo = mid i, j = get_ans(hi) if i != -1: print("{} {}".format(i + 1, j + 1)) else: i, j = get_ans(lo) print("{} {}".format(i + 1, j + 1))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER RETURN VAR VAR VAR VAR RETURN NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = [] def bs(a, mid, ans): global n, m can = [(0) for i in range(1 << m)] for i in range(n): t = 0 for j in range(m): t = t << 1 | (a[i][j] >= mid) can[t] = i + 1 for i in range(1 << m): if not can[i]: continue for j in range(1 << m): if not can[j]: continue if i | j == (1 << m) - 1: ans[0] = can[i] ans[1] = can[j] return 1 return 0 for i in range(n): p = [int(x) for x in input().split()] a.append(p) l = 0 r = 100000000000 ans = [1, 1] while l <= r: mid = (l + r) // 2 if bs(a, mid, ans): l = mid + 1 else: r = mid - 1 print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
n, m = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] ans = [] def check(mid: int) -> bool: global ans dic = {} for i in range(n): bit = 0 for j in range(m): if a[i][j] >= mid: bit += 1 bit <<= 1 dic[bit >> 1] = i for x, idx in dic.items(): for y, idy in dic.items(): if x | y == 2**m - 1: ans = idx + 1, idy + 1 return True return False le = 0 ri = int(1000000000.0) while le <= ri: mid = le + ri >> 1 if check(mid): le = mid + 1 else: ri = mid - 1 print(ans[0], ans[1])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
hell = 1000000007 id1 = 0 id2 = 0 a = [] def check(n, m, x): global id1, id2 b = [0] * (1 << m) idx = [0] * (1 << m) for i in range(n): mask = 0 for j in range(m): if a[i][j] >= x: mask = mask ^ 1 << j b[mask] = 1 idx[mask] = i + 1 for i in range(1 << m): if b[i]: for j in range(1 << m): if b[j]: mask = i | j if mask == (1 << m) - 1: id1 = idx[i] id2 = idx[j] return 1 return 0 def meowmeow321(): n, m = map(int, input().split()) for i in range(n): dog = [int(x) for x in input().split()] a.append(dog) lo = 0 hi = hell while hi - lo > 0: mid = (hi + lo + 1) // 2 if check(n, m, mid): lo = mid else: hi = mid - 1 check(n, m, lo) print(id1, id2) t = 1 for xxx in range(t): meowmeow321()
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
from sys import stdin, stdout idx1 = 0 idx2 = 0 VALD = 0 def getminmax(n, m, a): l = 0 h = 1000000009 while l < h: mid = (l + h + 1) // 2 exists = existsequalorbig(mid, m, a) if exists: l = mid else: h = mid - 1 def existsequalorbig(mid, m, a): global idx1 global idx2 global VALD abw = [] hs = set() for i in range(len(a)): v = 0 for j in range(m): if a[i][j] >= mid: v |= 1 v <<= 1 v >>= 1 if v not in hs: hs.add(v) abw.append([i, v]) for i in range(len(abw)): for j in range(i, len(abw)): if abw[i][1] | abw[j][1] == VALD: idx1 = abw[i][0] idx2 = abw[j][0] return True return False nm = list(map(int, stdin.readline().split())) n = nm[0] m = nm[1] VALD = int(pow(2, m) - 1) a = [] for i in range(n): a.append(list(map(int, stdin.readline().split()))) getminmax(n, m, a) stdout.write(str(idx1 + 1) + " " + str(idx2 + 1))
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
def check(mid, n, m, arr): masks = {} for index in range(n): array = arr[index] x = 0 for i in range(m): if array[i] >= mid: x ^= 1 << i masks[x] = index + 1 ans = False a, b = 1, 1 if (1 << m) - 1 in masks.keys(): return True, (masks[(1 << m) - 1], masks[(1 << m) - 1]) for i in masks.keys(): for j in masks.keys(): orAns = i | j if orAns == (1 << m) - 1: if i == (1 << m) - 1 and i in masks.keys(): a = masks[i] ans = True break elif j == (1 << m) - 1 and j in masks.keys(): b = masks[j] ans = True break elif i in masks.keys() and j in masks.keys(): ans = True a, b = masks[i], masks[j] break return ans, (a, b) def solve(n, m, arr): mini = 0 maxi = int(1000000000.0) + 5 i, j = 1, 1 while mini <= maxi: mid = (mini + maxi) // 2 ans, res = check(mid, n, m, arr) if ans: i, j = res mini = mid + 1 else: maxi = mid - 1 print(i, j) def main(): n, m = map(int, input().split(" ")) arr = [] for _ in range(n): x = list(map(int, input().split(" "))) arr.append(x) solve(n, m, arr) main()
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR RETURN NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys reader = (map(int, line.split()) for line in sys.stdin) input = reader.__next__ n, m = input() arrays = [] for i in range(n): arrays.append(list(input())) full = (1 << m) - 1 L = -1 R = 10**9 + 1 while L + 1 < R: check = L + R >> 1 masks = {} for i, arr in enumerate(arrays): curr = 0 for val in arr: curr <<= 1 if val >= check: curr |= 1 masks[curr] = i isValid = False for k1 in masks: for k2 in masks: if k1 | k2 == full: ans0 = masks[k1] ans1 = masks[k2] isValid = True break if isValid: break if isValid: L = check else: R = check print(ans0 + 1, ans1 + 1)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) a = [] for _ in [0] * n: a.append(list(map(int, input().split()))) ok = 0 ng = 10**9 + 1 judge = pow(2, m) - 1 dg = 1000 while ng - ok > 1: mid = (ng + ok) // 2 tank = set() for i in range(n): r = 0 for j in range(m): r *= 2 if a[i][j] >= mid: r += 1 tank.add(r) for p in tank: for q in tank: if p | q == judge: ok = mid break if ok != mid: ng = mid tank = set() res = [] for i in range(n): r = 0 for j in range(m): r *= 2 if a[i][j] >= ok: r += 1 if not r in tank: res.append(i * dg + r) tank.add(r) for p in res: for q in res: if p % dg | q % dg == judge: print(p // dg + 1, q // dg + 1) return main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 def bisearch_max(mn, mx, func): ok = mn ng = mx while ok + 1 < ng: mid = (ok + ng) // 2 if func(mid): ok = mid else: ng = mid return ok def check(m): ok = [0] * N S = set() for i in range(N): for j in range(M): if A[i][j] >= m: ok[i] |= 1 << j S.add(ok[i]) full = (1 << M) - 1 for bit1 in range(1 << M): for bit2 in range(bit1, 1 << M): if bit1 in S and bit2 in S: if bit1 | bit2 == full: return True return False N, M = MAP() A = [None] * N for i in range(N): A[i] = LIST() res = bisearch_max(0, 10**9 + 1, check) ok = [0] * N S = set() D = {} for i in range(N): for j in range(M): if A[i][j] >= res: ok[i] |= 1 << j S.add(ok[i]) D[ok[i]] = i + 1 full = (1 << M) - 1 for bit1 in range(1 << M): for bit2 in range(bit1, 1 << M): if bit1 in S and bit2 in S: if bit1 | bit2 == full: print(D[bit1], D[bit2]) exit()
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys input = sys.stdin.readline N, M = map(int, input().split()) state = [list(map(int, input().split())) for _ in range(N)] Ans = {} l = -1 r = 10**9 + 1 while r - l > 1: m = (l + r) // 2 T = {} for j, S in enumerate(state): bit = 0 for i, s in enumerate(S): if s >= m: bit += 1 << i T[bit] = j ok = False for bit1 in range(1 << M): for bit2 in range(1 << M): if bit1 | bit2 == (1 << M) - 1 and bit1 in T and bit2 in T: ok = True Ans[m] = [T[bit1], T[bit2]] break if ok: break if ok: l = m else: r = m print(Ans[l][0] + 1, Ans[l][1] + 1)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST VAR VAR VAR VAR IF VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
def isPoss(n, arrs, nvals): masks = set() midx = {} for pos, arr in enumerate(arrs): mask = 0 for i in range(nvals): if arr[i] >= n: mask += 1 << i midx[mask] = pos + 1 masks.add(mask) for m1 in masks: for m2 in masks: if m1 | m2 == (1 << nvals) - 1: return midx[m1], midx[m2] return -1, -1 narr, nvals = map(int, input().split()) arrs = [] for i in range(narr): arrs.append(list(map(int, input().split()))) mn = -1 mx = 10**9 + 1 while mn < mx - 1: mid = (mn + mx) // 2 a, b = isPoss(mid, arrs, nvals) if a != -1: mn = mid else: mx = mid - 1 for i in range(1, -1, -1): a, b = isPoss(mn + i, arrs, nvals) if a != -1: print(a, b) break
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR VAR VAR VAR RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
import sys input = sys.stdin.buffer.readline def find_pair(candidate, data, m): ans = -1, -1 binary_bit = [(False) for i in range(1 << m)] for i in data: bit_tmp = 0 for j in range(len(i)): if i[j] >= candidate: bit_tmp |= 1 << j binary_bit[bit_tmp] = True for i in range(1 << m): for j in range(1 << m): if i | j == (1 << m) - 1 and binary_bit[i] and binary_bit[j]: ans = i, j break return ans def backtracking(candidate, ans, data): idx_i = -1 idx_j = -1 for i in range(len(data)): bit_tmp = 0 for j in range(len(data[i])): if data[i][j] >= candidate: bit_tmp |= 1 << j if bit_tmp == ans[0]: idx_i = i if bit_tmp == ans[1]: idx_j = i print(str(idx_i + 1) + " " + str(idx_j + 1)) def main(): n, m = [int(i) for i in input().split()] data = [[int(i) for i in input().split()] for i in range(n)] a = 0 b = 10**9 + 7 ans = -1, -1 candidate = -1 while a <= b: mid = (a + b) // 2 bin_ans = find_pair(mid, data, m) if bin_ans[0] != -1 and bin_ans[1] != -1: ans = bin_ans candidate = mid a = mid + 1 else: b = mid - 1 backtracking(candidate, ans, data) main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}. You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}). Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible. Input The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively. Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9). Output Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them. Example Input 6 5 5 0 3 1 2 1 8 9 1 3 1 2 3 4 5 9 1 0 3 7 2 3 0 6 3 6 4 1 7 0 Output 1 5
def check(x: int) -> (int, int): vis = {} for i, array in enumerate(a): t = 0 for j, val in enumerate(array): if val >= x: t |= 1 << j vis[t] = i if (1 << m) - 1 in vis: return vis[(1 << m) - 1], vis[(1 << m) - 1] for i in range(1, (1 << m) - 1): for j in range(1, (1 << m) - 1): if i in vis and j in vis and i | j == (1 << m) - 1: return vis[i], vis[j] return -1, -1 n, m = map(int, input().split()) a = [] for i in range(n): a.append(list(map(int, input().split()))) l = 0 r = int(1000000000.0) while l <= r: mid = l + r >> 1 if check(mid) != (-1, -1): l = mid + 1 else: r = mid - 1 ans = check(r) print("%d %d" % (ans[0] + 1, ans[1] + 1))
FUNC_DEF VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP NUMBER VAR NUMBER VAR RETURN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR VAR VAR VAR RETURN NUMBER NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
for _ in range(int(input())): n, k = map(int, input().split()) arr = list(map(int, input().split())) count = 0 for i in range(k): if 2**i not in arr: count += 1 print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
t = int(input()) for i in range(t): n, k = map(int, input().split()) count = 0 arr = [int(p) for p in input().split()] must_have_nos = {} for j in range(k): must_have_nos[2**j] = False for l in arr: if l in must_have_nos: must_have_nos[l] = True for m in must_have_nos: if not must_have_nos[m]: count += 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
def list_input(): return list(map(int, input().split())) def map_input(): return map(int, input().split()) def map_string(): return input().split() for _ in range(int(input())): n, k = map_input() a = list_input() s = set(a) b = [] for i in range(k): if 1 << i not in s: b.append(1 << i) print(len(b))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
for _ in range(int(input())): S = set() N, K = map(int, input().split()) Present = [0] * K Check = [(2**i) for i in range(K)] ARR = list(map(int, input().split())) for i in ARR: for j in range(K): if Check[j] == i: Present[j] = 1 count_zeros = 0 for i in Present: if i == 0: count_zeros += 1 print(count_zeros)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) nums = [int(i) for i in input().split()] ans = 0 mask = 1 << k - 1 while mask: if mask not in nums: ans += 1 mask = mask >> 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER WHILE VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
def is_power(a): if not a & a - 1: return True return False tc = int(input()) for i in range(0, tc): n, k = map(lambda x: int(x), input().split()) array = set(map(lambda x: int(x), input().split())) ans = sum([(1 if j != 0 and is_power(j) else 0) for j in array]) ans = 0 if ans >= k else k - ans print(ans)
FUNC_DEF IF BIN_OP VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
t = int(input()) for i in range(t): n, k = map(int, input().split()) arr = list(map(int, input().split())) s = set(arr) c = 0 arr = list(set(arr)) for j in range(k + 1): x = 2**j if x in arr: c += 1 print(k - c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
powers = [(2**i) for i in range(20)] t = int(input()) for _ in range(t): n, k = map(int, input().split()) ints = set(list(map(int, input().split()))) count = 0 for i in ints: if i in powers: count += 1 print(k - count)
ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) l = list(map(int, input().split())) s = [] for i in range(n): if l[i] > 0: if l[i] & l[i] - 1 == 0: s.append(l[i]) s = set(s) print(k - len(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
ck = lambda: map(int, input().split()) for _ in range(int(input())): n, k = ck() a = list(set(ck())) c = 0 for i in range(k): if 1 << i not in a: c += 1 print(c)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
t = input() t = int(t) ans = [] for i in range(t): y = 0 a = list(map(int, input().split(" "))) n = a[0] k = a[1] a = list(map(int, input().split(" "))) for i in range(k): if 2**i not in a: y = y + 1 ans.append(y) for i in ans: print(i)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
for i in range(int(input())): d, k = map(int, input().split()) n = map(int, input().split()) n = list(n) add = 0 j = 0 while j < k: tk = 2**j ll = 0 pp = 0 while ll < d: if n[ll] == tk: pp = 1 break ll += 1 if pp == 0: add += 1 j += 1 print(add)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
t = int(input()) ans = [] for i in range(t): n, k = list(map(int, input().split())) numbers = list(map(int, input().split())) present = [(False) for j in range(k)] for number in numbers: binary = bin(number) idx = 0 if number != 0 and number & number - 1 == 0: present[len(binary) - 2 - 1] = True count = 0 for cond in present: if cond == False: count += 1 if count == 0: ans.append(0) else: ans.append(count) for x in ans: print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
def ip(): return int(input()) def ipp(): return map(int, input().split()) def sar(): return list(ipp()) def pars(a): print(" ".join(list(map(str, a)))) print("\r") def parl(a): print("\r".join(list(map(str, a)))) print("\r") T = 1 T = int(input().strip()) for _ in range(T): n, k = ipp() a = [] a = sar() b = [] for i in a: if i > 0 and i & i - 1 == 0: b.append(i) d = set(b) print(k - len(d))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
import sys def solve(x, k): x = set(x) for i in range(k): if 1 << i in x: k -= 1 return k f = sys.stdin t = int(f.readline()) for i in range(t): n, k = map(int, f.readline().split()) x = list(map(int, f.readline().split())) print(solve(x, k))
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
for _ in range(int(input())): [n, k] = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a = list(set(a)) di = {} for i in a: di[i] = 1 j = 1 t = 1 << k ans = 0 while j < t: try: l = di[j] except: ans += 1 j <<= 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then. The code given by Bhuvan is the following which runs given an array of N integers and another integer K : void recurse ( array a, int n ) { // n = size of array define array b currently empty consider all 2^{n} subsets of a[] { x = bitwise OR of elements in the subsets add x into "b" if it is not present yet } if (sizeof( b ) == 1 < k) { printf(“Won”); return; } recurse ( b, sizeof( b ) ); } Chef Tobby tried to run an experiment with only one integer in the array with value 2 and K = 3. To his horror, he found out that the algorithm is resulting in an infinite loop. He is livid with the possibility that the algorithm can lead to infinite loops for certain cases. On closer inspection he determines that it might be possible to insert additional elements in the initial array to subvert the problem. Since time is very less, Chef Tobby would like to insert the minimum number of elements. Chef Tobby has to finish writing the paper, so he asks his graduate student Leamas to fix it. Leamas has no idea how to fix the problem so he asks you for help. ------ Input section ------ The first line contains T, the number of test cases. Each test case consists of 2 lines. The first line contains 2 integers N and K, denoting the number of elements in the array and parameter mentioned in problem statement. Next line contains N space separated integers, denoting the elements of the array. ------ Output section ------ Output the minimum number of elements that need to be inserted so that inifinite loop can be avoided. ------ Input constraints ------ 1 ≤ T ≤ 10 1 ≤ Sum of N over all test cases ≤ 10^{5} 1 ≤ K ≤ 20 0 ≤ A[i] ≤ 2^{K}-1, where A[i] denotes the i^{th} element of the array. ----- Sample Input 1 ------ 1 2 2 3 1 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ You can win the game by inserting the element 2 into the array. ----- Sample Input 2 ------ 1 7 3 3 7 5 4 6 2 1 ----- Sample Output 2 ------ 0 ----- explanation 2 ------ The initial array will result will terminate in the first step of algorithm only. Thus there is no need to insert any new element.
t = int(input()) for _ in range(t): a = input().split() n = int(a[0]) k = int(a[1]) a = input().split() a = [int(x) for x in a] c = 0 i = 1 p = pow(2, k) - 1 while i <= p: if i not in a: c += 1 i = i * 2 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \land denotes [bitwise AND]. Note that after this operation, the length of the array decreases by one. Formally, as long as |A| > 1 (where |A| denotes the current length of A), you can pick an index 1 ≤ i < |A| and transform A into [A_{1}, A_{2}, \ldots, A_{i-1}, A_{i} \land A_{i+1}, A_{i+2}, \ldots, A_{|A|}]. Find the minimum number of moves required to make all numbers in the resulting array equal. ------ Input Format ------ - The first line of input contains an integer T — the number of test cases you need to solve. - The first line of each test case contains one integer N, the size of the array. - The second line of each test case contains N space-separated integers A_{1}, \ldots, A_{N} — the elements of the array A. ------ Output Format ------ For each test case, output on a new line the minimum number of moves required to make all numbers equal. ------ Constraints ------ $1 ≤T ≤10^{6}$ $2 ≤N ≤10^{6}$ - Sum of $N$ over all test cases is at most $10^{6}$. $0 ≤A_{i} < 2^{30}$ ------ subtasks ------ Subtask 1 (20 points): $0 ≤A_{i} ≤255$ Sum of $N$ over all test cases is at most $255$. Subtask 2 (30 points): Sum of $N$ over all test cases is at most $2000$. Subtask 3 (50 points): Original constraints. ----- Sample Input 1 ------ 4 4 0 0 0 1 2 1 1 6 1 2 3 4 5 6 4 2 28 3 22 ----- Sample Output 1 ------ 1 0 4 3 ----- explanation 1 ------ Test case $1$: Choose $i = 3$ to make the array $[0, 0, 0 \land 1] = [0, 0, 0]$. Test case $2$: All elements of the array are already equal. Test case $3$: One possible sequence of moves is as follows: - Choose $i = 1$, making the array $[1\land 2, 3, 4, 5, 6] = [0, 3, 4, 5, 6]$ - Choose $i = 2$, making the array $[0, 0, 5, 6]$ - Choose $i = 3$, making the array $[0, 0, 4]$ - Choose $i = 2$, making the array $[0, 0]$ It can be verified that in this case, making every element equal using $3$ or fewer moves is impossible.
r = int(input()) while r != 0: r -= 1 n = int(input()) a = list(map(int, input().split())) x = (1 << 30) - 1 for i in a: x = x & i y = (1 << 30) - 1 c = 0 for i in a: y = y & i if y == x: c += 1 y = (1 << 30) - 1 print(n - c)
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \land denotes [bitwise AND]. Note that after this operation, the length of the array decreases by one. Formally, as long as |A| > 1 (where |A| denotes the current length of A), you can pick an index 1 ≤ i < |A| and transform A into [A_{1}, A_{2}, \ldots, A_{i-1}, A_{i} \land A_{i+1}, A_{i+2}, \ldots, A_{|A|}]. Find the minimum number of moves required to make all numbers in the resulting array equal. ------ Input Format ------ - The first line of input contains an integer T — the number of test cases you need to solve. - The first line of each test case contains one integer N, the size of the array. - The second line of each test case contains N space-separated integers A_{1}, \ldots, A_{N} — the elements of the array A. ------ Output Format ------ For each test case, output on a new line the minimum number of moves required to make all numbers equal. ------ Constraints ------ $1 ≤T ≤10^{6}$ $2 ≤N ≤10^{6}$ - Sum of $N$ over all test cases is at most $10^{6}$. $0 ≤A_{i} < 2^{30}$ ------ subtasks ------ Subtask 1 (20 points): $0 ≤A_{i} ≤255$ Sum of $N$ over all test cases is at most $255$. Subtask 2 (30 points): Sum of $N$ over all test cases is at most $2000$. Subtask 3 (50 points): Original constraints. ----- Sample Input 1 ------ 4 4 0 0 0 1 2 1 1 6 1 2 3 4 5 6 4 2 28 3 22 ----- Sample Output 1 ------ 1 0 4 3 ----- explanation 1 ------ Test case $1$: Choose $i = 3$ to make the array $[0, 0, 0 \land 1] = [0, 0, 0]$. Test case $2$: All elements of the array are already equal. Test case $3$: One possible sequence of moves is as follows: - Choose $i = 1$, making the array $[1\land 2, 3, 4, 5, 6] = [0, 3, 4, 5, 6]$ - Choose $i = 2$, making the array $[0, 0, 5, 6]$ - Choose $i = 3$, making the array $[0, 0, 4]$ - Choose $i = 2$, making the array $[0, 0]$ It can be verified that in this case, making every element equal using $3$ or fewer moves is impossible.
for i in range(int(input())): n = int(input()) arr = list(map(int, input().split())) x = arr[0] for j in range(1, n): x = x & arr[j] j = 0 c = 0 while j < n: y = arr[j] j += 1 if y == 0: continue while y != x and j < n: y = y & arr[j] j += 1 c += 1 if y != x: c += 1 print(c)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \land denotes [bitwise AND]. Note that after this operation, the length of the array decreases by one. Formally, as long as |A| > 1 (where |A| denotes the current length of A), you can pick an index 1 ≤ i < |A| and transform A into [A_{1}, A_{2}, \ldots, A_{i-1}, A_{i} \land A_{i+1}, A_{i+2}, \ldots, A_{|A|}]. Find the minimum number of moves required to make all numbers in the resulting array equal. ------ Input Format ------ - The first line of input contains an integer T — the number of test cases you need to solve. - The first line of each test case contains one integer N, the size of the array. - The second line of each test case contains N space-separated integers A_{1}, \ldots, A_{N} — the elements of the array A. ------ Output Format ------ For each test case, output on a new line the minimum number of moves required to make all numbers equal. ------ Constraints ------ $1 ≤T ≤10^{6}$ $2 ≤N ≤10^{6}$ - Sum of $N$ over all test cases is at most $10^{6}$. $0 ≤A_{i} < 2^{30}$ ------ subtasks ------ Subtask 1 (20 points): $0 ≤A_{i} ≤255$ Sum of $N$ over all test cases is at most $255$. Subtask 2 (30 points): Sum of $N$ over all test cases is at most $2000$. Subtask 3 (50 points): Original constraints. ----- Sample Input 1 ------ 4 4 0 0 0 1 2 1 1 6 1 2 3 4 5 6 4 2 28 3 22 ----- Sample Output 1 ------ 1 0 4 3 ----- explanation 1 ------ Test case $1$: Choose $i = 3$ to make the array $[0, 0, 0 \land 1] = [0, 0, 0]$. Test case $2$: All elements of the array are already equal. Test case $3$: One possible sequence of moves is as follows: - Choose $i = 1$, making the array $[1\land 2, 3, 4, 5, 6] = [0, 3, 4, 5, 6]$ - Choose $i = 2$, making the array $[0, 0, 5, 6]$ - Choose $i = 3$, making the array $[0, 0, 4]$ - Choose $i = 2$, making the array $[0, 0]$ It can be verified that in this case, making every element equal using $3$ or fewer moves is impossible.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) bit = a[0] for i in range(1, n): bit = bit & a[i] ans = 0 left = int("1" * 32, 2) for i in range(n): left = left & a[i] if left == bit: left = int("1" * 32, 2) else: ans += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \land denotes [bitwise AND]. Note that after this operation, the length of the array decreases by one. Formally, as long as |A| > 1 (where |A| denotes the current length of A), you can pick an index 1 ≤ i < |A| and transform A into [A_{1}, A_{2}, \ldots, A_{i-1}, A_{i} \land A_{i+1}, A_{i+2}, \ldots, A_{|A|}]. Find the minimum number of moves required to make all numbers in the resulting array equal. ------ Input Format ------ - The first line of input contains an integer T — the number of test cases you need to solve. - The first line of each test case contains one integer N, the size of the array. - The second line of each test case contains N space-separated integers A_{1}, \ldots, A_{N} — the elements of the array A. ------ Output Format ------ For each test case, output on a new line the minimum number of moves required to make all numbers equal. ------ Constraints ------ $1 ≤T ≤10^{6}$ $2 ≤N ≤10^{6}$ - Sum of $N$ over all test cases is at most $10^{6}$. $0 ≤A_{i} < 2^{30}$ ------ subtasks ------ Subtask 1 (20 points): $0 ≤A_{i} ≤255$ Sum of $N$ over all test cases is at most $255$. Subtask 2 (30 points): Sum of $N$ over all test cases is at most $2000$. Subtask 3 (50 points): Original constraints. ----- Sample Input 1 ------ 4 4 0 0 0 1 2 1 1 6 1 2 3 4 5 6 4 2 28 3 22 ----- Sample Output 1 ------ 1 0 4 3 ----- explanation 1 ------ Test case $1$: Choose $i = 3$ to make the array $[0, 0, 0 \land 1] = [0, 0, 0]$. Test case $2$: All elements of the array are already equal. Test case $3$: One possible sequence of moves is as follows: - Choose $i = 1$, making the array $[1\land 2, 3, 4, 5, 6] = [0, 3, 4, 5, 6]$ - Choose $i = 2$, making the array $[0, 0, 5, 6]$ - Choose $i = 3$, making the array $[0, 0, 4]$ - Choose $i = 2$, making the array $[0, 0]$ It can be verified that in this case, making every element equal using $3$ or fewer moves is impossible.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) t = l[0] for i in range(1, n): t &= l[i] g = 0 c = 2**30 - 1 for i in range(n): c &= l[i] if c == t: g += 1 c = 2**30 - 1 print(n - g)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \land denotes [bitwise AND]. Note that after this operation, the length of the array decreases by one. Formally, as long as |A| > 1 (where |A| denotes the current length of A), you can pick an index 1 ≤ i < |A| and transform A into [A_{1}, A_{2}, \ldots, A_{i-1}, A_{i} \land A_{i+1}, A_{i+2}, \ldots, A_{|A|}]. Find the minimum number of moves required to make all numbers in the resulting array equal. ------ Input Format ------ - The first line of input contains an integer T — the number of test cases you need to solve. - The first line of each test case contains one integer N, the size of the array. - The second line of each test case contains N space-separated integers A_{1}, \ldots, A_{N} — the elements of the array A. ------ Output Format ------ For each test case, output on a new line the minimum number of moves required to make all numbers equal. ------ Constraints ------ $1 ≤T ≤10^{6}$ $2 ≤N ≤10^{6}$ - Sum of $N$ over all test cases is at most $10^{6}$. $0 ≤A_{i} < 2^{30}$ ------ subtasks ------ Subtask 1 (20 points): $0 ≤A_{i} ≤255$ Sum of $N$ over all test cases is at most $255$. Subtask 2 (30 points): Sum of $N$ over all test cases is at most $2000$. Subtask 3 (50 points): Original constraints. ----- Sample Input 1 ------ 4 4 0 0 0 1 2 1 1 6 1 2 3 4 5 6 4 2 28 3 22 ----- Sample Output 1 ------ 1 0 4 3 ----- explanation 1 ------ Test case $1$: Choose $i = 3$ to make the array $[0, 0, 0 \land 1] = [0, 0, 0]$. Test case $2$: All elements of the array are already equal. Test case $3$: One possible sequence of moves is as follows: - Choose $i = 1$, making the array $[1\land 2, 3, 4, 5, 6] = [0, 3, 4, 5, 6]$ - Choose $i = 2$, making the array $[0, 0, 5, 6]$ - Choose $i = 3$, making the array $[0, 0, 4]$ - Choose $i = 2$, making the array $[0, 0]$ It can be verified that in this case, making every element equal using $3$ or fewer moves is impossible.
from sys import stdin def ii(): return int(stdin.readline()) def mi(): return map(int, stdin.readline().split()) def li(): return list(mi()) def si(): return stdin.readline() t = 1 t = ii() for _ in range(t): n = ii() l1 = li() ans = l1[0] for i in l1[1:]: ans &= i if l1.count(ans) == n: print(0) continue c1 = 0 curr = l1[0] for i in l1[1:]: if curr != ans: curr &= i c1 += 1 else: curr = i if curr != ans: c1 += 1 c2 = 0 l1 = l1[::-1] curr = l1[0] for i in l1[1:]: if curr != ans: curr &= i c2 += 1 else: curr = i if curr != ans: c2 += 1 print(min(c1, c2))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR