description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | n = int(input())
arr = list(map(int, input().split()))
def to_bin(n):
return bin(n).replace("0b", "")
for i in range(n):
arr[i] = to_bin(arr[i])
max_len = len(arr[0])
for i in arr:
temp_len = len(i)
if temp_len > max_len:
max_len = temp_len
for i in range(n):
arr[i] = "0" * (max_len - le... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIG... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def solve(group, bit):
if bit == t - 1:
for i in range(1, len(group)):
if group[i][bit] != group[0][bit]:
return 1
return 0
g0, g1 = [], []
for i in range(len(group)):
if int(group[i][bit]):
g1.append(group[i])
else:
g0.appe... | FUNC_DEF IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR ... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def get_bit(val, id):
return val >> id & 1
trie = []
def new_node():
trie.append([-1] * 2)
def add(val):
indx = 0
for i in range(30, -1, -1):
x = get_bit(val, i)
if trie[indx][x] == -1:
new_node()
trie[indx][x] = len(trie) - 1
indx = trie[indx][x]
... | FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | mx = 32
def f(a, pos):
if pos < 0 or len(a) == 0:
return 0
on = []
off = []
for x in a:
if x & 1 << pos:
on.append(x)
else:
off.append(x)
if len(on) == 0:
return f(off, pos - 1)
if len(off) == 0:
return f(on, pos - 1)
a.clear(... | ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VA... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | n = int(input())
seq = sorted(list(map(int, input().split())))
queue = [(0, n, 30, 0)]
best = 2**30
while queue:
l, r, b, v = queue.pop()
if b >= 0:
mask = 1 << b
if not mask & seq[l] and mask & seq[r - 1]:
for i in range(l, r):
if mask & seq[i]:
q... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR ... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | 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 ran... | 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 ... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def argmin(a):
if len(a[0]) == 0:
return "", 0
start_zeros = [item for item in a if item[0] == "0"]
start_ones = [item for item in a if item[0] == "1"]
if len(start_zeros) == 0:
a_ones, ans_ones = argmin([item[1:] for item in start_ones])
return "1" + a_ones, ans_ones
if len(... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER NUMBER RETURN STRING NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER STRING ASSIGN VAR VAR VAR VAR VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR RETURN BIN_OP STRING VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def dp(bit, arr, left, right):
if bit == -1:
return 0, 0
mask = 1 << bit
piv = None
for i in range(left, right):
if arr[i] & mask:
piv = i
break
if piv is None:
ans, msk = dp(bit - 1, arr, left, right)
return ans, msk + mask
if piv == left:... | FUNC_DEF IF VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR V... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | n = int(input())
a = list(map(int, input().split()))
def check(l, b):
if b == 0:
ans = int(not all(map(lambda x: x == l[0], l)))
return ans
l.sort()
u = 0
while u < len(l):
if l[u] & 1 << b:
break
u += 1
for i in range(len(l)):
l[i] &= (1 << b) -... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUM... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | DIG = 29
def build_xor_tree(a, n):
tree = [[-1, -1]]
for i in range(n):
cur = 0
for pos in range(DIG, -1, -1):
if a[i] & 1 << pos:
if tree[cur][1] == -1:
tree.append([-1, -1])
tree[cur][1] = len(tree) - 1
cur =... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NU... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def abc(x, i, l):
a = []
b = []
for j in l:
if x[j][i] == "1":
a.append(j)
else:
b.append(j)
if i == 30:
if a and b:
return "1"
return "0"
if a and b:
return "1" + min(abc(x, i + 1, a), abc(x, i + 1, b))
if a:
re... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR RETURN STRING RETURN STRING IF VAR VAR RETURN BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR RETURN BIN_OP... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def dfs(s, k):
if k < 0:
return 0
s1 = [i for i in s if i & ex2[k]]
s0 = [i for i in s if i & ex2[k] == 0]
if len(s1) == 0:
return dfs(s0, k - 1)
if len(s0) == 0:
return dfs(s1, k - 1)
return ex2[k] + min(dfs(s1, k - 1), dfs(s0, k - 1))
n = int(input())
s = list(map(int... | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR ... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | from sys import stdin
input = stdin.readline
n = int(input())
l = list(map(int, input().split()))
cyk = [1] * 50
for i in range(1, 50):
cyk[i] = cyk[i - 1] * 2
def wyn(lista):
m = max(lista)
if m == min(lista):
return 0
le = len(bin(m))
duze = []
male = []
pyk = cyk[le - 3]
fo... | ASSIGN 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 FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBE... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | import sys
input = sys.stdin.readline
def calc(arr, b):
if not arr or b < 0:
return 0
bit1, bit0 = [], []
for x in arr:
if x >> b & 1:
bit1.append(x)
else:
bit0.append(x)
if not bit1:
return calc(bit0, b - 1)
elif not bit0:
return ca... | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR ... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | n = int(input())
a = [int(x) for x in input().split(" ")]
a.sort()
b = pow(2, 30)
while b > 0 and a[n - 1] % b == a[n - 1]:
b /= 2
b = int(b)
if b == 0:
print(0)
exit(0)
def sol(nums, lo, hi, bit):
bit = int(bit)
if bit < 1:
return nums[lo] % 2, 0
if hi - lo == 0:
return nums[l... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER WHILE VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FU... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | n = int(input())
a = list(map(int, input().split()))
bit = []
for i in range(n):
s = bin(a[i])[2:]
if len(s) < 30:
s = "0" * (30 - len(s)) + s
bit.append(s)
def ans(p, j, an):
if j == 30:
return an
if len(p) == 1:
return an + "0" * (30 - j)
d1 = []
d0 = []
for i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF V... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def solve(a, b=32):
if b == -1:
return 0
a1 = []
a2 = []
n = len(a)
for i in range(n):
if a[i] // 2**b % 2 == 1:
a1.append(a[i])
else:
a2.append(a[i])
if len(a1) == 0:
return solve(a2, b - 1)
elif len(a2) == 0:
return solve(a1, ... | FUNC_DEF NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def q(s, b):
if not s or b < 0:
return 0
n, f = [], []
for i in s:
if i & 1 << b:
n += (i,)
else:
f += (i,)
if not n:
return q(f, b - 1)
if not f:
return q(n, b - 1)
return min(q(n, b - 1), q(f, b - 1)) + 2**b
input()
print(q([*ma... | FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR N... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def func(arr, bitmask):
if bitmask == 0:
return 0
arr_off = []
arr_on = []
for num in arr:
if num & bitmask == 0:
arr_off.append(num)
else:
arr_on.append(num)
if not arr_off:
return func(arr_on, bitmask >> 1)
if not arr_on:
return f... | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | def answer(ans1, ans2):
if max(len(ans1), len(ans2)) == 0:
return 0
if len(ans2) > 0 and len(ans1) == 0:
ans1, ans2 = ans2, ans1
if len(ans1) > 0 and len(ans2) == 0:
g1 = []
g2 = []
flag = 1
for t in range(len(ans1[0])):
k1 = []
for j i... | FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR ... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | n = int(input())
nums = [int(x) for x in input().split(" ")]
totor = 0
for num in nums:
totor |= num
exp = 1
while totor:
exp <<= 1
totor >>= 1
exp >>= 1
def ans(s, exp):
if not exp:
return 0
ones = []
zeros = []
for e in s:
if e >= exp:
ones.append(e - exp)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR... |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to he... | t = int(input())
lst = [int(ele) for ele in input().split()]
maxn = max(lst)
n = len(bin(maxn)[2:])
newlst = [("0" * (n - len(bin(ele)[2:])) + bin(ele)[2:]) for ele in lst]
def catchEvil(lstrino, loc):
count0, count1 = [], []
for ele in lstrino:
if ele[n - 1 - loc] == "1":
count1.append(el... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR VAR LIST L... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | from sys import stdin, stdout
def getans(n, m, arr):
if n == 2 or m == 2:
lim = 0
if m == 2:
lim = n
mark = [((arr[i][0] + arr[i][1]) % 2) for i in range(lim)]
sol = [[(0) for i in range(lim)] for j in range(2)]
else:
lim = m
mark... | FUNC_DEF IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
def input():
return sys.stdin.readline().rstrip()
def input_split():
return [int(i) for i in input().split()]
n, m = input_split()
grid = []
for _ in range(n):
grid.append([int(i) for i in input()])
if n >= 4 and m >= 4:
ans = -1
elif n < 2 or m < 2:
ans = 0
elif n == 2 or m == 2:
... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | def p(f):
for i in range(len(f)):
print(i, end=": ")
for j in range(len(f[i])):
print(int(f[i][j]), end=" ")
print()
def build_mask(n, m, f):
global mask
mask1 = [([0] * n) for i in range(2)]
for i in range(1 << n):
for j in range(1 << n):
for k ... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [[int(j) for j in input()[:-1]] for i in range(n)]
if n >= 4 and m >= 4:
print(-1)
exit()
if n == 1 or m == 1:
print(0)
exit()
inf = 10000000000000
if n == 2 or m == 2:
bitcheck = [([0] * 4) for i in range(4)]
for j in r... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
if n > 3:
print(-1)
elif n == 1:
print(0)
else:
l = []
for i in range(n):
temp = list(map(int, list(input())))
l.append(temp)
if n == 2:
A = l[:]
BU = [((A[0][i] + A[1][i]) % 2) for i in range(m)]
odd = 0
even = 0
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
if n == 1 or m == 1:
for i in range(n):
input()
print(0)
elif n >= 4 and m >= 4:
for i in range(n):
input()
print(-1)
else:
matrix = []
for i in range(n):
row = input()
matrix.append([])
for j in range(m):
matri... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
A = [list(map(int, list(input()))) for i in range(n)]
def diff3(X, i, j):
if i == 1 and j == 1:
k = [0, 1, 0]
elif i == 0 and j == 1:
k = [0, 0, 1]
elif i == 1 and j == 0:
k = [0, 1, 1]
else:
k = [0, 0, 0]
dif = 0
for ii in range... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR L... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_numb... | IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | def is_valid(prev_mask, curr_mask, N):
bits = prev_mask ^ curr_mask
if N == 2:
return bits != 0 and bits != 3
else:
check1 = bits != 0 and bits != 1 and bits != 4
check2 = bits != 7 and bits != 6 and bits != 3
return check1 and check2
def solve():
N, M = map(int, input(... | FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR 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 VAR VAR FUNC_CALL VA... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
mat = []
for i in range(n):
p = list(map(int, input()))
mat.append(p)
if min(n, m) >= 4:
print(-1)
if min(n, m) == 1:
print(0)
if n == 2 or m == 2:
p1 = 0
p2 = 0
temp1 = min(n, m)
temp2 = max(n, m)
n = temp1
m = temp2
for i in range(m):
... | 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 VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
if min(n, m) == 1:
print(0)
elif n >= 4:
print(-1)
elif n == 2:
lis = []
c = d = 0
for i in range(2):
s = list(input())
lis.append(s)
for i in range(m):
if (int(lis[0][i]) + int(lis[1][i]) + i) % 2:
c += 1
else:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | from sys import stdin, stdout
def five_O_five(n, m, a_2d):
if n > 3:
return -1
if n == 1:
return 0
MAX = 10**9
if n == 2:
preMask = [0, 0, 0, 0]
for i in range(m):
curMask = [MAX, MAX, MAX, MAX]
for j in range(4):
val = ord(a_2d[0... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR STRING BIN... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = [int(i) for i in input().split()]
matrix = ["" for i in range(n)]
for i in range(n):
matrix[i] = input()
if n >= 4:
print(-1)
elif n == 1:
print(0)
elif n == 2:
ps = 0
ptl = 0
for i in range(m):
if (int(matrix[0][i]) + int(matrix[1][i])) % 2 == i % 2:
ps += 1
e... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_O... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
A = [list(map(int, list(input().strip()))) for i in range(n)]
if n >= 4 and m >= 4:
print(-1)
sys.exit()
if n == 1 or m == 1:
print(0)
sys.exit()
if m == 2 or m == 3:
B = [([0] * n) for i in range(m)]
for i in range(m):
... | 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 VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VA... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
b = []
D = dict()
for _ in range(n):
s = input().rstrip()
b.append(s)
if n > m:
c = [(["0"] * n) for i in range(m)]
for i in range(m):
for j in range(n):
c[i][j] = b[j][i]
m, n = n, m
b = c
if n >= 4:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR V... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
l = []
for _ in range(n):
l.append(input().strip())
def witch(s):
out = 0
if s[0] != s[1]:
out += 2
if s[1] != s[2]:
out += 1
return out
if n >= 4 and m >= 4:
print(-1)
else:
if n < m:
n, m = ... | 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 FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NU... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = list(map(int, input().split()))
if n >= 4 and m >= 4:
print(-1)
elif n <= 1 or m <= 1:
print(0)
else:
matrix = []
for _ in range(n):
matrix.append(input())
if n > 3:
matrix2 = []
for j in range(m):
row = []
for i in range(n):
row... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = list(map(int, input().split()))
g = []
for _ in range(n):
g.append(input())
if n < m:
new_g = [[(0) for _ in range(m)] for _ in range(n)]
for i in range(n):
for j in range(m):
new_g[i][j] = int(g[i][j])
else:
new_g = [[(0) for _ in range(n)] for _ in range(m)]
for i in ran... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSI... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | def f(l, a):
i, count = 0, 0
for x in l:
count += x not in a[i]
i = (i + 1) % 2
return count
def g(l, mx):
return min([f(l, mx[i]) for i in range(len(mx))])
def two():
l = [(x[0] + x[1]) for x in zip(input(), input())]
mx = [["00", "11"], ["10", "01"]], [["10", "01"], ["00", ... | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LI... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
if min(n, m) > 3:
print(-1)
exit()
if min(n, m) == 1:
print(0)
exit()
if n > m:
inp = []
for i in range(n):
inp.append(list(map(int, input().split())))
u = []
n, m = m, n
for i in range(n):
u.append([0] * m)
for i in range(n):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
mat = []
for i in range(n):
mat.append([bool(int(i)) for i in input()])
if n >= 4 and m >= 4:
print(-1)
exit(0)
if n == 1 or m == 1:
print(0)
exit(0)
if n > m:
m, n = n, m
mat = [[i[j] for i in mat] for j in range(len(mat[0]))]
if n == 2:
res = []
for... | 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 VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBE... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [list(input().rstrip()) for i in range(n)]
for i in range(n):
for j in range(m):
a[i][j] = int(a[i][j])
if n >= 4:
print(-1)
exit()
if n == 1:
print(0)
exit()
if n == 2:
a.append(a[0])
r = n * m
for tar in range(... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
if n == 1 or m == 1:
print(0)
exit()
field = []
for _ in range(n):
field.append([int(item) for item in input().rstrip()])
if n < m:
n, m = m, n
nfield = []
for col in zip(*field):
nfield.append(list(col))
field =... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR 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 IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_C... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | raw = input()
n, m = map(int, raw.split(" "))
mx = []
for ri in range(n):
mx += [input()]
if n >= 4:
print(-1)
if n == 1:
print(0)
if n == 2:
p = m // 2
s = "AB" * (p + 2)
s1 = s[:m]
s2 = s[1 : m + 1]
r1, r2 = 0, 0
for i in range(m):
o1 = int(mx[0][i] != mx[1][i])
let... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
def hasOddCnt2x2(mat, i, j):
cnt = 0
for ii in range(i, i + 2):
for jj in range(j, j + 2):
cnt += mat[ii][jj]
return cnt % 2 == 1
def convertRowToBitMask(row):
b = 0
for i, x in enumerate(row):
if x == 1:
b = b | 1 << i
return b
def nMoves... | IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER F... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | 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... | 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_C... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | def gen_changes_table(threes):
table = []
for c, three in enumerate(threes):
line = []
for c2, three2 in enumerate(threes):
total = 0
for i in range(3):
if three[i] != three2[i]:
total += 1
line.append(total)
table.a... | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR N... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import itertools
n, m = map(int, input().split())
rows = []
for _ in range(n):
rows.append(list(map(int, input())))
if m >= 4 and n >= 4:
print(-1)
exit()
if m == 1 or n == 1:
print(0)
exit()
if n == 2 or m == 2:
if n == 2:
pars = [((rows[0][i] + rows[1][i]) % 2) for i in range(m)]
... | IMPORT 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 VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NU... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | def solve_two(A, n, m):
B = [((A[0][i] + A[1][i]) % 2) for i in range(m)]
odd = 0
even = 0
for i in range(m):
if B[i] == i % 2:
odd += 1
else:
even += 1
return min(odd, even)
def solve_three(A, n, m):
BU = [((A[0][i] + A[1][i]) % 2) for i in range(m)]
... | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
def checkPairable(b1, b2, n):
ok = True
for start in range(n - 1):
cnt = 0
if b1 & 1 << start > 0:
cnt += 1
if b1 & 1 << start + 1 > 0:
cnt += 1
if b2 & 1 << start > 0:
cnt += 1
if b2 & 1 << start + 1 > 0:
cnt +... | IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | from sys import stdin
def inp():
return stdin.buffer.readline().rstrip().decode("utf8")
def itg():
return int(stdin.buffer.readline())
def mpint():
return map(int, stdin.buffer.readline().split())
def clockwise(two_d_array, copy=False):
if copy:
return list(map(list, zip(*two_d_array[::-... | FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NUMBER IF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF VAR RETURN ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
data = [list(int(v) for v in input()) for _ in range(n)]
if n > 3 and m > 3:
print(-1)
elif n == 1 or m == 1:
print(0)
else:
if n < m:
n, m = m, n
data = [list(t) for t in zip(*data)]
if m == 2:
x, y = 0, 0
for i, v in enumerate(data):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL V... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = []
def f(x, y):
res = 0
if x[0] != y[0]:
res += 1
if x[1] != y[1]:
res += 1
if x[2] != y[2]:
res += 1
return res
if n >= 4 and m >= 4:
for i in range(n):
a.append(list(input()))
... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
def dif(x, y):
ans = 0
for i in range(3):
if x % 2 != y % 2:
ans += 1
x //= 2
y //= 2
return ans
def s(x, y):
ans = 0
for i in range(3):
ans += x % 2
ans += y % 2
x //= 2
y //= 2
return ans
def main():
n, m ... | IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | mod = 10**9 + 7
def solve():
n, m = map(int, input().split())
ans = 0
s = []
for i in range(n):
s.append(list(input()))
if n >= 4 and m > -4:
ans = -1
elif n == 1 or m == 1:
ans = 0
elif n == 2 or m == 2:
vec = []
if n == 2:
for i in rang... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER V... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
size = input()[:-1].split(" ")
size[0] = int(size[0])
size[1] = int(size[1])
lines = []
def diffOddDouble(bitList):
flipCount = []
for x in range(2):
for y in range(2):
flipCount.append(
sum(
bitList[i][0] == (i + x... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP VA... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
masks = ["000", "001", "010", "011", "100", "101", "110", "111"]
D = {}
x = []
for _ in range(n):
l = input().rstrip()
x.append(l)
if n < 2:
print(0)
if n == 2:
masks = ["00", "01", "10", "11"]
for mask in masks:
D... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | from sys import exit, stdin, stdout
def input():
return stdin.readline().strip()
def match_same(col):
if len(set(col)) == 1:
return 0
return 1
def match_exact(p, q):
ret = 0
for a, b in zip(p, q):
if a != b:
ret += 1
return ret
def match_diff(col):
if len(... | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | n, m = map(int, input().split())
if n > 3 and m > 3:
print(-1)
else:
arr = [[] for i in range(n)]
for i in range(n):
arr[i] = list(map(int, list(input())))
if n < m:
arr1 = [[(0) for i in range(n)] for i in range(m)]
for i in range(n):
for j in range(m):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | from itertools import chain, product
def find_cells_to_fix_n(matrix):
if len(matrix) < 2 or len(matrix[0]) < 2:
return 0
if not len(matrix) <= len(matrix[0]):
matrix = tuple(zip(*matrix))
len_y, len_x = len(matrix), len(matrix[0])
if len_y >= 4:
result = None
elif len_y == ... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NONE IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASS... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | 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 ran... | 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 ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | from sys import stdin
input = stdin.readline
n, m = map(int, input().split())
a = []
for x in range(n):
a.append(input().rstrip())
if n == 1:
print(0)
elif n >= 4:
print(-1)
elif n == 2:
cnt1, cnt2 = 0, 0
for x in range(m):
if x % 2 == 0:
cnt1 += a[0][x] == a[1][x]
c... | 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 FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR ... |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
matrix = [0] * n
for i in range(n):
line = input()
matrix[i] = [0] * m
for j in range(m):
matrix[i][j] = int(line[j])
if n > m:
matrix2 = [0] * m
for i in range(m):
matrix2[i] = [0] * n
for j in range(n):... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VA... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
from sys import stdin
def solve(n, k):
s = set()
ans = []
for i in range(len(n)):
dig = n[i]
if len(s) == k and dig not in s:
bigmin = None
for c in s:
if dig < c:
if bigmin == None:
bigmin = c
... | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NONE FOR VAR VAR IF VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
input = sys.stdin.readline
tests = int(input())
for test in range(tests):
tInt, k = map(int, input().split())
t = [int(x) for x in str(tInt)]
foundInts = 0
ints = []
firstOccurence = {}
pos = 0
while pos < len(t):
char = t[pos]
if char not in ints:
if ... | IMPORT 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 VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
def solve():
n, k = map(int, input().split())
s = str(n)
se = set()
for i in range(len(s)):
se.add(s[i])
if len(se) <= k:
return s
se = set()
i = 0
while True:
se.add(s[i])
if len(se) > k:
break
i += 1
se.remove(s[i])
... | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for i in range(int(input())):
n, k = map(int, input().split())
x = n
while len(set(str(x))) > k:
x = x // 10 if x % 10 == 0 else x + 1
p = str(x)
d = "0" if len(set(p)) < k else min(p)
print(p + d * (len(str(n)) - len(p))) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VA... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | times = int(input())
for _ in range(times):
n, k = map(int, input().split())
num = n
while len(set(str(num))) > k:
if num % 10 == 0:
num = num // 10
else:
num += 1
last = str(min(str(num))) * (len(str(n)) - len(str(num)))
print(str(num) + last) | 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 VAR WHILE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for _ in range(int(input())):
n, k = input().split()
k = int(k)
a = []
ans = 0
it = False
for i in range(len(n)):
if it:
if k:
ans = ans * 10
else:
ans = ans * 10 + min(a)
continue
j = i
while j < len(n):... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VA... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for _ in range(int(input())):
n, k = map(int, input().split())
tmp = n
while len(set(str(tmp))) > k:
if tmp % 10 == 0:
tmp //= 10
else:
tmp += 1
if len(set(str(tmp))) < k:
print(str(tmp) + "0" * (len(str(n)) - len(str(tmp))))
else:
print(str(tm... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for _ in range(int(input())):
x, k = input().split()
k = int(k)
n = len(x)
while len(set(x)) > k:
x = str(int(x) + 1).rstrip("0")
print(x + (min(x) if len(set(x)) == k else "0") * (n - len(x))) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR FUNC_C... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for i in range(int(input())):
a, k = input().split()
k = int(k)
k0 = k
b = [0] * 10
a = [int(i) for i in a]
j = 0
m = 9
mx = 0
for i in a:
if b[i] == 0:
k -= 1
if k < 0:
break
j += 1
b[i] += 1
m = min(m, i)
mx = ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR ... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def lower_bound(nums, x):
for i in range(len(nums)):
if nums[i] >= x:
return i
return -1
def check(n, k, num, pos, _n, wid):
x = num
nums = dict()
while x > 0:
nums.setdefault(x % 10, 0)
x //= 10
nums = list(nums.keys())
nums.sort()
flag = 0
for ... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSI... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def find_nearest(s, k):
ln = len(s)
if max(s[: ln - 1]) > s[ln - 1]:
x = list(set(s[: ln - 1]))
x.sort()
for it in x:
if it > s[-1]:
s = s[: ln - 1] + it
return s
else:
for i in range(ln - 1, -1, -1):
x = s[:i]
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER AS... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def getBeautiful(num, k):
if len(set(str(num))) <= k:
return num
unstableIdx = k
st = str(num)
digits = set(map(int, set(st[:unstableIdx])))
while int(st[unstableIdx]) in digits or len(digits) < k:
if unstableIdx != len(st) - 1:
digits.add(int(st[unstableIdx]))
... | FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for _ in range(int(input())):
n, k = map(int, input().split())
s = str(n)
if k == 1:
if int(s[0] * len(s)) >= n:
print(s[0] * len(s))
else:
print(str(int(s[0]) + 1) * len(s))
continue
dg, prob = set(), False
for i, v in enumerate(s):
if v not i... | 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 IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL V... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | from sys import stdin, stdout
def find_next_big(d, dic):
for i in range(d + 1, 10):
if dic[i] > 0:
return i
return -1
def find_min(dic):
for i in range(0, 10):
if dic[i] > 0:
return i
return -1
def find_cnt(dic):
cnt = 0
for i in range(0, 10):
... | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT FOR V... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def main(t):
n, k = map(int, input().split())
s = str(n)
m = len(s)
dic = {}
ans = ""
for i in range(m):
if s[i] in dic:
dic[s[i]] += 1
else:
dic[s[i]] = 1
if len(dic) == k and i < m - 1:
if s[i + 1 :] > max(dic) * (m - i - 1):
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for _ in range(int(input())):
n, k = map(int, input().split())
d = [int(x) for x in str(n)]
l = len(d)
if n == 1000000000:
print(1111111111 if k == 1 else 1000000000)
continue
if k >= len(set(d)):
print(n)
continue
mn = 10**15
for i in range(l):
for v ... | 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 VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BI... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
arr = [i for i in str(n)]
l = len(arr)
if len(set(arr)) <= k:
print(n)
continue
ans = -1
for i in range(0, l):
s = set()
vals = []
fo... | 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 VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSI... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | t = int(input())
some_list = []
for i in range(t):
some_list.append(input())
for i in range(t):
n_k = some_list[i].split()
n = int(n_k[0])
k = int(n_k[1])
x = n
while len(set(str(n))) > k:
if n % 10 == 0:
n = n // 10
else:
n += 1
end = str(min(str(n)))... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_O... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys as _sys
def _main():
[tests_n] = _read_ints()
for i_test in range(tests_n):
[n, k] = _read_ints()
result = find_nearest_beautiful_number(lower_bound=n, k_parameter=k)
print(result)
def find_nearest_beautiful_number(lower_bound: int, k_parameter: int):
prefix = lower_bo... | IMPORT FUNC_DEF ASSIGN LIST VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF VAR VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VA... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
input = sys.stdin.readline
def inp():
return int(input())
def input_list():
return list(map(int, input().split()))
def input_string():
s = input()
return list(s[: len(s) - 1])
def input_int_gen():
return map(int, input().split())
def largest(using, n_digits):
return (10**n_... | IMPORT 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 FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def first_bad(A, k):
seen = [0] * 10
for i, a in enumerate(A):
if seen[a] == 0:
k -= 1
seen[a] = 1
if k < 0:
return i
return -1
t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
A = [(ord(c) - ord("0")) for c in str(n)]... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL ... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def find_lsb(mask):
if mask == 0:
return -1
lsb = 0
while True:
if mask & 1 << lsb:
break
lsb += 1
return lsb
def solve(n, k):
mask = 0
cnt = 0
for c in n:
if mask & 1 << int(c):
continue
cnt += 1
mask |= 1 << int(c)
... | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
def main(N, K):
S = str(N)
d = len(S)
if d <= K:
return N
if len(set(S)) <= K:
return N
for i in range(d - 1, -1, -1):
up = set(S[:i])
if len(up) > K:
continue
if len(up) == K:
n = int(S[i])
for m in sorted(up):... | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR ... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
input = sys.stdin.readline
bits = [[] for _ in range(11)]
for bit in range(1 << 10):
se = set()
for i in range(10):
if bit >> i & 1:
se.add(i)
bits[len(se)].append(se)
def main():
n, k = input().strip().split()
k = int(k)
l = len(n)
times = (10**l - 1) // 9
... | IMPORT ASSIGN VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for s in [*open(0)][1:]:
prefix, k = map(int, s.split())
n = str(prefix)
while len(set(str(prefix))) > k:
prefix = prefix // 10 if not prefix % 10 else prefix + 1
prefix = str(prefix)
x = len(n) - len(prefix)
suffix = str(min(prefix) * x)
print(prefix + suffix) | FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = [int(i) for i in input().split()]
sn = [int(i) for i in str(n)]
s = set()
ans = []
for i in sn:
if i in s:
ans.append(i)
elif len(s) < k:
s.add(i)
ans.append(i)
els... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR E... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def number(L):
r = 0
for d in L:
r = r * 10 + int(d)
return r
def go(n, i, D, eq):
if i == len(n):
return True, []
if eq:
for d in D:
if n[i] == d:
flag, x = go(n, i + 1, D, True)
if flag:
return True, [d] + x
... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER LIST IF VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR RETURN NUMBER BIN_OP LIST VAR VAR IF VAR VAR VAR ASSIGN VAR ... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | t = int(input())
while t:
num, k = [int(tok) for tok in input().split()]
ans = 111111111111111
num = str(num)
n = len(num)
s = set()
for ch in num:
s.add(ch)
if len(s) <= k:
print(int(num))
else:
for ind in range(0, n):
if num[ind] == "9":
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
import time
input = sys.stdin.readline
def main():
t = int(input())
for _ in range(t):
n, k = list(map(int, input().split()))
digits = len(str(n))
first = str(n)[0]
if digits == 1:
print(n)
continue
if k == 1:
if int(first... | IMPORT IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
def get_digits(n):
digits = []
while n != 0:
digits.append(n % 10)
n = n // 10
return digits[::-1]
def construct(digits):
result = 0
power = 1
for d in digits[::-1]:
result += power * d
power *= 10
return result
def solve(n, k):
digits = g... | IMPORT FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETUR... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | for _ in range(int(input())):
n, k = input().split()
k = int(k)
m = len(n)
d = {}
i = 0
for i in range(m):
if n[i] not in d:
if len(d) == k:
break
d[n[i]] = 0
d[n[i]] += 1
else:
print(n)
continue
n = list(n)
whil... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIG... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
n = ""
k = l = 0
d = [0] * 9
def dfs(cur, dset):
p = len(cur)
if p == l:
return cur
if cur > n:
nd = 0
else:
nd = int(n[p])
for i in range(nd, 10):
if i in dset:
r = dfs(cur + str(i), dset)
if r != -1:
return r
... | IMPORT ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR NUMBE... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def solve(n, k):
a = sorted((n.index(x), int(x)) for x in set(n))
if len(a) <= k:
return n
d = {x[1] for x in a[:k]}
for i in range(a[k][1], 10):
if i in d:
m = n[: a[k][0]] + str(i)
break
else:
m = solve(str(int(n[: a[k][0]]) + 1), k)
return m + (... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FU... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | import sys
t = int(input())
for i in range(t):
n, k = sys.stdin.readline().split()
n = n.lstrip("000000000")
k = int(k)
L = []
for s in n:
if int(s) not in L:
L.append(int(s))
if len(L) <= k:
print(n)
else:
L = L[:k]
Num = list(map(int, n))
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR... |
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is called $k$-beautiful if its decimal representation having no leadin... | def f(n, k):
dig_set = set()
pre = ""
for x in n:
dig_set.add(x)
if len(dig_set) > int(k):
post_head = x
dig_set.remove(x)
break
pre += x
post_head = ""
post = n[len(pre) :]
if post_head:
min_dig = min(dig_set)
poss_... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.